From 875f09bc66533e1f118dcc66a2c6fcc984be61ad Mon Sep 17 00:00:00 2001 From: Ninad1306 Date: Fri, 2 Aug 2024 11:57:35 +0530 Subject: [PATCH] fix: populate item tax template when mapping subcontracting order --- .../overrides/subcontracting_transaction.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/india_compliance/gst_india/overrides/subcontracting_transaction.py b/india_compliance/gst_india/overrides/subcontracting_transaction.py index c92dfedf0..76b47c828 100644 --- a/india_compliance/gst_india/overrides/subcontracting_transaction.py +++ b/india_compliance/gst_india/overrides/subcontracting_transaction.py @@ -1,6 +1,7 @@ import frappe from frappe import _, bold from frappe.contacts.doctype.address.address import get_address_display +from erpnext.stock.get_item_details import _get_item_tax_template from india_compliance.gst_india.overrides.sales_invoice import ( update_dashboard_with_gst_logs, @@ -37,6 +38,30 @@ def after_mapping(doc, method, source_doc): return set_taxes(doc) + set_item_tax_template(doc, source_doc.as_dict()) + + +def set_item_tax_template(doc, args): + args["tax_category"] = frappe.db.get_value( + "Purchase Taxes and Charges Template", args.taxes_and_charges, "tax_category" + ) + + for item in doc.items: + item_doc = frappe.get_cached_doc("Item", item.item_code) + + item_tax_template = None + if item_doc.taxes: + item_tax_template = _get_item_tax_template(args, item_doc.taxes) + + if not item_tax_template: + item_group = item_doc.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) + item_group = item_group_doc.parent_item_group + + item.item_tax_template = item_tax_template def set_taxes(doc):