fix: add validation for PO in Stock Entry (#31974)
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index f719c1e..c68d1db 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -116,6 +116,7 @@
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 @@
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