From 4e58c1da3ac1649d64377d53aec68e489a4a9d41 Mon Sep 17 00:00:00 2001 From: Sagar Sharma Date: Wed, 2 Feb 2022 14:56:11 +0530 Subject: [PATCH] fix: ordered_qty for production-plan-item --- erpnext/manufacturing/doctype/work_order/work_order.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index b12e157390f..fc72639be68 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -449,7 +449,13 @@ class WorkOrder(Document): def update_ordered_qty(self): if self.production_plan and self.production_plan_item: - qty = self.qty if self.docstatus == 1 else 0 + qty = frappe.get_value("Production Plan Item", self.production_plan_item, "ordered_qty") + + if self.docstatus == 1: + qty += self.qty + elif self.docstatus == 2: + qty -= self.qty + frappe.db.set_value('Production Plan Item', self.production_plan_item, 'ordered_qty', qty)