From 6e90f49a35e0548286c618cea13a30e39b629783 Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Mon, 12 Feb 2018 10:48:57 +0100 Subject: [PATCH] Wrong Exchange Rate Is Fetched When Exchange Rate Is Different From Company Currency For Price Lists #12712 (#12714) * unconditionally fetch exchange rate * Revert "unconditionally fetch exchange rate" This reverts commit d0d404d342092b5ba4398ed3bd8d8ff8f60b5f8a. * allow for `plc_conversion_rate` field to be reset * fetch exchange rate using price list currency and company currency not form currency * clean up --- erpnext/public/js/controllers/transaction.js | 10 ++++++++-- erpnext/stock/get_item_details.py | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index c5c9973b7a..a56ebd2e75 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -704,7 +704,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } if(!this.in_apply_price_list) { - this.apply_price_list(); + this.apply_price_list(null, true); } }, @@ -1056,7 +1056,13 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ if(!price_list_rate_changed) me.calculate_taxes_and_totals(); }, - apply_price_list: function(item) { + apply_price_list: function(item, reset_plc_conversion) { + // We need to reset plc_conversion_rate sometimes because the call to + // `erpnext.stock.get_item_details.apply_price_list` is sensitive to its value + if (!reset_plc_conversion) { + this.frm.set_value("plc_conversion_rate", ""); + } + var me = this; var args = this._get_args(item); if (!((args.items && args.items.length) || args.price_list)) { diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index a7638b4169..9c26a18f82 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -10,6 +10,7 @@ from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_ from erpnext.setup.utils import get_exchange_rate from frappe.model.meta import get_field_precision from erpnext.stock.doctype.batch.batch import get_batch_no +from erpnext import get_company_currency @frappe.whitelist() @@ -590,11 +591,12 @@ def get_price_list_currency_and_exchange_rate(args): price_list_currency = get_price_list_currency(args.price_list) price_list_uom_dependant = get_price_list_uom_dependant(args.price_list) plc_conversion_rate = args.plc_conversion_rate + company_currency = get_company_currency(args.company) if (not plc_conversion_rate) or (price_list_currency and args.price_list_currency \ and price_list_currency != args.price_list_currency): # cksgb 19/09/2016: added args.transaction_date as posting_date argument for get_exchange_rate - plc_conversion_rate = get_exchange_rate(price_list_currency, args.currency, + plc_conversion_rate = get_exchange_rate(price_list_currency, company_currency, args.transaction_date) or plc_conversion_rate return frappe._dict({