refactor: some logic

This commit is contained in:
ruthra kumar 2023-09-18 12:35:24 +05:30
parent decdbd2782
commit 4c8a8c3bcd
3 changed files with 67 additions and 20 deletions

View File

@ -1,8 +1,20 @@
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
// frappe.ui.form.on("Bisect Accounting Statements", {
// refresh(frm) {
// },
// });
frappe.ui.form.on("Bisect Accounting Statements", {
refresh(frm) {
frm.add_custom_button(__('Bisect'), () =>
frm.trigger("bisect")
);
frm.change_custom_button_type(__('Bisect'), null, 'primary');
},
bisect(frm) {
frm.call({
doc: frm.doc,
method: 'bisect',
callback: (r) => {
console.log(r);
}
});
}
});

View File

@ -7,31 +7,53 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"from",
"from_date",
"column_break_qxbi",
"to"
"to_date",
"section_break_3x70",
"period_from",
"column_break_5ett",
"period_to"
],
"fields": [
{
"fieldname": "from",
"fieldtype": "Date",
"label": "From"
},
{
"fieldname": "to",
"fieldtype": "Date",
"label": "To"
},
{
"fieldname": "column_break_qxbi",
"fieldtype": "Column Break"
},
{
"fieldname": "from_date",
"fieldtype": "Date",
"label": "From Date"
},
{
"fieldname": "to_date",
"fieldtype": "Date",
"label": "To Date"
},
{
"fieldname": "section_break_3x70",
"fieldtype": "Section Break"
},
{
"fieldname": "period_from",
"fieldtype": "Date",
"label": "Period From"
},
{
"fieldname": "column_break_5ett",
"fieldtype": "Column Break"
},
{
"fieldname": "period_to",
"fieldtype": "Date",
"label": "Period To"
}
],
"hide_toolbar": 1,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-09-15 21:36:21.516679",
"modified": "2023-09-16 08:02:33.472406",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Bisect Accounting Statements",

View File

@ -1,9 +1,22 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
# import frappe
from math import ceil, floor
import frappe
from dateutil.relativedelta import relativedelta
from frappe.model.document import Document
from frappe.utils import getdate
class BisectAccountingStatements(Document):
pass
@frappe.whitelist()
def bisect(self):
cur_frm_date, cur_to_date = getdate(self.from_date), getdate(self.to_date)
while True:
delta = cur_to_date - cur_frm_date
if delta.days == 0:
return
cur_floor = floor(delta.days / 2)
cur_to_date = cur_frm_date + relativedelta(days=+cur_floor)
print((cur_frm_date, cur_to_date), delta, cur_floor)