fix: Initialise pending qty as planned qty for independent item rows in Prod Plan
- Rows that are not fetched from MR or SO, had pending qty 0 throughout
- Initialise pending qty on save only.
- After submit this field will be updated by work order/stock entry
- Bring functions in `validate()` closer to the top
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index a6d4dfc..839547d 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -28,9 +28,24 @@
class ProductionPlan(Document):
def validate(self):
+ self.set_pending_qty_in_row_without_reference()
self.calculate_total_planned_qty()
self.set_status()
+ def set_pending_qty_in_row_without_reference(self):
+ "Set Pending Qty in independent rows (not from SO or MR)."
+ if self.docstatus > 0: # set only to initialise value before submit
+ return
+
+ for item in self.po_items:
+ if not item.get("sales_order") or not item.get("material_request"):
+ item.pending_qty = item.planned_qty
+
+ def calculate_total_planned_qty(self):
+ self.total_planned_qty = 0
+ for d in self.po_items:
+ self.total_planned_qty += flt(d.planned_qty)
+
def validate_data(self):
for d in self.get('po_items'):
if not d.bom_no:
@@ -263,11 +278,6 @@
'qty': so_detail['qty']
})
- def calculate_total_planned_qty(self):
- self.total_planned_qty = 0
- for d in self.po_items:
- self.total_planned_qty += flt(d.planned_qty)
-
def calculate_total_produced_qty(self):
self.total_produced_qty = 0
for d in self.po_items: