refactor: add basic navigation
1. remove unnecessary columns 2. added basic tree navigation
This commit is contained in:
parent
b2dde55f2c
commit
705ef4f5a3
@ -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,
|
||||
|
@ -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",
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user