fix: incorrect produced qty in the production plan (#19569)
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js
index 5198937..3b24d0f 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.js
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js
@@ -3,6 +3,11 @@
frappe.ui.form.on('Production Plan', {
setup: function(frm) {
+ frm.custom_make_buttons = {
+ 'Work Order': 'Work Order',
+ 'Material Request': 'Material Request',
+ };
+
frm.fields_dict['po_items'].grid.get_field('warehouse').get_query = function(doc) {
return {
filters: {
diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py
index ae4d9be..6ea3dc8 100644
--- a/erpnext/manufacturing/doctype/work_order/work_order.py
+++ b/erpnext/manufacturing/doctype/work_order/work_order.py
@@ -223,7 +223,15 @@
def update_production_plan_status(self):
production_plan = frappe.get_doc('Production Plan', self.production_plan)
- production_plan.run_method("update_produced_qty", self.produced_qty, self.production_plan_item)
+ produced_qty = 0
+ if self.production_plan_item:
+ total_qty = frappe.get_all("Work Order", fields = "sum(produced_qty) as produced_qty",
+ filters = {'docstatus': 1, 'production_plan': self.production_plan,
+ 'production_plan_item': self.production_plan_item}, as_list=1)
+
+ produced_qty = total_qty[0][0] if total_qty else 0
+
+ production_plan.run_method("update_produced_qty", produced_qty, self.production_plan_item)
def on_submit(self):
if not self.wip_warehouse: