[fix] [exchange-rate] let user defined exchange rate take preceedence

This commit is contained in:
Rushabh Mehta 2015-10-15 11:50:38 +05:30
parent f861856ed9
commit 746fd90625

View File

@ -63,6 +63,10 @@ def before_tests():
@frappe.whitelist()
def get_exchange_rate(from_currency, to_currency):
exchange = "%s-%s" % (from_currency, to_currency)
value = flt(frappe.db.get_value("Currency Exchange", exchange, "exchange_rate"))
if not value:
try:
cache = frappe.cache()
key = "currency_exchange_rate:{0}:{1}".format(from_currency, to_currency)
@ -79,5 +83,7 @@ def get_exchange_rate(from_currency, to_currency):
cache.setex(key, value, 24 * 60 * 60)
return flt(value)
except:
exchange = "%s-%s" % (from_currency, to_currency)
return flt(frappe.db.get_value("Currency Exchange", exchange, "exchange_rate"))
frappe.msgprint(_("Unable to find exchange rate"))
return 0.0
else:
return 0.0