From a34839ab7d2ce4b634380e121c95f8cd67481f4f Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 7 Nov 2025 15:25:47 +0530 Subject: [PATCH] feat: Allow Editing of Items and Quantities in Work Order (cherry picked from commit b5e6c3e70302b0ab72f6af0d0b786dff34db654f) # Conflicts: # erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.json # erpnext/manufacturing/doctype/work_order/work_order.js # erpnext/manufacturing/doctype/work_order/work_order.py --- .../manufacturing_settings.json | 30 +++++++++++++++++++ .../manufacturing_settings.py | 1 + .../doctype/work_order/work_order.js | 30 +++++++++++++++++++ .../doctype/work_order/work_order.py | 10 +++++++ 4 files changed, 71 insertions(+) diff --git a/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.json b/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.json index 277200af310..37a9fc8349d 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,42 @@ "fieldname": "enforce_time_logs", "fieldtype": "Check", "label": "Enforce Time Logs" +<<<<<<< HEAD +======= + }, + { + "fieldname": "section_break_xhtl", + "fieldtype": "Section Break", + "label": "Extra Material Transfer" + }, + { + "fieldname": "column_break_kemp", + "fieldtype": "Column Break" + }, + { + "description": "The user will be able to transfer additional materials from the store to the Work in Progress (WIP) warehouse.", + "fieldname": "transfer_extra_materials_percentage", + "fieldtype": "Percent", + "label": "Transfer Extra Raw Materials to WIP (%)" + }, + { + "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" +>>>>>>> b5e6c3e703 (feat: Allow Editing of Items and Quantities in Work Order) } ], "icon": "icon-wrench", "index_web_pages_for_search": 1, "issingle": 1, "links": [], +<<<<<<< HEAD "modified": "2025-05-16 11:23:16.916512", +======= + "modified": "2025-11-07 14:52:56.241459", +>>>>>>> b5e6c3e703 (feat: Allow Editing of Items and Quantities in Work Order) "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 2d67c7bd490..e33434f6409 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -242,6 +242,36 @@ frappe.ui.form.on("Work Order", { frm.trigger("add_custom_button_to_return_components"); frm.trigger("allow_alternative_item"); +<<<<<<< HEAD +======= + frm.trigger("hide_reserve_stock_button"); + frm.trigger("toggle_items_editable"); + }, + + toggle_items_editable(frm) { + frm.toggle_enable("required_items", frm.doc.__onload?.allow_editing_items === 1 ? 1 : 0); + }, + + hide_reserve_stock_button(frm) { + frm.toggle_display("reserve_stock", false); + if (frm.doc.__onload?.enable_stock_reservation) { + frm.toggle_display("reserve_stock", true); + } + }, + + has_unreserved_stock(frm) { + let has_unreserved_stock = frm.doc.required_items.some( + (item) => flt(item.required_qty) > flt(item.stock_reserved_qty) + ); + + return has_unreserved_stock; + }, + + has_reserved_stock(frm) { + let has_reserved_stock = frm.doc.required_items.some((item) => flt(item.stock_reserved_qty) > 0); + + return has_reserved_stock; +>>>>>>> b5e6c3e703 (feat: Allow Editing of Items and Quantities in Work Order) }, 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 9d862e84da7..dd239465621 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,16 @@ class WorkOrder(Document): validate_uom_is_integer(self, "stock_uom", ["required_qty"]) +<<<<<<< HEAD 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.enable_auto_reserve_stock() +>>>>>>> b5e6c3e703 (feat: Allow Editing of Items and Quantities in Work Order) self.validate_operations_sequence() def validate_operations_sequence(self):