From e79bbf4a06ef54dd03521e876e2eda3fc33ae382 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 31 Jan 2025 23:04:54 +0530 Subject: [PATCH] fix: not able to make manufacturing entry for alternate items --- .../doctype/work_order/test_work_order.py | 53 +++++++++++++++++++ .../stock/doctype/stock_entry/stock_entry.py | 7 ++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index edbe0a95105..441464fc469 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -2318,6 +2318,59 @@ class TestWorkOrder(FrappeTestCase): stock_entry.submit() + def test_components_alternate_item_for_bom_based_manufacture_entry(self): + frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM") + frappe.db.set_single_value("Manufacturing Settings", "validate_components_quantities_per_bom", 1) + + fg_item = "Test FG Item For Component Validation for alternate item" + source_warehouse = "Stores - _TC" + raw_materials = ["Test Component Validation RM Item 112", "Test Component Validation RM Item 22"] + alternate_item = ["Alternate Test Component Validation RM Item 1"] + + make_item(fg_item, {"is_stock_item": 1}) + for item in raw_materials + alternate_item: + make_item(item, {"is_stock_item": 1, "allow_alternative_item": 1}) + test_stock_entry.make_stock_entry( + item_code=item, + target=source_warehouse, + qty=10, + basic_rate=100, + ) + + frappe.get_doc( + { + "doctype": "Item Alternative", + "item_code": raw_materials[0], + "alternative_item_code": alternate_item[0], + "two_way": 1, + } + ).insert() + + make_bom(item=fg_item, source_warehouse=source_warehouse, raw_materials=raw_materials) + + wo = make_wo_order_test_record( + item=fg_item, + qty=10, + source_warehouse=source_warehouse, + ) + + transfer_entry = frappe.get_doc(make_stock_entry(wo.name, "Material Transfer for Manufacture", 10)) + transfer_entry.save() + transfer_entry.items[0].item_code = alternate_item[0] + transfer_entry.items[0].original_item = raw_materials[0] + transfer_entry.submit() + + self.assertTrue(transfer_entry.docstatus == 1) + + manufacture_entry = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 10)) + manufacture_entry.save() + self.assertTrue(manufacture_entry.items[0].item_code == alternate_item[0]) + self.assertTrue(manufacture_entry.items[0].original_item == raw_materials[0]) + + manufacture_entry.submit() + + frappe.db.set_single_value("Manufacturing Settings", "validate_components_quantities_per_bom", 0) + def test_components_qty_for_bom_based_manufacture_entry(self): frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM") frappe.db.set_single_value("Manufacturing Settings", "validate_components_quantities_per_bom", 1) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 25ffc45cc93..9be6ac3e12b 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -767,7 +767,7 @@ class StockEntry(StockController): def get_matched_items(self, item_code): for row in self.items: - if row.item_code == item_code: + if row.item_code == item_code or row.original_item == item_code: return row return {} @@ -1836,7 +1836,7 @@ class StockEntry(StockController): item_wh = frappe._dict(item_wh) - for item in item_dict.values(): + for original_item, item in item_dict.items(): if self.pro_doc and cint(self.pro_doc.from_wip_warehouse): item["from_warehouse"] = self.pro_doc.wip_warehouse # Get Reserve Warehouse from Subcontract Order @@ -1844,6 +1844,9 @@ class StockEntry(StockController): item["from_warehouse"] = item_wh.get(item.item_code) item["to_warehouse"] = self.to_warehouse if self.purpose == "Send to Subcontractor" else "" + if original_item != item.get("item_code"): + item["original_item"] = original_item + self.add_to_stock_entry_detail(item_dict) # fetch the serial_no of the first stock entry for the second stock entry -- GitLab