From 216aaaf1d6bcf93ac861a7c2a91fc7b45f28fe9d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 4 Sep 2015 16:41:04 +0530 Subject: [PATCH] Set currency and exchange rate based on Customer's currency while making Quotation from Opportunity --- erpnext/crm/doctype/opportunity/opportunity.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 78729a3bcb..5cf96e9904 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -6,6 +6,7 @@ import frappe, json from frappe.utils import cstr, cint from frappe import msgprint, _ from frappe.model.mapper import get_mapped_doc +from erpnext.setup.utils import get_exchange_rate from erpnext.utilities.transaction_base import TransactionBase @@ -179,7 +180,17 @@ def get_item_details(item_code): def make_quotation(source_name, target_doc=None): def set_missing_values(source, target): quotation = frappe.get_doc(target) - quotation.currency = None # set it as default from customer + + company_currency = frappe.db.get_value("Company", quotation.company, "default_currency") + party_account_currency = frappe.db.get_value("Customer", quotation.customer, "party_account_currency") + if company_currency == party_account_currency: + exchange_rate = 1 + else: + exchange_rate = get_exchange_rate(party_account_currency, company_currency) + + quotation.currency = party_account_currency or company_currency + quotation.conversion_rate = exchange_rate + quotation.run_method("set_missing_values") quotation.run_method("calculate_taxes_and_totals")