Corrections properly distinguish between transaction_date and posting_date as the basis for determining translation date that is passed to get_exchange_rate

This commit is contained in:
Chude Osiegbu
2016-09-19 03:53:37 +01:00
parent 375a3c003d
commit 256ec170d0
3 changed files with 22 additions and 20 deletions

View File

@@ -65,16 +65,16 @@ def before_tests():
frappe.db.commit()
@frappe.whitelist()
def get_exchange_rate(posting_date, from_currency, to_currency):
if not (posting_date and from_currency and to_currency):
# cksgb 19/09/2016: Should this be an empty return or should it throw and exception?
def get_exchange_rate(translation_date, from_currency, to_currency):
if not (translation_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
entries = frappe.get_all("Currency Exchange", fields = ["*"], filters=[["date", "<=", get_datetime_str(posting_date)], ["from_currency", "=", from_currency], ["to_currency", "=", to_currency]], order_by="date desc")
entries = frappe.get_all("Currency Exchange", fields = ["*"], filters=[["date", "<=", get_datetime_str(translation_date)], ["from_currency", "=", from_currency], ["to_currency", "=", to_currency]], order_by="date desc")
if entries:
return flt(entries[0].exchange_rate)
@@ -96,5 +96,5 @@ def get_exchange_rate(posting_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, posting_date))
frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}").format(from_currency, to_currency, translation_date))
return 0.0