diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 51d4f66b9bb..a894f8cb44a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -448,4 +448,4 @@ erpnext.patches.v16_0.update_serial_batch_entries erpnext.patches.v16_0.set_company_wise_warehouses erpnext.patches.v16_0.set_valuation_method_on_companies erpnext.patches.v15_0.migrate_old_item_wise_tax_detail_data_to_table - +erpnext.patches.v16_0.set_total_budget_amount diff --git a/erpnext/patches/v16_0/set_total_budget_amount.py b/erpnext/patches/v16_0/set_total_budget_amount.py new file mode 100644 index 00000000000..163f0f17274 --- /dev/null +++ b/erpnext/patches/v16_0/set_total_budget_amount.py @@ -0,0 +1,16 @@ +import frappe + + +def execute(): + if frappe.db.has_column("Budget", "total_budget_amount"): + frappe.db.sql( + """ + UPDATE `tabBudget` b + SET b.total_budget_amount = ( + SELECT SUM(ba.budget_amount) + FROM `tabBudget Account` ba + WHERE ba.parent = b.name + ) + WHERE IFNULL(b.total_budget_amount, 0) = 0 + """ + )