mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 11:19:09 +00:00
refactor: calculate summary on tree navigation
(cherry picked from commit f7b7b2b438)
This commit is contained in:
@@ -17,7 +17,6 @@ frappe.ui.form.on("Bisect Accounting Statements", {
|
|||||||
frm.add_custom_button(__('Build Tree'), () =>
|
frm.add_custom_button(__('Build Tree'), () =>
|
||||||
frm.trigger("build_tree")
|
frm.trigger("build_tree")
|
||||||
);
|
);
|
||||||
// frm.change_custom_button_type(__('Bisect'), null, 'primary');
|
|
||||||
},
|
},
|
||||||
bisect_left(frm) {
|
bisect_left(frm) {
|
||||||
frm.call({
|
frm.call({
|
||||||
@@ -54,5 +53,5 @@ frappe.ui.form.on("Bisect Accounting Statements", {
|
|||||||
console.log(r);
|
console.log(r);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,13 +7,26 @@
|
|||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
|
"company",
|
||||||
|
"column_break_hcam",
|
||||||
"from_date",
|
"from_date",
|
||||||
"column_break_qxbi",
|
"column_break_qxbi",
|
||||||
"to_date",
|
"to_date",
|
||||||
"column_break_iwny",
|
"column_break_iwny",
|
||||||
"algorithm",
|
"algorithm",
|
||||||
"section_break_zbty",
|
"section_break_zbty",
|
||||||
"current_node"
|
"current_node",
|
||||||
|
"sandbox",
|
||||||
|
"section_break_hmsy",
|
||||||
|
"current_from_date",
|
||||||
|
"column_break_uqyd",
|
||||||
|
"current_to_date",
|
||||||
|
"section_break_hbyo",
|
||||||
|
"p_l_summary",
|
||||||
|
"column_break_aivo",
|
||||||
|
"b_s_summary",
|
||||||
|
"column_break_gvwx",
|
||||||
|
"difference"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -50,13 +63,73 @@
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Current Node",
|
"label": "Current Node",
|
||||||
"options": "Nodes"
|
"options": "Nodes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "sandbox",
|
||||||
|
"fieldtype": "HTML",
|
||||||
|
"label": "sandbox"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_hmsy",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "current_from_date",
|
||||||
|
"fieldtype": "Datetime",
|
||||||
|
"label": "Current From Date"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "current_to_date",
|
||||||
|
"fieldtype": "Datetime",
|
||||||
|
"label": "Current To Date"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_uqyd",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_hbyo",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "p_l_summary",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "P&L Summary"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "b_s_summary",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Balance Sheet Summary"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "difference",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Difference"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_aivo",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_gvwx",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "company",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Company",
|
||||||
|
"options": "Company"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_hcam",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hide_toolbar": 1,
|
"hide_toolbar": 1,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-09-26 12:09:23.649156",
|
"modified": "2023-09-26 21:07:14.290963",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Bisect Accounting Statements",
|
"name": "Bisect Accounting Statements",
|
||||||
|
|||||||
@@ -116,6 +116,20 @@ class BisectAccountingStatements(Document):
|
|||||||
root = frappe.db.get_all("Nodes", filters={"root": ["is", "not set"]})[0]
|
root = frappe.db.get_all("Nodes", filters={"root": ["is", "not set"]})[0]
|
||||||
frappe.db.set_single_value("Bisect Accounting Statements", "current_node", root.name)
|
frappe.db.set_single_value("Bisect Accounting Statements", "current_node", root.name)
|
||||||
|
|
||||||
|
def get_report_summary(self):
|
||||||
|
filters = {
|
||||||
|
"company": self.company,
|
||||||
|
"filter_based_on": "Date Range",
|
||||||
|
"period_start_date": self.current_from_date,
|
||||||
|
"period_end_date": self.current_to_date,
|
||||||
|
"periodicity": "Yearly",
|
||||||
|
}
|
||||||
|
pl_summary = frappe.get_doc("Report", "Profit and Loss Statement")
|
||||||
|
self.p_l_summary = pl_summary.execute_script_report(filters=filters)[5]
|
||||||
|
bs_summary = frappe.get_doc("Report", "Balance Sheet")
|
||||||
|
self.b_s_summary = bs_summary.execute_script_report(filters=filters)[5]
|
||||||
|
self.difference = abs(self.p_l_summary - self.b_s_summary)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def bisect_left(self):
|
def bisect_left(self):
|
||||||
if self.current_node is not None:
|
if self.current_node is not None:
|
||||||
@@ -123,8 +137,9 @@ class BisectAccountingStatements(Document):
|
|||||||
if cur_node.left_child is not None:
|
if cur_node.left_child is not None:
|
||||||
lft_node = frappe.get_doc("Nodes", cur_node.left_child)
|
lft_node = frappe.get_doc("Nodes", cur_node.left_child)
|
||||||
self.current_node = cur_node.left_child
|
self.current_node = cur_node.left_child
|
||||||
self.from_date = lft_node.period_from_date
|
self.current_from_date = lft_node.period_from_date
|
||||||
self.to_date = lft_node.period_to_date
|
self.current_to_date = lft_node.period_to_date
|
||||||
|
self.get_report_summary()
|
||||||
self.save()
|
self.save()
|
||||||
else:
|
else:
|
||||||
frappe.msgprint("No more children on Left")
|
frappe.msgprint("No more children on Left")
|
||||||
@@ -136,8 +151,9 @@ class BisectAccountingStatements(Document):
|
|||||||
if cur_node.right_child is not None:
|
if cur_node.right_child is not None:
|
||||||
rgt_node = frappe.get_doc("Nodes", cur_node.right_child)
|
rgt_node = frappe.get_doc("Nodes", cur_node.right_child)
|
||||||
self.current_node = cur_node.right_child
|
self.current_node = cur_node.right_child
|
||||||
self.from_date = rgt_node.period_from_date
|
self.current_from_date = rgt_node.period_from_date
|
||||||
self.to_date = rgt_node.period_to_date
|
self.current_to_date = rgt_node.period_to_date
|
||||||
|
self.get_report_summary()
|
||||||
self.save()
|
self.save()
|
||||||
else:
|
else:
|
||||||
frappe.msgprint("No more children on Right")
|
frappe.msgprint("No more children on Right")
|
||||||
@@ -149,8 +165,9 @@ class BisectAccountingStatements(Document):
|
|||||||
if cur_node.root is not None:
|
if cur_node.root is not None:
|
||||||
root = frappe.get_doc("Nodes", cur_node.root)
|
root = frappe.get_doc("Nodes", cur_node.root)
|
||||||
self.current_node = cur_node.root
|
self.current_node = cur_node.root
|
||||||
self.from_date = root.period_from_date
|
self.current_from_date = root.period_from_date
|
||||||
self.to_date = root.period_to_date
|
self.current_to_date = root.period_to_date
|
||||||
|
self.get_report_summary()
|
||||||
self.save()
|
self.save()
|
||||||
else:
|
else:
|
||||||
frappe.msgprint("Reached Root")
|
frappe.msgprint("Reached Root")
|
||||||
|
|||||||
Reference in New Issue
Block a user