mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-14 15:11:52 +00:00
fix: lock budget distribution table and guard against null distribution rows
(cherry picked from commit d37e5cd97d)
This commit is contained in:
@@ -136,6 +136,9 @@ function set_total_budget_amount(frm) {
|
|||||||
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;
|
||||||
|
|
||||||
|
frm.set_df_property("budget_distribution", "cannot_add_rows", true);
|
||||||
|
frm.set_df_property("budget_distribution", "cannot_delete_rows", true);
|
||||||
|
|
||||||
["amount", "percent"].forEach((field) => {
|
["amount", "percent"].forEach((field) => {
|
||||||
grid.update_docfield_property(field, "read_only", frm.doc.distribute_equally);
|
grid.update_docfield_property(field, "read_only", frm.doc.distribute_equally);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -355,8 +355,8 @@ class Budget(Document):
|
|||||||
if self.should_regenerate_budget_distribution():
|
if self.should_regenerate_budget_distribution():
|
||||||
return
|
return
|
||||||
|
|
||||||
total_amount = sum(d.amount for d in self.budget_distribution)
|
total_amount = sum(flt(d.amount) for d in self.budget_distribution)
|
||||||
total_percent = sum(d.percent for d in self.budget_distribution)
|
total_percent = sum(flt(d.percent) for d in self.budget_distribution)
|
||||||
|
|
||||||
if flt(abs(total_amount - self.budget_amount), 2) > 0.10:
|
if flt(abs(total_amount - self.budget_amount), 2) > 0.10:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Start Date",
|
"label": "Start Date",
|
||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
|
"reqd": 1,
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -25,26 +26,29 @@
|
|||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "End Date",
|
"label": "End Date",
|
||||||
"read_only": 1
|
"read_only": 1,
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "amount",
|
"fieldname": "amount",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Amount"
|
"label": "Amount",
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "percent",
|
"fieldname": "percent",
|
||||||
"fieldtype": "Percent",
|
"fieldtype": "Percent",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Percent"
|
"label": "Percent",
|
||||||
|
"reqd": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"grid_page_length": 50,
|
"grid_page_length": 50,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2025-11-03 13:18:28.398198",
|
"modified": "2026-06-18 11:23:17.669733",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Budget Distribution",
|
"name": "Budget Distribution",
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ class BudgetDistribution(Document):
|
|||||||
from frappe.types import DF
|
from frappe.types import DF
|
||||||
|
|
||||||
amount: DF.Currency
|
amount: DF.Currency
|
||||||
end_date: DF.Date | None
|
end_date: DF.Date
|
||||||
parent: DF.Data
|
parent: DF.Data
|
||||||
parentfield: DF.Data
|
parentfield: DF.Data
|
||||||
parenttype: DF.Data
|
parenttype: DF.Data
|
||||||
percent: DF.Percent
|
percent: DF.Percent
|
||||||
start_date: DF.Date | None
|
start_date: DF.Date
|
||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -84,7 +84,13 @@ def build_budget_map(budget_records, filters):
|
|||||||
budget_distributions = get_budget_distributions(budget)
|
budget_distributions = get_budget_distributions(budget)
|
||||||
|
|
||||||
for row in budget_distributions:
|
for row in budget_distributions:
|
||||||
|
if not row.start_date or not row.end_date:
|
||||||
|
continue
|
||||||
|
|
||||||
months = get_months_in_range(row.start_date, row.end_date)
|
months = get_months_in_range(row.start_date, row.end_date)
|
||||||
|
if not months:
|
||||||
|
continue
|
||||||
|
|
||||||
monthly_budget = flt(row.amount) / len(months)
|
monthly_budget = flt(row.amount) / len(months)
|
||||||
|
|
||||||
for month_date in months:
|
for month_date in months:
|
||||||
|
|||||||
Reference in New Issue
Block a user