From 455bfcd7505bbe93a52b2afdf088502a740ca466 Mon Sep 17 00:00:00 2001 From: Ravibharathi <131471282+ravibharathi656@users.noreply.github.com> Date: Fri, 8 May 2026 18:17:33 +0530 Subject: [PATCH] fix: fetch get_item_tax_template while update items (#54784) --- erpnext/controllers/accounts_controller.py | 5 +++++ erpnext/stock/get_item_details.py | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 1308d2c1588..e903ab1ca30 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -68,6 +68,7 @@ from erpnext.stock.doctype.item.item import get_uom_conv_factor from erpnext.stock.doctype.packed_item.packed_item import make_packing_list from erpnext.stock.get_item_details import ( _get_item_tax_template, + _get_item_tax_template_from_item_group, get_conversion_factor, get_item_details, get_item_tax_map, @@ -3647,6 +3648,10 @@ def set_child_tax_template_and_map(item, child_item, parent_doc): } child_item.item_tax_template = _get_item_tax_template(args, item.taxes) + + if not child_item.get("item_tax_template"): + child_item.item_tax_template = _get_item_tax_template_from_item_group(args, item.item_group) + if child_item.get("item_tax_template"): child_item.item_tax_rate = get_item_tax_map( parent_doc.get("company"), child_item.item_tax_template, as_json=True diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 4e13bb246f2..e055de42adf 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -671,6 +671,7 @@ def get_item_tax_info(company, tax_category, item_codes, item_rates=None, item_t return out +# nosemgrep: frappe-semgrep-rules.rules.security.missing-argument-type-hint @frappe.whitelist() def get_item_tax_template(args, item=None, out=None): if isinstance(args, str): @@ -687,11 +688,7 @@ def get_item_tax_template(args, item=None, out=None): item_tax_template = _get_item_tax_template(args, item.taxes, out) if not item_tax_template: - item_group = item.item_group - while item_group and not item_tax_template: - item_group_doc = frappe.get_cached_doc("Item Group", item_group) - item_tax_template = _get_item_tax_template(args, item_group_doc.taxes, out) - item_group = item_group_doc.parent_item_group + item_tax_template = _get_item_tax_template_from_item_group(args, item.item_group, out) 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)) @@ -699,6 +696,18 @@ def get_item_tax_template(args, item=None, out=None): return item_tax_template +def _get_item_tax_template_from_item_group(args, item_group, out=None): + from frappe.utils.nestedset import get_ancestors_of + + ancestors = get_ancestors_of("Item Group", item_group) + for group in [item_group, *ancestors]: + group_doc = frappe.get_cached_doc("Item Group", group) + item_tax_template = _get_item_tax_template(args, group_doc.taxes, out) + if item_tax_template: + return item_tax_template + return None + + def _get_item_tax_template(args, taxes, out=None, for_validate=False): if out is None: out = {}