fix: User is not able to change item tax template
This commit is contained in:
parent
c05496a5a7
commit
1f7b95f390
@ -270,11 +270,14 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
|||||||
let me = this;
|
let me = this;
|
||||||
let item_codes = [];
|
let item_codes = [];
|
||||||
let item_rates = {};
|
let item_rates = {};
|
||||||
|
let item_tax_templates = {};
|
||||||
|
|
||||||
$.each(this.frm.doc.items || [], function(i, item) {
|
$.each(this.frm.doc.items || [], function(i, item) {
|
||||||
if (item.item_code) {
|
if (item.item_code) {
|
||||||
// Use combination of name and item code in case same item is added multiple times
|
// Use combination of name and item code in case same item is added multiple times
|
||||||
item_codes.push([item.item_code, item.name]);
|
item_codes.push([item.item_code, item.name]);
|
||||||
item_rates[item.name] = item.net_rate;
|
item_rates[item.name] = item.net_rate;
|
||||||
|
item_tax_templates[item.name] = item.item_tax_template
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -285,18 +288,16 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
|||||||
company: me.frm.doc.company,
|
company: me.frm.doc.company,
|
||||||
tax_category: cstr(me.frm.doc.tax_category),
|
tax_category: cstr(me.frm.doc.tax_category),
|
||||||
item_codes: item_codes,
|
item_codes: item_codes,
|
||||||
|
item_tax_templates: item_tax_templates,
|
||||||
item_rates: item_rates
|
item_rates: item_rates
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (!r.exc) {
|
if (!r.exc) {
|
||||||
$.each(me.frm.doc.items || [], function(i, item) {
|
$.each(me.frm.doc.items || [], function(i, item) {
|
||||||
if (item.name && r.message.hasOwnProperty(item.name)) {
|
if (item.name && r.message.hasOwnProperty(item.name) && r.message[item.name].item_tax_template) {
|
||||||
item.item_tax_template = r.message[item.name].item_tax_template;
|
item.item_tax_template = r.message[item.name].item_tax_template;
|
||||||
item.item_tax_rate = r.message[item.name].item_tax_rate;
|
item.item_tax_rate = r.message[item.name].item_tax_rate;
|
||||||
me.add_taxes_from_item_tax_template(item.item_tax_rate);
|
me.add_taxes_from_item_tax_template(item.item_tax_rate);
|
||||||
} else {
|
|
||||||
item.item_tax_template = "";
|
|
||||||
item.item_tax_rate = "{}";
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -436,7 +436,7 @@ def get_barcode_data(items_list):
|
|||||||
return itemwise_barcode
|
return itemwise_barcode
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_item_tax_info(company, tax_category, item_codes, item_rates=None):
|
def get_item_tax_info(company, tax_category, item_codes, item_tax_templates, item_rates=None):
|
||||||
out = {}
|
out = {}
|
||||||
if isinstance(item_codes, string_types):
|
if isinstance(item_codes, string_types):
|
||||||
item_codes = json.loads(item_codes)
|
item_codes = json.loads(item_codes)
|
||||||
@ -444,12 +444,18 @@ def get_item_tax_info(company, tax_category, item_codes, item_rates=None):
|
|||||||
if isinstance(item_rates, string_types):
|
if isinstance(item_rates, string_types):
|
||||||
item_rates = json.loads(item_rates)
|
item_rates = json.loads(item_rates)
|
||||||
|
|
||||||
|
if isinstance(item_tax_templates, string_types):
|
||||||
|
item_tax_templates = json.loads(item_tax_templates)
|
||||||
|
|
||||||
for item_code in item_codes:
|
for item_code in item_codes:
|
||||||
if not item_code or item_code[1] in out:
|
if not item_code or item_code[1] in out or not item_tax_templates.get(item_code[1]):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
out[item_code[1]] = {}
|
out[item_code[1]] = {}
|
||||||
item = frappe.get_cached_doc("Item", item_code[0])
|
item = frappe.get_cached_doc("Item", item_code[0])
|
||||||
args = {"company": company, "tax_category": tax_category, "net_rate": item_rates[item_code[1]]}
|
args = {"company": company, "tax_category": tax_category, "net_rate": item_rates[item_code[1]],
|
||||||
|
"item_tax_template": item_tax_templates.get(item_code[1])}
|
||||||
|
|
||||||
get_item_tax_template(args, item, out[item_code[1]])
|
get_item_tax_template(args, item, out[item_code[1]])
|
||||||
out[item_code[1]]["item_tax_rate"] = get_item_tax_map(company, out[item_code[1]].get("item_tax_template"), as_json=True)
|
out[item_code[1]]["item_tax_rate"] = get_item_tax_map(company, out[item_code[1]].get("item_tax_template"), as_json=True)
|
||||||
|
|
||||||
@ -463,9 +469,7 @@ def get_item_tax_template(args, item, out):
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
item_tax_template = args.get("item_tax_template")
|
item_tax_template = args.get("item_tax_template")
|
||||||
|
item_tax_template = _get_item_tax_template(args, item.taxes, out)
|
||||||
if not item_tax_template:
|
|
||||||
item_tax_template = _get_item_tax_template(args, item.taxes, out)
|
|
||||||
|
|
||||||
if not item_tax_template:
|
if not item_tax_template:
|
||||||
item_group = item.item_group
|
item_group = item.item_group
|
||||||
@ -508,7 +512,8 @@ def _get_item_tax_template(args, taxes, out=None, for_validate=False):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# do not change if already a valid template
|
# do not change if already a valid template
|
||||||
if args.get('item_tax_template') in taxes:
|
if args.get('item_tax_template') in [t.item_tax_template for t in taxes]:
|
||||||
|
out["item_tax_template"] = args.get('item_tax_template')
|
||||||
return args.get('item_tax_template')
|
return args.get('item_tax_template')
|
||||||
|
|
||||||
for tax in taxes:
|
for tax in taxes:
|
||||||
|
Loading…
Reference in New Issue
Block a user