[fix] call apply price list, apply pricing rule only if price list is mentioned or there are items in the table

This commit is contained in:
Anand Doshi 2015-11-27 14:37:40 +05:30
parent 15b22c9d7d
commit 70f57eb7f0
3 changed files with 20 additions and 9 deletions

View File

@ -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",

View File

@ -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

View File

@ -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