diff --git a/erpnext/accounts/doctype/budget/budget.js b/erpnext/accounts/doctype/budget/budget.js index 6f8e0cdd43a..5128fdc9c92 100644 --- a/erpnext/accounts/doctype/budget/budget.js +++ b/erpnext/accounts/doctype/budget/budget.js @@ -55,6 +55,7 @@ frappe.ui.form.on("Budget", { frm.doc.budget_distribution.forEach((row) => { row.amount = flt((row.percent / 100) * frm.doc.budget_amount, 2); }); + set_total_budget_amount(frm); frm.refresh_field("budget_distribution"); } }, @@ -105,6 +106,8 @@ frappe.ui.form.on("Budget Distribution", { let row = frappe.get_doc(cdt, cdn); if (frm.doc.budget_amount) { row.percent = flt((row.amount / frm.doc.budget_amount) * 100, 2); + + set_total_budget_amount(frm); frm.refresh_field("budget_distribution"); } }, @@ -112,11 +115,23 @@ frappe.ui.form.on("Budget Distribution", { let row = frappe.get_doc(cdt, cdn); if (frm.doc.budget_amount) { row.amount = flt((row.percent / 100) * frm.doc.budget_amount, 2); + + set_total_budget_amount(frm); frm.refresh_field("budget_distribution"); } }, }); +function set_total_budget_amount(frm) { + let total = 0; + + (frm.doc.budget_distribution || []).forEach((row) => { + total += flt(row.amount); + }); + + frm.set_value("budget_distribution_total", total); +} + function toggle_distribution_fields(frm) { const grid = frm.fields_dict.budget_distribution.grid; diff --git a/erpnext/accounts/doctype/budget/budget.json b/erpnext/accounts/doctype/budget/budget.json index 8476a2831f0..960d62e4c99 100644 --- a/erpnext/accounts/doctype/budget/budget.json +++ b/erpnext/accounts/doctype/budget/budget.json @@ -25,6 +25,10 @@ "distribute_equally", "section_break_fpdt", "budget_distribution", + "section_break_wkqb", + "column_break_paum", + "column_break_nwor", + "budget_distribution_total", "section_break_6", "applicable_on_material_request", "action_if_annual_budget_exceeded_on_mr", @@ -222,7 +226,8 @@ }, { "fieldname": "section_break_fpdt", - "fieldtype": "Section Break" + "fieldtype": "Section Break", + "hide_border": 1 }, { "fieldname": "budget_distribution", @@ -303,13 +308,32 @@ "options": "Monthly\nQuarterly\nHalf-Yearly\nYearly", "read_only_depends_on": "eval: doc.revision_of", "reqd": 1 + }, + { + "fieldname": "section_break_wkqb", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_paum", + "fieldtype": "Column Break" + }, + { + "fieldname": "column_break_nwor", + "fieldtype": "Column Break" + }, + { + "fieldname": "budget_distribution_total", + "fieldtype": "Currency", + "label": "Budget Distribution Total", + "no_copy": 1, + "read_only": 1 } ], "grid_page_length": 50, "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2025-11-19 17:00:00.648224", + "modified": "2025-12-10 02:35:01.197613", "modified_by": "Administrator", "module": "Accounts", "name": "Budget", diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py index 7280f2ee5fc..39528da99db 100644 --- a/erpnext/accounts/doctype/budget/budget.py +++ b/erpnext/accounts/doctype/budget/budget.py @@ -53,6 +53,7 @@ class Budget(Document): budget_against: DF.Literal["", "Cost Center", "Project"] budget_amount: DF.Currency budget_distribution: DF.Table[BudgetDistribution] + budget_distribution_total: DF.Currency budget_end_date: DF.Date | None budget_start_date: DF.Date | None company: DF.Link @@ -230,6 +231,7 @@ class Budget(Document): def before_save(self): self.allocate_budget() + self.budget_distribution_total = sum(flt(row.amount) for row in self.budget_distribution) def on_update(self): self.validate_distribution_totals() @@ -305,6 +307,8 @@ class Budget(Document): row.end_date = end_date self.add_allocated_amount(row, row_percent) + self.budget_distribution_total = self.budget_amount + def get_budget_periods(self): """Return list of (start_date, end_date) tuples based on frequency.""" frequency = self.distribution_frequency