fix: fetch correct item tax template on item rate update (#47973)

This commit is contained in:
Diptanil Saha
2025-06-09 19:23:33 +05:30
committed by GitHub
parent 95d1d7047d
commit f88e68230a
2 changed files with 27 additions and 22 deletions

View File

@@ -44,23 +44,22 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
if (item.item_code && item.rate) { if (item.item_code && item.rate) {
frappe.call({ frappe.call({
method: "frappe.client.get_value", method: "erpnext.stock.get_item_details.get_item_tax_template",
args: { args: {
doctype: "Item Tax", args: {
parent: "Item", item_code: item.item_code,
filters: { company: frm.doc.company,
parent: item.item_code, base_net_rate: item.base_net_rate,
minimum_net_rate: ["<=", item.rate], tax_category: frm.doc.tax_category,
maximum_net_rate: [">=", item.rate] item_tax_template: item.item_tax_template,
}, posting_date: frm.doc.posting_date,
fieldname: "item_tax_template" bill_date: frm.doc.bill_date,
transaction_date: frm.doc.transaction_date,
}
}, },
callback: function(r) { callback: function(r) {
const tax_rule = r.message; const item_tax_template = r.message;
frappe.model.set_value(cdt, cdn, 'item_tax_template', item_tax_template);
let matched_template = tax_rule ? tax_rule.item_tax_template : null;
frappe.model.set_value(cdt, cdn, 'item_tax_template', matched_template);
} }
}); });
} }

View File

@@ -662,13 +662,17 @@ def get_item_tax_info(company, tax_category, item_codes, item_rates=None, item_t
return out return out
def get_item_tax_template(args, item, out): @frappe.whitelist()
""" def get_item_tax_template(args, item=None, out=None):
args = { if isinstance(args, str):
"tax_category": None args = json.loads(args)
"item_tax_template": None
} if not item:
""" if not args.get("item_code"):
frappe.throw(_("Item/Item Code required to get Item Tax Template."))
else:
item = frappe.get_cached_doc("Item", args.get("item_code"))
item_tax_template = None item_tax_template = None
if item.taxes: if item.taxes:
item_tax_template = _get_item_tax_template(args, item.taxes, out) item_tax_template = _get_item_tax_template(args, item.taxes, out)
@@ -680,9 +684,11 @@ def get_item_tax_template(args, item, out):
item_tax_template = _get_item_tax_template(args, item_group_doc.taxes, out) item_tax_template = _get_item_tax_template(args, item_group_doc.taxes, out)
item_group = item_group_doc.parent_item_group item_group = item_group_doc.parent_item_group
if args.get("child_doctype") and item_tax_template: if out and args.get("child_doctype") and item_tax_template:
out.update(get_fetch_values(args.get("child_doctype"), "item_tax_template", item_tax_template)) out.update(get_fetch_values(args.get("child_doctype"), "item_tax_template", item_tax_template))
return item_tax_template
def _get_item_tax_template(args, taxes, out=None, for_validate=False): def _get_item_tax_template(args, taxes, out=None, for_validate=False):
if out is None: if out is None: