[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:
parent
15b22c9d7d
commit
70f57eb7f0
@ -558,9 +558,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
|
|
||||||
apply_pricing_rule: function(item, calculate_taxes_and_totals) {
|
apply_pricing_rule: function(item, calculate_taxes_and_totals) {
|
||||||
var me = this;
|
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({
|
return this.frm.call({
|
||||||
method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.apply_pricing_rule",
|
method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.apply_pricing_rule",
|
||||||
args: { args: this._get_args(item) },
|
args: { args: args },
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (!r.exc && r.message) {
|
if (!r.exc && r.message) {
|
||||||
me._set_values_for_item_list(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) {
|
apply_price_list: function(item) {
|
||||||
var me = this;
|
var me = this;
|
||||||
var args = this._get_args(item);
|
var args = this._get_args(item);
|
||||||
|
if (!((args.item_list && args.item_list.length) || args.price_list)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return this.frm.call({
|
return this.frm.call({
|
||||||
method: "erpnext.stock.get_item_details.apply_price_list",
|
method: "erpnext.stock.get_item_details.apply_price_list",
|
||||||
|
|||||||
@ -72,21 +72,20 @@ def get_exchange_rate(from_currency, to_currency):
|
|||||||
key = "currency_exchange_rate:{0}:{1}".format(from_currency, to_currency)
|
key = "currency_exchange_rate:{0}:{1}".format(from_currency, to_currency)
|
||||||
value = cache.get(key)
|
value = cache.get(key)
|
||||||
|
|
||||||
print value
|
|
||||||
|
|
||||||
if not value:
|
if not value:
|
||||||
import requests
|
import requests
|
||||||
response = requests.get("http://api.fixer.io/latest", params={
|
response = requests.get("http://api.fixer.io/latest", params={
|
||||||
"base": from_currency,
|
"base": from_currency,
|
||||||
"symbols": to_currency
|
"symbols": to_currency
|
||||||
})
|
})
|
||||||
# expire in 24 hours
|
# expire in 6 hours
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
value = response.json()["rates"][to_currency]
|
value = response.json()["rates"][to_currency]
|
||||||
cache.setex(key, value, 24 * 60 * 60)
|
cache.setex(key, value, 6 * 60 * 60)
|
||||||
|
|
||||||
return flt(value)
|
return flt(value)
|
||||||
except:
|
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
|
return 0.0
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|||||||
@ -427,6 +427,9 @@ def get_price_list_currency(price_list):
|
|||||||
return result.currency
|
return result.currency
|
||||||
|
|
||||||
def get_price_list_currency_and_exchange_rate(args):
|
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)
|
price_list_currency = get_price_list_currency(args.price_list)
|
||||||
plc_conversion_rate = args.plc_conversion_rate
|
plc_conversion_rate = args.plc_conversion_rate
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user