fix: update production plan status (backport #27567)

* fix: update production plan status #27567

fix: update production plan status
(cherry picked from commit 05831b18ad)

# Conflicts:
#	erpnext/patches.txt

* fix: resolve conflicts

Co-authored-by: Alan <2.alan.tom@gmail.com>
Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
mergify[bot]
2021-10-27 13:20:51 +05:30
committed by GitHub
parent 6acab32934
commit d4b4bd9d97
3 changed files with 42 additions and 1 deletions

View File

@@ -311,7 +311,7 @@ class ProductionPlan(Document):
if self.total_produced_qty > 0:
self.status = "In Process"
if self.total_produced_qty >= self.total_planned_qty:
if self.check_have_work_orders_completed():
self.status = "Completed"
if self.status != 'Completed':
@@ -575,6 +575,15 @@ class ProductionPlan(Document):
self.append("sub_assembly_items", data)
def check_have_work_orders_completed(self):
wo_status = frappe.db.get_list(
"Work Order",
filters={"production_plan": self.name},
fields="status",
pluck="status"
)
return all(s == "Completed" for s in wo_status)
@frappe.whitelist()
def download_raw_materials(doc, warehouses=None):
if isinstance(doc, str):

View File

@@ -329,3 +329,4 @@ erpnext.patches.v13_0.trim_sales_invoice_custom_field_length
erpnext.patches.v13_0.enable_scheduler_job_for_item_reposting
erpnext.patches.v13_0.requeue_failed_reposts
erpnext.patches.v13_0.fetch_thumbnail_in_website_items
erpnext.patches.v12_0.update_production_plan_status

View File

@@ -0,0 +1,31 @@
# Copyright (c) 2021, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
def execute():
frappe.reload_doc("manufacturing", "doctype", "production_plan")
frappe.db.sql("""
UPDATE `tabProduction Plan` ppl
SET status = "Completed"
WHERE ppl.name IN (
SELECT ss.name FROM (
SELECT
(
count(wo.status = "Completed") =
count(pp.name)
) =
(
pp.status != "Completed"
AND pp.total_produced_qty >= pp.total_planned_qty
) AS should_set,
pp.name AS name
FROM
`tabWork Order` wo INNER JOIN`tabProduction Plan` pp
ON wo.production_plan = pp.name
GROUP BY pp.name
HAVING should_set = 1
) ss
)
""")