mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-29 18:04:46 +00:00
feat: Budget Revision
This commit is contained in:
@@ -32,6 +32,16 @@ frappe.ui.form.on("Budget", {
|
|||||||
|
|
||||||
refresh: function (frm) {
|
refresh: function (frm) {
|
||||||
frm.trigger("toggle_reqd_fields");
|
frm.trigger("toggle_reqd_fields");
|
||||||
|
|
||||||
|
if (!frm.doc.__islocal && frm.doc.docstatus == 1) {
|
||||||
|
frm.add_custom_button(
|
||||||
|
__("Revise Budget"),
|
||||||
|
function () {
|
||||||
|
frm.events.revise_budget_action(frm);
|
||||||
|
},
|
||||||
|
__("Actions")
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
budget_against: function (frm) {
|
budget_against: function (frm) {
|
||||||
@@ -51,4 +61,27 @@ frappe.ui.form.on("Budget", {
|
|||||||
frm.toggle_reqd("cost_center", frm.doc.budget_against == "Cost Center");
|
frm.toggle_reqd("cost_center", frm.doc.budget_against == "Cost Center");
|
||||||
frm.toggle_reqd("project", frm.doc.budget_against == "Project");
|
frm.toggle_reqd("project", frm.doc.budget_against == "Project");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
revise_budget_action: function (frm) {
|
||||||
|
frappe.confirm(
|
||||||
|
__(
|
||||||
|
"Are you sure you want to revise this budget? The current budget will be cancelled and a new draft will be created."
|
||||||
|
),
|
||||||
|
function () {
|
||||||
|
frappe.call({
|
||||||
|
method: "erpnext.accounts.doctype.budget.budget.revise_budget",
|
||||||
|
args: { budget_name: frm.doc.name },
|
||||||
|
callback: function (r) {
|
||||||
|
if (r.message) {
|
||||||
|
frappe.msgprint(__("New revised budget created successfully"));
|
||||||
|
frappe.set_route("Form", "Budget", r.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
frappe.msgprint(__("Revision cancelled"));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -45,7 +45,9 @@
|
|||||||
"column_break_ybiq",
|
"column_break_ybiq",
|
||||||
"total_budget_amount",
|
"total_budget_amount",
|
||||||
"section_break_fpdt",
|
"section_break_fpdt",
|
||||||
"budget_distribution"
|
"budget_distribution",
|
||||||
|
"section_break_kkan",
|
||||||
|
"revision_of"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -313,13 +315,23 @@
|
|||||||
"fieldname": "budget_amount",
|
"fieldname": "budget_amount",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"label": "Budget Amount"
|
"label": "Budget Amount"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_kkan",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "revision_of",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Revision Of",
|
||||||
|
"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-10-15 02:29:23.201493",
|
"modified": "2025-10-15 16:55:25.157976",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Budget",
|
"name": "Budget",
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ class Budget(Document):
|
|||||||
monthly_distribution: DF.Link | None
|
monthly_distribution: DF.Link | None
|
||||||
naming_series: DF.Literal["BUDGET-.YYYY.-"]
|
naming_series: DF.Literal["BUDGET-.YYYY.-"]
|
||||||
project: DF.Link | None
|
project: DF.Link | None
|
||||||
|
revision_of: DF.Data | None
|
||||||
total_budget_amount: DF.Currency
|
total_budget_amount: DF.Currency
|
||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
@@ -159,6 +160,9 @@ class Budget(Document):
|
|||||||
self.allocate_budget()
|
self.allocate_budget()
|
||||||
|
|
||||||
def allocate_budget(self):
|
def allocate_budget(self):
|
||||||
|
if self.revision_of:
|
||||||
|
return
|
||||||
|
|
||||||
self.set("budget_distribution", [])
|
self.set("budget_distribution", [])
|
||||||
if not (self.budget_start_date and self.budget_end_date and self.allocation_frequency):
|
if not (self.budget_start_date and self.budget_end_date and self.allocation_frequency):
|
||||||
return
|
return
|
||||||
@@ -167,7 +171,7 @@ class Budget(Document):
|
|||||||
end = getdate(self.budget_end_date)
|
end = getdate(self.budget_end_date)
|
||||||
freq = self.allocation_frequency
|
freq = self.allocation_frequency
|
||||||
|
|
||||||
months = month_diff(end, start) + 1
|
months = month_diff(end, start)
|
||||||
if freq == "Monthly":
|
if freq == "Monthly":
|
||||||
total_periods = months
|
total_periods = months
|
||||||
elif freq == "Quarterly":
|
elif freq == "Quarterly":
|
||||||
@@ -652,3 +656,20 @@ def get_expense_cost_center(doctype, args):
|
|||||||
return frappe.db.get_value(
|
return frappe.db.get_value(
|
||||||
doctype, args.get(frappe.scrub(doctype)), ["cost_center", "default_expense_account"]
|
doctype, args.get(frappe.scrub(doctype)), ["cost_center", "default_expense_account"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def revise_budget(budget_name):
|
||||||
|
old_budget = frappe.get_doc("Budget", budget_name)
|
||||||
|
|
||||||
|
if old_budget.docstatus == 1:
|
||||||
|
old_budget.cancel()
|
||||||
|
frappe.db.commit()
|
||||||
|
|
||||||
|
new_budget = frappe.copy_doc(old_budget)
|
||||||
|
new_budget.docstatus = 0
|
||||||
|
new_budget.revision_of = old_budget.name
|
||||||
|
new_budget.posting_date = frappe.utils.nowdate()
|
||||||
|
new_budget.insert()
|
||||||
|
|
||||||
|
return new_budget.name
|
||||||
|
|||||||
@@ -29,20 +29,22 @@
|
|||||||
"fieldname": "amount",
|
"fieldname": "amount",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Amount"
|
"label": "Amount",
|
||||||
|
"read_only_depends_on": "eval:doc.end_date < frappe.datetime.get_today()"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "percent",
|
"fieldname": "percent",
|
||||||
"fieldtype": "Percent",
|
"fieldtype": "Percent",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Percent"
|
"label": "Percent",
|
||||||
|
"read_only_depends_on": "eval:doc.end_date < frappe.datetime.get_today()"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"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-10-12 23:47:30.393908",
|
"modified": "2025-10-15 16:53:23.462653",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Budget Distribution",
|
"name": "Budget Distribution",
|
||||||
|
|||||||
Reference in New Issue
Block a user