fix(patch): remove dead links to ProdPlan Item
This commit is contained in:
parent
1af13ca4bf
commit
d3e90ed8c8
@ -358,4 +358,5 @@ erpnext.patches.v13_0.update_accounts_in_loan_docs
|
||||
erpnext.patches.v14_0.update_batch_valuation_flag
|
||||
erpnext.patches.v14_0.delete_non_profit_doctypes
|
||||
erpnext.patches.v14_0.update_employee_advance_status
|
||||
erpnext.patches.v13_0.add_cost_center_in_loans
|
||||
erpnext.patches.v13_0.add_cost_center_in_loans
|
||||
erpnext.patches.v13_0.remove_unknown_links_to_prod_plan_items
|
||||
|
@ -0,0 +1,34 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
"""
|
||||
Remove "production_plan_item" field where linked field doesn't exist in tha table.
|
||||
"""
|
||||
|
||||
work_order = frappe.qb.DocType("Work Order")
|
||||
pp_item = frappe.qb.DocType("Production Plan Item")
|
||||
|
||||
broken_work_orders = (
|
||||
frappe.qb
|
||||
.from_(work_order)
|
||||
.left_join(pp_item).on(work_order.production_plan_item == pp_item.name)
|
||||
.select(work_order.name)
|
||||
.where(
|
||||
(work_order.docstatus == 0)
|
||||
& (work_order.production_plan_item.notnull())
|
||||
& (work_order.production_plan_item.like("new-production-plan%"))
|
||||
& (pp_item.name.isnull())
|
||||
)
|
||||
).run(pluck=True)
|
||||
|
||||
if not broken_work_orders:
|
||||
return
|
||||
|
||||
(frappe.qb
|
||||
.update(work_order)
|
||||
.set(work_order.production_plan_item, None)
|
||||
.where(work_order.name.isin(broken_work_orders))
|
||||
).run()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user