mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
feat: show budget distribution total
(cherry picked from commit f194ac093c)
This commit is contained in:
@@ -55,6 +55,7 @@ frappe.ui.form.on("Budget", {
|
|||||||
frm.doc.budget_distribution.forEach((row) => {
|
frm.doc.budget_distribution.forEach((row) => {
|
||||||
row.amount = flt((row.percent / 100) * frm.doc.budget_amount, 2);
|
row.amount = flt((row.percent / 100) * frm.doc.budget_amount, 2);
|
||||||
});
|
});
|
||||||
|
set_total_budget_amount(frm);
|
||||||
frm.refresh_field("budget_distribution");
|
frm.refresh_field("budget_distribution");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -105,6 +106,8 @@ frappe.ui.form.on("Budget Distribution", {
|
|||||||
let row = frappe.get_doc(cdt, cdn);
|
let row = frappe.get_doc(cdt, cdn);
|
||||||
if (frm.doc.budget_amount) {
|
if (frm.doc.budget_amount) {
|
||||||
row.percent = flt((row.amount / frm.doc.budget_amount) * 100, 2);
|
row.percent = flt((row.amount / frm.doc.budget_amount) * 100, 2);
|
||||||
|
|
||||||
|
set_total_budget_amount(frm);
|
||||||
frm.refresh_field("budget_distribution");
|
frm.refresh_field("budget_distribution");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -112,11 +115,23 @@ frappe.ui.form.on("Budget Distribution", {
|
|||||||
let row = frappe.get_doc(cdt, cdn);
|
let row = frappe.get_doc(cdt, cdn);
|
||||||
if (frm.doc.budget_amount) {
|
if (frm.doc.budget_amount) {
|
||||||
row.amount = flt((row.percent / 100) * frm.doc.budget_amount, 2);
|
row.amount = flt((row.percent / 100) * frm.doc.budget_amount, 2);
|
||||||
|
|
||||||
|
set_total_budget_amount(frm);
|
||||||
frm.refresh_field("budget_distribution");
|
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) {
|
function toggle_distribution_fields(frm) {
|
||||||
const grid = frm.fields_dict.budget_distribution.grid;
|
const grid = frm.fields_dict.budget_distribution.grid;
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,10 @@
|
|||||||
"distribute_equally",
|
"distribute_equally",
|
||||||
"section_break_fpdt",
|
"section_break_fpdt",
|
||||||
"budget_distribution",
|
"budget_distribution",
|
||||||
|
"section_break_wkqb",
|
||||||
|
"column_break_paum",
|
||||||
|
"column_break_nwor",
|
||||||
|
"budget_distribution_total",
|
||||||
"section_break_6",
|
"section_break_6",
|
||||||
"applicable_on_material_request",
|
"applicable_on_material_request",
|
||||||
"action_if_annual_budget_exceeded_on_mr",
|
"action_if_annual_budget_exceeded_on_mr",
|
||||||
@@ -222,7 +226,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "section_break_fpdt",
|
"fieldname": "section_break_fpdt",
|
||||||
"fieldtype": "Section Break"
|
"fieldtype": "Section Break",
|
||||||
|
"hide_border": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "budget_distribution",
|
"fieldname": "budget_distribution",
|
||||||
@@ -303,13 +308,32 @@
|
|||||||
"options": "Monthly\nQuarterly\nHalf-Yearly\nYearly",
|
"options": "Monthly\nQuarterly\nHalf-Yearly\nYearly",
|
||||||
"read_only_depends_on": "eval: doc.revision_of",
|
"read_only_depends_on": "eval: doc.revision_of",
|
||||||
"reqd": 1
|
"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,
|
"grid_page_length": 50,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2025-11-19 17:00:00.648224",
|
"modified": "2025-12-10 02:35:01.197613",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Budget",
|
"name": "Budget",
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class Budget(Document):
|
|||||||
budget_against: DF.Literal["", "Cost Center", "Project"]
|
budget_against: DF.Literal["", "Cost Center", "Project"]
|
||||||
budget_amount: DF.Currency
|
budget_amount: DF.Currency
|
||||||
budget_distribution: DF.Table[BudgetDistribution]
|
budget_distribution: DF.Table[BudgetDistribution]
|
||||||
|
budget_distribution_total: DF.Currency
|
||||||
budget_end_date: DF.Date | None
|
budget_end_date: DF.Date | None
|
||||||
budget_start_date: DF.Date | None
|
budget_start_date: DF.Date | None
|
||||||
company: DF.Link
|
company: DF.Link
|
||||||
@@ -230,6 +231,7 @@ class Budget(Document):
|
|||||||
|
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
self.allocate_budget()
|
self.allocate_budget()
|
||||||
|
self.budget_distribution_total = sum(flt(row.amount) for row in self.budget_distribution)
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
self.validate_distribution_totals()
|
self.validate_distribution_totals()
|
||||||
@@ -305,6 +307,8 @@ class Budget(Document):
|
|||||||
row.end_date = end_date
|
row.end_date = end_date
|
||||||
self.add_allocated_amount(row, row_percent)
|
self.add_allocated_amount(row, row_percent)
|
||||||
|
|
||||||
|
self.budget_distribution_total = self.budget_amount
|
||||||
|
|
||||||
def get_budget_periods(self):
|
def get_budget_periods(self):
|
||||||
"""Return list of (start_date, end_date) tuples based on frequency."""
|
"""Return list of (start_date, end_date) tuples based on frequency."""
|
||||||
frequency = self.distribution_frequency
|
frequency = self.distribution_frequency
|
||||||
|
|||||||
Reference in New Issue
Block a user