From f08704fcfc0170053a6e64431405d20f21f28f39 Mon Sep 17 00:00:00 2001 From: ervishnucs Date: Sun, 5 Apr 2026 11:16:37 +0530 Subject: [PATCH] fix: resolve item tax template from item group in update items (cherry picked from commit ad22256b2d8c35462ac46fdbcbb698ee4a522ba1) # Conflicts: # erpnext/stock/get_item_details.py --- erpnext/controllers/accounts_controller.py | 7 ++-- erpnext/stock/get_item_details.py | 37 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index eb96144058e..a9ee7efdab9 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -76,6 +76,7 @@ from erpnext.stock.get_item_details import ( ======= ItemDetailsCtx, _get_item_tax_template, + _get_item_tax_template_from_item_group, get_conversion_factor, get_item_details, get_item_tax_map, @@ -3668,11 +3669,7 @@ def set_child_tax_template_and_map(item, child_item, parent_doc): item_tax_template = _get_item_tax_template(ctx, item.taxes) 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) - item_group = item_group_doc.parent_item_group + item_tax_template = _get_item_tax_template_from_item_group(ctx, item.item_group) child_item.item_tax_template = item_tax_template >>>>>>> 97e7916b66 (fix: resolve item tax template from item group in update items) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 4e13bb246f2..ac354e61825 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -687,11 +687,15 @@ 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: +<<<<<<< HEAD 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(ctx, item.item_group, out) +>>>>>>> ad22256b2d (fix: resolve item tax template from item group in update items) 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,7 +703,40 @@ def get_item_tax_template(args, item=None, out=None): return item_tax_template +<<<<<<< HEAD def _get_item_tax_template(args, taxes, out=None, for_validate=False): +======= +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 +) -> None | str | list[str]: + """ + Accesses: + ctx = { + "company": str + "bill_date": str + "transaction_date": str + "tax_category": None + "item_tax_template": None + } + Passes: + ctx = { + "base_net_rate": float + } + """ +>>>>>>> ad22256b2d (fix: resolve item tax template from item group in update items) if out is None: out = {} taxes_with_validity = []