Merge pull request #51624 from frappe/mergify/bp/version-15-hotfix/pr-50869

fix: do cancellation procedures on WO close (backport #50869)
This commit is contained in:
mergify[bot]
2026-01-09 09:48:28 +00:00
committed by GitHub
parent 1fb554c312
commit d83365734e
3 changed files with 10 additions and 3 deletions

View File

@@ -316,7 +316,7 @@ class WorkOrder(Document):
# already ordered qty # already ordered qty
ordered_qty_against_so = frappe.db.sql( ordered_qty_against_so = frappe.db.sql(
"""select sum(qty) from `tabWork Order` """select sum(qty) from `tabWork Order`
where production_item = %s and sales_order = %s and docstatus < 2 and name != %s""", where production_item = %s and sales_order = %s and docstatus < 2 and status != 'Closed' and name != %s""",
(self.production_item, self.sales_order, self.name), (self.production_item, self.sales_order, self.name),
)[0][0] )[0][0]
@@ -516,6 +516,9 @@ class WorkOrder(Document):
self.validate_cancel() self.validate_cancel()
self.db_set("status", "Cancelled") self.db_set("status", "Cancelled")
self.on_close_or_cancel()
def on_close_or_cancel(self):
if self.production_plan and frappe.db.exists( if self.production_plan and frappe.db.exists(
"Production Plan Item Reference", {"parent": self.production_plan} "Production Plan Item Reference", {"parent": self.production_plan}
): ):
@@ -843,7 +846,7 @@ class WorkOrder(Document):
qty = frappe.db.sql( qty = frappe.db.sql(
f""" select sum(qty) from f""" select sum(qty) from
`tabWork Order` where sales_order = %s and docstatus = 1 and {cond} `tabWork Order` where sales_order = %s and docstatus = 1 and status <> 'Closed' and {cond}
""", """,
(self.sales_order, (self.product_bundle_item or self.production_item)), (self.sales_order, (self.product_bundle_item or self.production_item)),
as_list=1, as_list=1,
@@ -1604,8 +1607,8 @@ def close_work_order(work_order, status):
) )
) )
work_order.on_close_or_cancel()
work_order.update_status(status) work_order.update_status(status)
work_order.update_planned_qty()
frappe.msgprint(_("Work Order has been {0}").format(status)) frappe.msgprint(_("Work Order has been {0}").format(status))
work_order.notify_update() work_order.notify_update()
return work_order.status return work_order.status

View File

@@ -1875,6 +1875,7 @@ def get_work_order_items(sales_order, for_raw_material_request=0):
& (wo.sales_order == so.name) & (wo.sales_order == so.name)
& (wo.sales_order_item == i.name) & (wo.sales_order_item == i.name)
& (wo.docstatus.lt(2)) & (wo.docstatus.lt(2))
& (wo.status != "Closed")
) )
.run()[0][0] .run()[0][0]
) )

View File

@@ -273,6 +273,9 @@ class MaterialRequest(BuyingController):
.groupby(doctype.material_request_item) .groupby(doctype.material_request_item)
) )
if self.material_request_type == "Manufacture":
query = query.where(doctype.status != "Closed")
mr_items_ordered_qty = frappe._dict(query.run()) mr_items_ordered_qty = frappe._dict(query.run())
return mr_items_ordered_qty return mr_items_ordered_qty