refactor: calculate summary on tree navigation

This commit is contained in:
ruthra kumar 2023-09-26 20:33:13 +05:30
parent 99fbd8ad18
commit f7b7b2b438
3 changed files with 99 additions and 10 deletions

View File

@ -17,7 +17,6 @@ frappe.ui.form.on("Bisect Accounting Statements", {
frm.add_custom_button(__('Build Tree'), () =>
frm.trigger("build_tree")
);
// frm.change_custom_button_type(__('Bisect'), null, 'primary');
},
bisect_left(frm) {
frm.call({
@ -54,5 +53,5 @@ frappe.ui.form.on("Bisect Accounting Statements", {
console.log(r);
}
});
}
},
});

View File

@ -7,13 +7,26 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"company",
"column_break_hcam",
"from_date",
"column_break_qxbi",
"to_date",
"column_break_iwny",
"algorithm",
"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": [
{
@ -50,13 +63,73 @@
"fieldtype": "Link",
"label": "Current Node",
"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,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-09-26 12:09:23.649156",
"modified": "2023-09-26 21:07:14.290963",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Bisect Accounting Statements",

View File

@ -116,6 +116,20 @@ class BisectAccountingStatements(Document):
root = frappe.db.get_all("Nodes", filters={"root": ["is", "not set"]})[0]
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()
def bisect_left(self):
if self.current_node is not None:
@ -123,8 +137,9 @@ class BisectAccountingStatements(Document):
if cur_node.left_child is not None:
lft_node = frappe.get_doc("Nodes", cur_node.left_child)
self.current_node = cur_node.left_child
self.from_date = lft_node.period_from_date
self.to_date = lft_node.period_to_date
self.current_from_date = lft_node.period_from_date
self.current_to_date = lft_node.period_to_date
self.get_report_summary()
self.save()
else:
frappe.msgprint("No more children on Left")
@ -136,8 +151,9 @@ class BisectAccountingStatements(Document):
if cur_node.right_child is not None:
rgt_node = frappe.get_doc("Nodes", cur_node.right_child)
self.current_node = cur_node.right_child
self.from_date = rgt_node.period_from_date
self.to_date = rgt_node.period_to_date
self.current_from_date = rgt_node.period_from_date
self.current_to_date = rgt_node.period_to_date
self.get_report_summary()
self.save()
else:
frappe.msgprint("No more children on Right")
@ -149,8 +165,9 @@ class BisectAccountingStatements(Document):
if cur_node.root is not None:
root = frappe.get_doc("Nodes", cur_node.root)
self.current_node = cur_node.root
self.from_date = root.period_from_date
self.to_date = root.period_to_date
self.current_from_date = root.period_from_date
self.current_to_date = root.period_to_date
self.get_report_summary()
self.save()
else:
frappe.msgprint("Reached Root")