From 8566832dd51bc78d04ae2b0268883b4ae890a98a Mon Sep 17 00:00:00 2001 From: Sagar Sharma Date: Thu, 25 Aug 2022 15:05:13 +0530 Subject: [PATCH] fix: add validation for PO in Stock Entry (#31974) --- erpnext/stock/doctype/stock_entry/stock_entry.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index f719c1efda..c68d1db279 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -116,6 +116,7 @@ class StockEntry(StockController): self.validate_warehouse() self.validate_work_order() self.validate_bom() + self.validate_purchase_order() if self.purpose in ("Manufacture", "Repack"): self.mark_finished_and_scrap_items() @@ -946,6 +947,19 @@ class StockEntry(StockController): item_code = d.original_item or d.item_code validate_bom_no(item_code, d.bom_no) + def validate_purchase_order(self): + if self.purpose == "Send to Subcontractor" and self.get("purchase_order"): + is_old_subcontracting_flow = frappe.db.get_value( + "Purchase Order", self.purchase_order, "is_old_subcontracting_flow" + ) + + if not is_old_subcontracting_flow: + frappe.throw( + _("Please select Subcontracting Order instead of Purchase Order {0}").format( + self.purchase_order + ) + ) + def mark_finished_and_scrap_items(self): if any([d.item_code for d in self.items if (d.is_finished_item and d.t_warehouse)]): return