From 68338abe07b52479a4235fd4bf3a81c92bba5db6 Mon Sep 17 00:00:00 2001 From: NaviN <118178330+Navin-S-R@users.noreply.github.com> Date: Tue, 3 Feb 2026 21:03:14 +0530 Subject: [PATCH] fix: merge taxes in purchase receipt when get items from multiple purchase invoices (#51422) * fix: merge taxes in purchase receipt when get items from multiple purchase invoices * fix: make merge tax configurable * chore: follow standard merge taxes method * chore: follow standard merge taxes method (cherry picked from commit 6fde0a6261475927cc75d3daf917b27c88348518) # Conflicts: # erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py --- .../purchase_invoice/purchase_invoice.py | 21 +++++++++++++++++-- erpnext/public/js/utils.js | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 8be04ab67a1..c53d72f9eba 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -38,7 +38,7 @@ from erpnext.accounts.utils import get_account_currency, get_fiscal_year, update from erpnext.assets.doctype.asset.asset import is_cwip_accounting_enabled from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account from erpnext.buying.utils import check_on_hold_or_closed_status -from erpnext.controllers.accounts_controller import validate_account_head +from erpnext.controllers.accounts_controller import merge_taxes, validate_account_head from erpnext.controllers.buying_controller import BuyingController from erpnext.stock import get_warehouse_account_map from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( @@ -2083,6 +2083,19 @@ def make_purchase_receipt(source_name, target_doc=None, args=None): if isinstance(args, str): args = json.loads(args) + def post_parent_process(source_parent, target_parent): + remove_items_with_zero_qty(target_parent) + set_missing_values(source_parent, target_parent) + + def remove_items_with_zero_qty(target_parent): + target_parent.items = [row for row in target_parent.get("items") if row.get("qty") != 0] + + def set_missing_values(source_parent, target_parent): + target_parent.run_method("set_missing_values") + if args and args.get("merge_taxes"): + merge_taxes(source_parent, target_parent) + target_parent.run_method("calculate_taxes_and_totals") + def update_item(obj, target, source_parent): target.qty = flt(obj.qty) - flt(obj.received_qty) target.received_qty = flt(obj.qty) - flt(obj.received_qty) @@ -2122,7 +2135,11 @@ def make_purchase_receipt(source_name, target_doc=None, args=None): "postprocess": update_item, "condition": lambda doc: abs(doc.received_qty) < abs(doc.qty) and select_item(doc), }, - "Purchase Taxes and Charges": {"doctype": "Purchase Taxes and Charges"}, + "Purchase Taxes and Charges": { + "doctype": "Purchase Taxes and Charges", + "reset_value": not (args and args.get("merge_taxes")), + "ignore": args.get("merge_taxes") if args else 0, + }, }, target_doc, ) diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 5942b34158d..59d2c90dc14 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -979,7 +979,7 @@ erpnext.utils.map_current_doc = function (opts) { if (opts.source_doctype) { let data_fields = []; - if (["Purchase Receipt", "Delivery Note"].includes(opts.source_doctype)) { + if (["Purchase Receipt", "Delivery Note", "Purchase Invoice"].includes(opts.source_doctype)) { let target_meta = frappe.get_meta(cur_frm.doc.doctype); if (target_meta.fields.find((f) => f.fieldname === "taxes")) { data_fields.push({