From 70f57eb7f0089f1936d0520e352bb6dd6a617c39 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 27 Nov 2015 14:37:40 +0530 Subject: [PATCH] [fix] call apply price list, apply pricing rule only if price list is mentioned or there are items in the table --- erpnext/public/js/controllers/transaction.js | 15 ++++++++++++--- erpnext/setup/utils.py | 9 ++++----- erpnext/stock/get_item_details.py | 5 ++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 87cc2f65912..49f47e07cba 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -76,7 +76,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ if(this.frm.doc.__islocal && !(this.frm.doc.taxes || []).length && !(this.frm.doc.__onload ? this.frm.doc.__onload.load_after_mapping : false)) { this.apply_default_taxes(); - } else if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc["items"] + } else if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc["items"] && !this.frm.doc.is_pos) { me.calculate_taxes_and_totals(); } @@ -507,7 +507,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } if(this.frm.fields_dict["advances"]) { - setup_field_label_map(["advance_amount", "allocated_amount"], + setup_field_label_map(["advance_amount", "allocated_amount"], this.frm.doc.party_account_currency, "advances"); } @@ -558,9 +558,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ apply_pricing_rule: function(item, calculate_taxes_and_totals) { var me = this; + var args = this._get_args(item); + if (!(args.item_list && args.item_list.length)) { + if(calculate_taxes_and_totals) me.calculate_taxes_and_totals(); + return; + } + return this.frm.call({ method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.apply_pricing_rule", - args: { args: this._get_args(item) }, + args: { args: args }, callback: function(r) { if (!r.exc && r.message) { me._set_values_for_item_list(r.message); @@ -648,6 +654,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ apply_price_list: function(item) { var me = this; var args = this._get_args(item); + if (!((args.item_list && args.item_list.length) || args.price_list)) { + return; + } return this.frm.call({ method: "erpnext.stock.get_item_details.apply_price_list", diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index 5b8dd044c82..e44a53fa2d9 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -72,21 +72,20 @@ def get_exchange_rate(from_currency, to_currency): key = "currency_exchange_rate:{0}:{1}".format(from_currency, to_currency) value = cache.get(key) - print value - if not value: import requests response = requests.get("http://api.fixer.io/latest", params={ "base": from_currency, "symbols": to_currency }) - # expire in 24 hours + # expire in 6 hours response.raise_for_status() value = response.json()["rates"][to_currency] - cache.setex(key, value, 24 * 60 * 60) + cache.setex(key, value, 6 * 60 * 60) + return flt(value) except: - frappe.msgprint(_("Unable to find exchange rate")) + frappe.msgprint(_("Unable to find exchange rate for {0} to {1}").format(from_currency, to_currency)) return 0.0 else: return value diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 6c6f84ba38e..71bc64a2c9d 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -69,7 +69,7 @@ def get_item_details(args): if args.get("is_subcontracted") == "Yes": out.bom = get_default_bom(args.item_code) - + return out def process_args(args): @@ -427,6 +427,9 @@ def get_price_list_currency(price_list): return result.currency def get_price_list_currency_and_exchange_rate(args): + if not args.price_list: + return {} + price_list_currency = get_price_list_currency(args.price_list) plc_conversion_rate = args.plc_conversion_rate