From daf4d075cf7f6d91cea692a15876f57559d388d7 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Mon, 27 Apr 2026 13:58:55 +0530 Subject: [PATCH] fix: make inv dimen reqd only in delivery note (#54546) (cherry picked from commit 0aadd1e3a50689218286560f6e2c05f0082afaef) # Conflicts: # erpnext/patches.txt # erpnext/stock/doctype/inventory_dimension/inventory_dimension.py # erpnext/stock/doctype/packed_item/packed_item.json --- erpnext/patches.txt | 8 ++++++ .../patches/v16_0/packed_item_inv_dimen.py | 27 +++++++++++++++++++ .../inventory_dimension.py | 19 +++++++++++++ .../doctype/packed_item/packed_item.json | 9 +++++-- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v16_0/packed_item_inv_dimen.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 2dcee807fec..393aa97e4c5 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -433,3 +433,11 @@ erpnext.patches.v15_0.replace_http_with_https_in_sales_partner erpnext.patches.v16_0.add_portal_redirects erpnext.patches.v16_0.update_order_qty_and_requested_qty_based_on_mr_and_po erpnext.patches.v16_0.depends_on_inv_dimensions +<<<<<<< HEAD +======= +erpnext.patches.v16_0.uom_category +erpnext.patches.v16_0.merge_repost_settings_to_accounts_settings +erpnext.patches.v16_0.set_root_type_in_account_categories +erpnext.patches.v16_0.scr_inv_dimension +erpnext.patches.v16_0.packed_item_inv_dimen +>>>>>>> 0aadd1e3a5 (fix: make inv dimen reqd only in delivery note (#54546)) diff --git a/erpnext/patches/v16_0/packed_item_inv_dimen.py b/erpnext/patches/v16_0/packed_item_inv_dimen.py new file mode 100644 index 00000000000..38dd2007045 --- /dev/null +++ b/erpnext/patches/v16_0/packed_item_inv_dimen.py @@ -0,0 +1,27 @@ +import frappe + +from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions + + +def execute(): + for dimension in get_inventory_dimensions(): + if frappe.db.exists( + "Custom Field", + { + "fieldname": dimension.source_fieldname, + "dt": "Packed Item", + "reqd": 1, + }, + ): + frappe.set_value( + "Custom Field", + { + "fieldname": dimension.source_fieldname, + "dt": "Packed Item", + "reqd": 1, + }, + { + "reqd": 0, + "mandatory_depends_on": "eval:doc.parent_detail_docname && ['Delivery Note', 'Sales Invoice', 'POS Invoice'].includes(parent.doctype)", + }, + ) diff --git a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py index b43f2991bad..8212fee18e5 100644 --- a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py +++ b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.py @@ -166,6 +166,18 @@ class InventoryDimension(Document): if label_start_with: label = f"{label_start_with} {self.dimension_name}" +<<<<<<< HEAD +======= + mandatory_depends_on = self.mandatory_depends_on + if self.reqd: + if doctype == "Stock Entry Detail": + mandatory_depends_on = "eval:doc.s_warehouse" + elif doctype == "Subcontracting Receipt Supplied Item": + mandatory_depends_on = "eval:doc.reference_name" + elif doctype == "Packed Item": + mandatory_depends_on = "eval:doc.parent_detail_docname && ['Delivery Note', 'Sales Invoice', 'POS Invoice'].includes(parent.doctype)" + +>>>>>>> 0aadd1e3a5 (fix: make inv dimen reqd only in delivery note (#54546)) dimension_fields = [ dict( fieldname="inventory_dimension", @@ -183,7 +195,14 @@ class InventoryDimension(Document): depends_on="eval:doc.s_warehouse" if doctype == "Stock Entry Detail" else "", search_index=1, reqd=1 +<<<<<<< HEAD if self.reqd and not self.mandatory_depends_on and doctype != "Stock Entry Detail" +======= + if self.reqd + and not self.mandatory_depends_on + and doctype + not in ["Stock Entry Detail", "Subcontracting Receipt Supplied Item", "Packed Item"] +>>>>>>> 0aadd1e3a5 (fix: make inv dimen reqd only in delivery note (#54546)) else 0, mandatory_depends_on="eval:doc.s_warehouse" if self.reqd and doctype == "Stock Entry Detail" diff --git a/erpnext/stock/doctype/packed_item/packed_item.json b/erpnext/stock/doctype/packed_item/packed_item.json index 31726dff277..a0b392c9a7d 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.json +++ b/erpnext/stock/doctype/packed_item/packed_item.json @@ -8,6 +8,7 @@ "parent_item", "item_code", "item_name", + "delivered_by_supplier", "column_break_5", "description", "section_break_6", @@ -23,7 +24,6 @@ "use_serial_batch_fields", "column_break_11", "serial_and_batch_bundle", - "delivered_by_supplier", "section_break_bgys", "serial_no", "column_break_qlha", @@ -118,6 +118,7 @@ "read_only": 1 }, { + "depends_on": "eval:parent.doctype !== \"Sales Order\"", "fieldname": "section_break_9", "fieldtype": "Section Break" }, @@ -284,7 +285,7 @@ "label": "Use Serial No / Batch Fields" }, { - "depends_on": "eval:doc.use_serial_batch_fields === 1", + "depends_on": "eval:doc.use_serial_batch_fields === 1 && parent.doctype !== \"Sales Order\"", "fieldname": "section_break_bgys", "fieldtype": "Section Break" }, @@ -304,7 +305,11 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], +<<<<<<< HEAD "modified": "2025-07-09 19:12:45.850219", +======= + "modified": "2026-04-27 13:00:22.949296", +>>>>>>> 0aadd1e3a5 (fix: make inv dimen reqd only in delivery note (#54546)) "modified_by": "Administrator", "module": "Stock", "name": "Packed Item",