diff --git a/erpnext/accounts/doctype/budget/budget.json b/erpnext/accounts/doctype/budget/budget.json index a17919c52b0..bf1e7d091c1 100644 --- a/erpnext/accounts/doctype/budget/budget.json +++ b/erpnext/accounts/doctype/budget/budget.json @@ -188,7 +188,7 @@ "fieldtype": "Select", "label": "Series", "no_copy": 1, - "options": "BUDGET-.YYYY.-", + "options": "BUDGET-.########", "print_hide": 1, "reqd": 1, "set_only_once": 1 @@ -308,7 +308,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2025-11-06 10:36:35.565701", + "modified": "2025-11-17 17:38:27.759355", "modified_by": "Administrator", "module": "Accounts", "name": "Budget", diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py index 5bbf8dfc0bd..ad16cf00a9a 100644 --- a/erpnext/accounts/doctype/budget/budget.py +++ b/erpnext/accounts/doctype/budget/budget.py @@ -60,7 +60,7 @@ class Budget(Document): distribute_equally: DF.Check distribution_frequency: DF.Literal["Monthly", "Quarterly", "Half-Yearly", "Yearly"] from_fiscal_year: DF.Link - naming_series: DF.Literal["BUDGET-.YYYY.-"] + naming_series: DF.Literal["BUDGET-.########"] project: DF.Link | None revision_of: DF.Data | None to_fiscal_year: DF.Link diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 7d3296fe327..74f6e8a275b 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.migrate_submitted_budgets_to_new_structure +erpnext.patches.v16_0.migrate_budget_records_to_new_structure diff --git a/erpnext/patches/v16_0/migrate_submitted_budgets_to_new_structure.py b/erpnext/patches/v16_0/migrate_budget_records_to_new_structure.py similarity index 76% rename from erpnext/patches/v16_0/migrate_submitted_budgets_to_new_structure.py rename to erpnext/patches/v16_0/migrate_budget_records_to_new_structure.py index d803a852d3f..1c94f0e34bd 100644 --- a/erpnext/patches/v16_0/migrate_submitted_budgets_to_new_structure.py +++ b/erpnext/patches/v16_0/migrate_budget_records_to_new_structure.py @@ -3,14 +3,14 @@ from frappe.utils import add_months, flt, get_first_day, get_last_day def execute(): - submitted_budgets = frappe.get_all("Budget", filters={"docstatus": 1}, pluck="name") + budgets = frappe.get_all("Budget", filters={"docstatus": ["in", [0, 1]]}, pluck="name") - for old_budget in submitted_budgets: - old_bud = frappe.get_doc("Budget", old_budget) + for budget in budgets: + old_budget = frappe.get_doc("Budget", budget) old_accounts = frappe.get_all( "Budget Account", - filters={"parent": old_bud.name}, + filters={"parent": old_budget.name}, fields=["account", "budget_amount"], order_by="idx asc", ) @@ -19,10 +19,10 @@ def execute(): continue old_distribution = [] - if old_bud.monthly_distribution: + if old_budget.monthly_distribution: old_distribution = frappe.get_all( "Monthly Distribution Percentage", - filters={"parent": old_bud.monthly_distribution}, + filters={"parent": old_budget.monthly_distribution}, fields=["percentage_allocation"], order_by="idx asc", ) @@ -32,16 +32,16 @@ def execute(): else: percentage_list = [100 / 12] * 12 - fy = frappe.get_doc("Fiscal Year", old_bud.fiscal_year) + fy = frappe.get_doc("Fiscal Year", old_budget.fiscal_year) fy_start = fy.year_start_date fy_end = fy.year_end_date for acc in old_accounts: new = frappe.new_doc("Budget") - new.company = old_bud.company - new.cost_center = old_bud.cost_center - new.project = old_bud.project + new.company = old_budget.company + new.cost_center = old_budget.cost_center + new.project = old_budget.project new.fiscal_year = fy.name new.from_fiscal_year = fy.name @@ -71,8 +71,8 @@ def execute(): ] for field in fields_to_copy: - if hasattr(old_bud, field): - new.set(field, old_bud.get(field)) + if hasattr(old_budget, field): + new.set(field, old_budget.get(field)) start = fy_start for percentage in percentage_list: @@ -92,11 +92,14 @@ def execute(): start = add_months(start, 1) new.flags.ignore_validate = True - new.flags.ignore_mandatory = True new.flags.ignore_links = True - new.flags.ignore_permissions = True new.insert(ignore_permissions=True, ignore_mandatory=True) - new.submit() - old_bud.cancel() + if old_budget.docstatus == 1: + new.submit() + + if old_budget.docstatus == 1: + old_budget.cancel() + else: + old_budget.delete()