From 705ef4f5a31aac60ac879adecbede33ffd573588 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 25 Sep 2023 21:16:18 +0530 Subject: [PATCH] refactor: add basic navigation 1. remove unnecessary columns 2. added basic tree navigation --- .../bisect_accounting_statements.js | 27 ++++++++++++ .../bisect_accounting_statements.json | 24 +---------- .../bisect_accounting_statements.py | 42 ++++++++++++++++--- 3 files changed, 65 insertions(+), 28 deletions(-) diff --git a/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.js b/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.js index 732b2b0f9c..4e478ee4ab 100644 --- a/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.js +++ b/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.js @@ -19,6 +19,33 @@ frappe.ui.form.on("Bisect Accounting Statements", { ); // frm.change_custom_button_type(__('Bisect'), null, 'primary'); }, + bisect_left(frm) { + frm.call({ + doc: frm.doc, + method: 'bisect_left', + callback: (r) => { + console.log(r); + } + }); + }, + bisect_right(frm) { + frm.call({ + doc: frm.doc, + method: 'bisect_right', + callback: (r) => { + console.log(r); + } + }); + }, + move_up(frm) { + frm.call({ + doc: frm.doc, + method: 'move_up', + callback: (r) => { + console.log(r); + } + }); + }, build_tree(frm) { frm.call({ doc: frm.doc, diff --git a/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.json b/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.json index e0b84adeeb..c5715fe2ea 100644 --- a/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.json +++ b/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.json @@ -12,10 +12,6 @@ "to_date", "column_break_iwny", "algorithm", - "section_break_lwr2", - "current_from_date", - "column_break_uuic", - "current_to_date", "section_break_zbty", "current_node", "tree" @@ -59,31 +55,13 @@ "fieldname": "current_node", "fieldtype": "JSON", "label": "Current Node" - }, - { - "fieldname": "section_break_lwr2", - "fieldtype": "Section Break" - }, - { - "fieldname": "current_from_date", - "fieldtype": "Date", - "label": "Current From Date" - }, - { - "fieldname": "current_to_date", - "fieldtype": "Date", - "label": "Current To Date" - }, - { - "fieldname": "column_break_uuic", - "fieldtype": "Column Break" } ], "hide_toolbar": 1, "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2023-09-25 17:05:13.384320", + "modified": "2023-09-25 21:15:47.905386", "modified_by": "Administrator", "module": "Accounts", "name": "Bisect Accounting Statements", diff --git a/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.py b/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.py index 7c68f18775..accc8a9b42 100644 --- a/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.py +++ b/erpnext/accounts/doctype/bisect_accounting_statements/bisect_accounting_statements.py @@ -124,8 +124,12 @@ class BTree(object): tree = json.loads(tree) for x in tree: x = frappe._dict(x) - n = Node(x.parent, x.period, x.left_child, x.right_child) - n.period = x.period + n = Node(x.parent, None, x.left_child, x.right_child) + date_format = guess_date_format(x.period[0]) + n.period = ( + datetime.datetime.strptime(x.period[0], date_format), + datetime.datetime.strptime(x.period[1], date_format), + ) n.difference = x.difference x.profit_and_loss_summary = x.profit_and_loss_summary x.balance_sheet_summary = x.balance_sheet_summary @@ -187,9 +191,37 @@ class BisectAccountingStatements(Document): for x in self.tree_instance.btree: print(x) - print("Root", self.tree_instnace.current_node) + print("Root", self.tree_instance.current_node) self.tree = json.dumps(self.tree_instance.as_list()) - self.current_node = json.dumps(self.tree_intance.btree[0].as_dict()) + self.current_node = json.dumps(self.tree_instance.btree[0].as_dict()) - print(guess_date_format(json.loads(self.current_node)["period"][0])) + @frappe.whitelist() + def bisect_left(self): + if self.tree_instance.current_node is not None: + if self.tree_instance.current_node.left_child is not None: + self.current_node = self.tree_instance.btree[self.tree_instance.current_node.left_child] + self.current_node = json.dumps(self.current_node.as_dict()) + self.save() + else: + frappe.msgprint("No more children on Left") + + @frappe.whitelist() + def bisect_right(self): + if self.tree_instance.current_node is not None: + if self.tree_instance.current_node.right_child is not None: + self.current_node = self.tree_instance.btree[self.tree_instance.current_node.right_child] + self.current_node = json.dumps(self.current_node.as_dict()) + self.save() + else: + frappe.msgprint("No more children on Right") + + @frappe.whitelist() + def move_up(self): + if self.tree_instance.current_node is not None: + if self.tree_instance.current_node.parent is not None: + self.current_node = self.tree_instance.btree[self.tree_instance.current_node.parent] + self.current_node = json.dumps(self.current_node.as_dict()) + self.save() + else: + frappe.msgprint("Reached Root")