Modification to set_price_list_currency in accounts_controller.py to allow for specification of date in get_exchange_rate call
This commit is contained in:
@@ -131,8 +131,9 @@ class AccountsController(TransactionBase):
|
|||||||
self.plc_conversion_rate = 1.0
|
self.plc_conversion_rate = 1.0
|
||||||
|
|
||||||
elif not self.plc_conversion_rate:
|
elif not self.plc_conversion_rate:
|
||||||
|
# manqala 19/09/16: using the transaction date on the PO or SO as the basis for getting the exchange rate
|
||||||
self.plc_conversion_rate = get_exchange_rate(
|
self.plc_conversion_rate = get_exchange_rate(
|
||||||
self.price_list_currency, self.company_currency)
|
self.transaction_date, self.price_list_currency, self.company_currency)
|
||||||
|
|
||||||
# currency
|
# currency
|
||||||
if not self.currency:
|
if not self.currency:
|
||||||
|
|||||||
@@ -67,12 +67,13 @@ def before_tests():
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_exchange_rate(posting_date, from_currency, to_currency):
|
def get_exchange_rate(posting_date, from_currency, to_currency):
|
||||||
if not (posting_date and from_currency and 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?
|
||||||
return
|
return
|
||||||
|
|
||||||
if from_currency == to_currency:
|
if from_currency == to_currency:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
#Get all entries in Currency Exchange with from_currency and to_currency
|
# 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(posting_date)], ["from_currency", "=", from_currency], ["to_currency", "=", to_currency]], order_by="date desc")
|
||||||
if entries:
|
if entries:
|
||||||
return flt(entries[0].exchange_rate)
|
return flt(entries[0].exchange_rate)
|
||||||
|
|||||||
Reference in New Issue
Block a user