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
This commit is contained in:
marination 2022-02-08 17:55:38 +05:30
parent 7116d7ae0e
commit eaccef6116

View File

@ -28,9 +28,24 @@ from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
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 @@ class ProductionPlan(Document):
'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: