fix: scrap items order not showing correctly in stock entry (#21346)
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 7cf822b..95f9d46 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -865,14 +865,6 @@
self.add_to_stock_entry_detail(item_dict)
- if self.purpose != "Send to Subcontractor" and self.purpose in ["Manufacture", "Repack"]:
- scrap_item_dict = self.get_bom_scrap_material(self.fg_completed_qty)
- for item in itervalues(scrap_item_dict):
- if self.pro_doc and self.pro_doc.scrap_warehouse:
- item["to_warehouse"] = self.pro_doc.scrap_warehouse
-
- self.add_to_stock_entry_detail(scrap_item_dict, bom_no=self.bom_no)
-
# fetch the serial_no of the first stock entry for the second stock entry
if self.work_order and self.purpose == "Manufacture":
self.set_serial_nos(self.work_order)
@@ -883,9 +875,20 @@
if self.purpose in ("Manufacture", "Repack"):
self.load_items_from_bom()
+ self.set_scrap_items()
self.set_actual_qty()
self.calculate_rate_and_amount(raise_error_if_no_rate=False)
+ def set_scrap_items(self):
+ if self.purpose != "Send to Subcontractor" and self.purpose in ["Manufacture", "Repack"]:
+ scrap_item_dict = self.get_bom_scrap_material(self.fg_completed_qty)
+ for item in itervalues(scrap_item_dict):
+ item.idx = ''
+ if self.pro_doc and self.pro_doc.scrap_warehouse:
+ item["to_warehouse"] = self.pro_doc.scrap_warehouse
+
+ self.add_to_stock_entry_detail(scrap_item_dict, bom_no=self.bom_no)
+
def set_work_order_details(self):
if not getattr(self, "pro_doc", None):
self.pro_doc = frappe._dict()