From 3f77852e93d03704b3ff76d9ded4d963396870b7 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 15 May 2018 16:59:20 +0530 Subject: [PATCH] Pass buying or selling as filter parameters Wherever get_exchange_rate is called, pass filter buying or selling on the basis of doctype. --- erpnext/accounts/doctype/sales_invoice/pos.py | 2 +- erpnext/controllers/accounts_controller.py | 13 +++++++++---- erpnext/crm/doctype/opportunity/opportunity.py | 2 +- erpnext/demo/user/purchase.py | 2 +- erpnext/demo/user/sales.py | 2 +- erpnext/manufacturing/doctype/bom/bom.py | 2 +- erpnext/public/js/controllers/transaction.js | 9 +++++++-- erpnext/stock/get_item_details.py | 7 ++++++- 8 files changed, 27 insertions(+), 12 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index be6078a871..47894647ee 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -97,7 +97,7 @@ def update_pos_profile_data(doc, pos_profile, company_data): doc.conversion_rate = 1.0 if doc.currency != company_data.default_currency: - doc.conversion_rate = get_exchange_rate(doc.currency, company_data.default_currency, doc.posting_date) + doc.conversion_rate = get_exchange_rate(doc.currency, company_data.default_currency, doc.posting_date, args="for_selling") doc.selling_price_list = pos_profile.get('selling_price_list') or \ frappe.db.get_value('Selling Settings', None, 'selling_price_list') diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 050a14332e..0c8e485f62 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -148,8 +148,13 @@ class AccountsController(TransactionBase): if self.meta.get_field("currency"): # price list part - fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \ - else "buying_price_list" + if buying_or_selling.lower() == "selling": + fieldname = "selling_price_list" + args = "for_selling" + else: + fieldname = "buying_price_list" + args = "for_buying" + if self.meta.get_field(fieldname) and self.get(fieldname): self.price_list_currency = frappe.db.get_value("Price List", self.get(fieldname), "currency") @@ -159,7 +164,7 @@ class AccountsController(TransactionBase): elif not self.plc_conversion_rate: self.plc_conversion_rate = get_exchange_rate(self.price_list_currency, - self.company_currency, transaction_date) + self.company_currency, transaction_date, args) # currency if not self.currency: @@ -169,7 +174,7 @@ class AccountsController(TransactionBase): self.conversion_rate = 1.0 elif not self.conversion_rate: self.conversion_rate = get_exchange_rate(self.currency, - self.company_currency, transaction_date) + self.company_currency, transaction_date, args) def set_missing_item_details(self, for_validate=False): """set missing item values""" diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index fc886ac69d..5c203d9e1b 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -227,7 +227,7 @@ def make_quotation(source_name, target_doc=None): exchange_rate = 1 else: exchange_rate = get_exchange_rate(quotation.currency, company_currency, - quotation.transaction_date) + quotation.transaction_date, args="for_selling") quotation.conversion_rate = exchange_rate diff --git a/erpnext/demo/user/purchase.py b/erpnext/demo/user/purchase.py index d9fc1f3c4a..327f617cc9 100644 --- a/erpnext/demo/user/purchase.py +++ b/erpnext/demo/user/purchase.py @@ -56,7 +56,7 @@ def work(): if company_currency == party_account_currency: exchange_rate = 1 else: - exchange_rate = get_exchange_rate(party_account_currency, company_currency) + exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_buying") # make supplier quotations if random.random() < 0.2: diff --git a/erpnext/demo/user/sales.py b/erpnext/demo/user/sales.py index 2fd2565aad..02e1d427a5 100644 --- a/erpnext/demo/user/sales.py +++ b/erpnext/demo/user/sales.py @@ -89,7 +89,7 @@ def make_quotation(): if company_currency == party_account_currency: exchange_rate = 1 else: - exchange_rate = get_exchange_rate(party_account_currency, company_currency) + exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_selling") qtn = frappe.get_doc({ "creation": frappe.flags.current_date, diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 73c8ca0eb1..1fbc8068db 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -303,7 +303,7 @@ class BOM(WebsiteGenerator): if self.currency == self.company_currency(): self.conversion_rate = 1 elif self.conversion_rate == 1 or flt(self.conversion_rate) <= 0: - self.conversion_rate = get_exchange_rate(self.currency, self.company_currency()) + self.conversion_rate = get_exchange_rate(self.currency, self.company_currency(), args="for_buying") def validate_materials(self): """ Validate raw material entries """ diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 7c1a42a144..ab7cee67bc 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -667,9 +667,14 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ }, get_exchange_rate: function(transaction_date, from_currency, to_currency, callback) { - if (this.frm.doctype == "Purchase Order") { - var args = "for_buying"; + var args; + if (["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"].includes(this.frm.doctype)) { + args = "for_selling"; } + else if (["Purchase Order", "Purchase Receipt", "Purchase Invoice"].includes(this.frm.doctype)) { + args = "for_buying"; + } + if (!transaction_date || !from_currency || !to_currency) return; return frappe.call({ method: "erpnext.setup.utils.get_exchange_rate", diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index b36cd39ad7..31ee534e89 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -628,6 +628,11 @@ def get_price_list_currency_and_exchange_rate(args): if not args.price_list: return {} + if args.doctype in ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice']: + args.update({"exchange_rate": "for_selling"}) + elif args.doctype in ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']: + args.update({"exchange_rate": "for_buying"}) + 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 @@ -637,7 +642,7 @@ def get_price_list_currency_and_exchange_rate(args): 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, company_currency, - args.transaction_date) or plc_conversion_rate + args.transaction_date, args.exchange_rate) or plc_conversion_rate return frappe._dict({ "price_list_currency": price_list_currency,