From 1d36cb55cdc8ce9f59a82a89b84f44c7d3c0f0c0 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 7 Nov 2025 15:25:47 +0530 Subject: [PATCH 1/3] feat: Allow Editing of Items and Quantities in Work Order --- .../manufacturing_settings/manufacturing_settings.json | 10 +++++++++- .../manufacturing_settings/manufacturing_settings.py | 1 + erpnext/manufacturing/doctype/work_order/work_order.js | 5 +++++ erpnext/manufacturing/doctype/work_order/work_order.py | 7 ++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.json b/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.json index 277200af310..64a1c870ce4 100644 --- a/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.json +++ b/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.json @@ -15,6 +15,7 @@ "bom_section", "update_bom_costs_automatically", "column_break_lhyt", + "allow_editing_of_items_and_quantities_in_work_order", "section_break_6", "default_wip_warehouse", "default_fg_warehouse", @@ -243,13 +244,20 @@ "fieldname": "enforce_time_logs", "fieldtype": "Check", "label": "Enforce Time Logs" + }, + { + "default": "0", + "description": "If enabled, the system will allow users to edit the raw materials and their quantities in the Work Order. The system will not reset the quantities as per the BOM, if the user has changed them.", + "fieldname": "allow_editing_of_items_and_quantities_in_work_order", + "fieldtype": "Check", + "label": "Allow Editing of Items and Quantities in Work Order" } ], "icon": "icon-wrench", "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2025-05-16 11:23:16.916512", + "modified": "2025-11-07 14:52:56.241459", "modified_by": "Administrator", "module": "Manufacturing", "name": "Manufacturing Settings", diff --git a/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.py b/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.py index e9f011f78ba..44d42cccae0 100644 --- a/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.py +++ b/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.py @@ -18,6 +18,7 @@ class ManufacturingSettings(Document): from frappe.types import DF add_corrective_operation_cost_in_finished_good_valuation: DF.Check + allow_editing_of_items_and_quantities_in_work_order: DF.Check allow_overtime: DF.Check allow_production_on_holidays: DF.Check backflush_raw_materials_based_on: DF.Literal["BOM", "Material Transferred for Manufacture"] diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index b6206cefcbb..8e8d359430f 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -243,6 +243,11 @@ frappe.ui.form.on("Work Order", { frm.trigger("add_custom_button_to_return_components"); frm.trigger("allow_alternative_item"); + frm.trigger("toggle_items_editable"); + }, + + toggle_items_editable(frm) { + frm.toggle_enable("required_items", frm.doc.__onload?.allow_editing_items === 1 ? 1 : 0); }, add_custom_button_to_return_components: function (frm) { diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index bc3def1186f..e1a561958ed 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -141,6 +141,7 @@ class WorkOrder(Document): def onload(self): ms = frappe.get_doc("Manufacturing Settings") + self.set_onload("allow_editing_items", ms.allow_editing_of_items_and_quantities_in_work_order) self.set_onload("material_consumption", ms.material_consumption) self.set_onload("backflush_raw_materials_based_on", ms.backflush_raw_materials_based_on) self.set_onload("overproduction_percentage", ms.overproduction_percentage_for_work_order) @@ -167,7 +168,11 @@ class WorkOrder(Document): validate_uom_is_integer(self, "stock_uom", ["required_qty"]) - self.set_required_items(reset_only_qty=len(self.get("required_items"))) + if not len(self.get("required_items")) or not frappe.db.get_single_value( + "Manufacturing Settings", "allow_editing_of_items_and_quantities_in_work_order" + ): + self.set_required_items(reset_only_qty=len(self.get("required_items"))) + self.validate_operations_sequence() def validate_operations_sequence(self): From 62d58702a03f016893a9e7537425ce37a9cb729e Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 2 Dec 2025 11:18:07 +0530 Subject: [PATCH 2/3] fix: not able to set operation in work order --- erpnext/manufacturing/doctype/work_order/work_order.js | 8 +++++++- .../doctype/work_order_item/work_order_item.json | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index 8e8d359430f..4e2ba94e308 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -247,7 +247,13 @@ frappe.ui.form.on("Work Order", { }, toggle_items_editable(frm) { - frm.toggle_enable("required_items", frm.doc.__onload?.allow_editing_items === 1 ? 1 : 0); + if (!frm.doc.__onload?.allow_editing_items) { + frm.set_df_property("required_items", "cannot_delete_rows", true); + frm.set_df_property("required_items", "cannot_add_rows", true); + frm.fields_dict["required_items"].grid.update_docfield_property("item_code", "read_only", 1); + frm.fields_dict["required_items"].grid.update_docfield_property("required_qty", "read_only", 1); + frm.fields_dict["required_items"].grid.refresh(); + } }, add_custom_button_to_return_components: function (frm) { diff --git a/erpnext/manufacturing/doctype/work_order_item/work_order_item.json b/erpnext/manufacturing/doctype/work_order_item/work_order_item.json index 580168180a7..98ee0a63d53 100644 --- a/erpnext/manufacturing/doctype/work_order_item/work_order_item.json +++ b/erpnext/manufacturing/doctype/work_order_item/work_order_item.json @@ -151,7 +151,7 @@ ], "istable": 1, "links": [], - "modified": "2024-11-19 15:48:16.823384", + "modified": "2025-12-02 11:16:05.081613", "modified_by": "Administrator", "module": "Manufacturing", "name": "Work Order Item", From 3c327d5225849b84db403a7901fe3e0fd48eceb6 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Wed, 1 Apr 2026 08:43:56 +0530 Subject: [PATCH 3/3] fix(ux): refresh grid to correctly persist the state of fields --- .../doctype/work_order/work_order.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index 4e2ba94e308..f8bbab0ff95 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -247,13 +247,16 @@ frappe.ui.form.on("Work Order", { }, toggle_items_editable(frm) { - if (!frm.doc.__onload?.allow_editing_items) { - frm.set_df_property("required_items", "cannot_delete_rows", true); - frm.set_df_property("required_items", "cannot_add_rows", true); - frm.fields_dict["required_items"].grid.update_docfield_property("item_code", "read_only", 1); - frm.fields_dict["required_items"].grid.update_docfield_property("required_qty", "read_only", 1); - frm.fields_dict["required_items"].grid.refresh(); - } + let allow_edit = true; + if (!frm.doc.__onload?.allow_editing_items) allow_edit = false; + + frm.set_df_property("required_items", "cannot_delete_rows", !allow_edit); + frm.set_df_property("required_items", "cannot_add_rows", !allow_edit); + + const grid = frm.fields_dict["required_items"].grid; + grid.update_docfield_property("item_code", "read_only", !allow_edit); + grid.update_docfield_property("required_qty", "read_only", !allow_edit); + grid.refresh(); }, add_custom_button_to_return_components: function (frm) {