Fixes and patch for Currency Exchange based on date

This commit is contained in:
Nabin Hait
2016-12-08 15:36:23 +05:30
parent b267a6c90e
commit 288a18e0cc
10 changed files with 98 additions and 33 deletions

View File

@@ -79,12 +79,8 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
<<<<<<< HEAD
"in_list_view": 1,
"in_standard_filter": 1,
=======
"in_list_view": 0,
>>>>>>> 4a0c8400762adb857c8e929d3af56ba83d8c3f76
"label": "To Currency",
"length": 0,
"no_copy": 0,
@@ -142,11 +138,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
<<<<<<< HEAD
"modified": "2016-11-07 05:28:09.772560",
=======
"modified": "2016-09-05 22:47:38.746711",
>>>>>>> 4a0c8400762adb857c8e929d3af56ba83d8c3f76
"modified": "2016-11-08 05:28:09.772560",
"modified_by": "Administrator",
"module": "Setup",
"name": "Currency Exchange",

View File

@@ -3,5 +3,18 @@
from __future__ import unicode_literals
import frappe
test_records = frappe.get_test_records('Currency Exchange')
import frappe, unittest
test_records = frappe.get_test_records('Currency Exchange')
class TestCurrencyExchange(unittest.TestCase):
def test_exchnage_rate(self):
from erpnext.setup.utils import get_exchange_rate
# Exchange rate as on 15th Jan, 2016, should be fetched from Currency Exchange record
exchange_rate = get_exchange_rate("2016-01-15", "USD", "INR")
self.assertEqual(exchange_rate, 60.0)
# Exchange rate as on 15th Dec, 2015, should be fetched from fixer.io
exchange_rate = get_exchange_rate("2015-12-15", "USD", "INR")
self.assertFalse(exchange_rate==60)

View File

@@ -1,21 +1,21 @@
[
{
"doctype": "Currency Exchange",
"date": "01-01-2016",
"date": "2016-01-01",
"exchange_rate": 60.0,
"from_currency": "USD",
"to_currency": "INR"
},
{
"doctype": "Currency Exchange",
"date": "01-01-2016",
"date": "2016-01-01",
"exchange_rate": 0.773,
"from_currency": "USD",
"to_currency": "EUR"
},
{
"doctype": "Currency Exchange",
"date": "01-01-2016",
"date": "2016-01-01",
"exchange_rate": 0.0167,
"from_currency": "INR",
"to_currency": "USD"

View File

@@ -65,22 +65,22 @@ def before_tests():
frappe.db.commit()
@frappe.whitelist()
def get_exchange_rate(translation_date, from_currency, to_currency):
if not (translation_date and from_currency and to_currency):
def get_exchange_rate(transaction_date, from_currency, to_currency):
if not (transaction_date and from_currency and to_currency):
# manqala 19/09/2016: Should this be an empty return or should it throw and exception?
return
if from_currency == to_currency:
return 1
# cksgb 19/09/2016: get all entries in Currency Exchange with from_currency and to_currency. Order by date desc. Top one is the required exchange rate
# cksgb 19/09/2016: get last entry in Currency Exchange with from_currency and to_currency.
entries = frappe.get_all("Currency Exchange", fields = ["exchange_rate"],
filters=[
["date", "<=", get_datetime_str(translation_date)],
["date", "<=", get_datetime_str(transaction_date)],
["from_currency", "=", from_currency],
["to_currency", "=", to_currency]
], order_by="date desc", limit=1)
if entries:
return flt(entries[0].exchange_rate)
@@ -102,5 +102,5 @@ def get_exchange_rate(translation_date, from_currency, to_currency):
return flt(value)
except:
frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}").format(from_currency, to_currency, translation_date))
frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}").format(from_currency, to_currency, transaction_date))
return 0.0