mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 13:39:18 +00:00
cache exchange rates and use them as needed
This commit is contained in:
@@ -160,18 +160,17 @@ def get_currency(filters):
|
|||||||
|
|
||||||
def convert(value, from_, to, date):
|
def convert(value, from_, to, date):
|
||||||
rate = get_rate_as_at(date, from_, to)
|
rate = get_rate_as_at(date, from_, to)
|
||||||
if not rate:
|
|
||||||
rate = get_exchange_rate(from_, to, date)
|
|
||||||
converted_value = value / (rate or 1)
|
converted_value = value / (rate or 1)
|
||||||
return converted_value
|
return converted_value
|
||||||
|
|
||||||
|
|
||||||
def get_rate_as_at(date, from_curr, to_currency):
|
def get_rate_as_at(date, from_currency, to_currency):
|
||||||
for rate in __exchange_rates:
|
rate = __exchange_rates.get('{0}-{1}@{2}'.format(from_currency, to_currency, date))
|
||||||
if rate.get('date') == getdate(date) \
|
if not rate:
|
||||||
and rate.get('from_currency') == from_curr \
|
rate = get_exchange_rate(from_currency, to_currency, date) or 1
|
||||||
and rate.get('to_currency') == to_currency:
|
__exchange_rates['{0}-{1}@{2}'.format(from_currency, to_currency, date)] = rate
|
||||||
return rate.get('exchange_rate')
|
|
||||||
|
return rate
|
||||||
|
|
||||||
|
|
||||||
def is_p_or_l_account(account_name):
|
def is_p_or_l_account(account_name):
|
||||||
|
|||||||
Reference in New Issue
Block a user