From 4fbaea17f847802ab4a2553ad3043ea7c73a39af Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 7 May 2026 16:04:20 +0530 Subject: [PATCH] fix: fetch get_item_tax_template while update items (backport #53708) (#54767) * fix: fetch get_item_tax_template while update items (cherry picked from commit 03c9d16ca64d1961a67b65e067e5d4ef2c8a66ca) * fix: resolve item tax template from item group in update items (cherry picked from commit 97e7916b6605b685c77ffdf3e8c616ff7b4e634c) * fix: resolve item tax template from item group in update items (cherry picked from commit ad22256b2d8c35462ac46fdbcbb698ee4a522ba1) --------- Co-authored-by: ervishnucs --- erpnext/controllers/accounts_controller.py | 8 +++++++- erpnext/stock/get_item_details.py | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 95867aac1a9..4f931bb0724 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -71,6 +71,7 @@ from erpnext.stock.get_item_details import ( NOT_APPLICABLE_TAX, ItemDetailsCtx, _get_item_tax_template, + _get_item_tax_template_from_item_group, get_conversion_factor, get_item_details, get_item_tax_map, @@ -3673,7 +3674,12 @@ def set_child_tax_template_and_map(item, child_item, parent_doc): } ) - child_item.item_tax_template = _get_item_tax_template(ctx, item.taxes) + item_tax_template = _get_item_tax_template(ctx, item.taxes) + + if not item_tax_template: + item_tax_template = _get_item_tax_template_from_item_group(ctx, item.item_group) + + child_item.item_tax_template = item_tax_template child_item.item_tax_rate = get_item_tax_map( doc=parent_doc, tax_template=child_item.item_tax_template, diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index bed23665401..abf392478c2 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -726,11 +726,7 @@ def get_item_tax_template(ctx, item=None, out: ItemDetails | None = None): item_tax_template = _get_item_tax_template(ctx, 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(ctx, item_group_doc.taxes, out) - item_group = item_group_doc.parent_item_group + item_tax_template = _get_item_tax_template_from_item_group(ctx, item.item_group, out) if out and ctx.get("child_doctype") and item_tax_template: out.update(get_fetch_values(ctx.get("child_doctype"), "item_tax_template", item_tax_template)) @@ -738,6 +734,18 @@ def get_item_tax_template(ctx, item=None, out: ItemDetails | None = None): return item_tax_template +def _get_item_tax_template_from_item_group(ctx, 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(ctx, group_doc.taxes, out) + if item_tax_template: + return item_tax_template + return None + + @erpnext.normalize_ctx_input(ItemDetailsCtx) def _get_item_tax_template( ctx: ItemDetailsCtx, taxes, out: ItemDetails | None = None, for_validate=False