From a99f926a4b23ce4d1c2fb65cff833eef5177902a Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Fri, 27 Dec 2019 12:21:15 +0530 Subject: [PATCH] fix: incorrect validation for scrap items (#20109) --- erpnext/stock/doctype/stock_entry/stock_entry.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 47f6cf64f5..18af062147 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -585,12 +585,18 @@ class StockEntry(StockController): def validate_finished_goods(self): """validation: finished good quantity should be same as manufacturing quantity""" + if not self.work_order: return + items_with_target_warehouse = [] allowance_percentage = flt(frappe.db.get_single_value("Manufacturing Settings", "overproduction_percentage_for_work_order")) + production_item, wo_qty = frappe.db.get_value("Work Order", + self.work_order, ["production_item", "qty"]) + for d in self.get('items'): - if self.purpose != "Send to Subcontractor" and d.bom_no and flt(d.transfer_qty) > flt(self.fg_completed_qty) and (d.t_warehouse != getattr(self, "pro_doc", frappe._dict()).scrap_warehouse): + if (self.purpose != "Send to Subcontractor" and d.bom_no + and flt(d.transfer_qty) > flt(self.fg_completed_qty) and d.item_code == production_item): frappe.throw(_("Quantity in row {0} ({1}) must be same as manufactured quantity {2}"). \ format(d.idx, d.transfer_qty, self.fg_completed_qty)) @@ -598,9 +604,6 @@ class StockEntry(StockController): items_with_target_warehouse.append(d.item_code) if self.work_order and self.purpose == "Manufacture": - production_item, wo_qty = frappe.db.get_value("Work Order", - self.work_order, ["production_item", "qty"]) - allowed_qty = wo_qty + (allowance_percentage/100 * wo_qty) if self.fg_completed_qty > allowed_qty: frappe.throw(_("For quantity {0} should not be grater than work order quantity {1}")