refactor: some logic
This commit is contained in:
parent
decdbd2782
commit
4c8a8c3bcd
@ -1,8 +1,20 @@
|
|||||||
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
// frappe.ui.form.on("Bisect Accounting Statements", {
|
frappe.ui.form.on("Bisect Accounting Statements", {
|
||||||
// refresh(frm) {
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@ -7,31 +7,53 @@
|
|||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"from",
|
"from_date",
|
||||||
"column_break_qxbi",
|
"column_break_qxbi",
|
||||||
"to"
|
"to_date",
|
||||||
|
"section_break_3x70",
|
||||||
|
"period_from",
|
||||||
|
"column_break_5ett",
|
||||||
|
"period_to"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
|
||||||
"fieldname": "from",
|
|
||||||
"fieldtype": "Date",
|
|
||||||
"label": "From"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "to",
|
|
||||||
"fieldtype": "Date",
|
|
||||||
"label": "To"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "column_break_qxbi",
|
"fieldname": "column_break_qxbi",
|
||||||
"fieldtype": "Column Break"
|
"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,
|
"hide_toolbar": 1,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-09-15 21:36:21.516679",
|
"modified": "2023-09-16 08:02:33.472406",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Bisect Accounting Statements",
|
"name": "Bisect Accounting Statements",
|
||||||
|
|||||||
@ -1,9 +1,22 @@
|
|||||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# 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.model.document import Document
|
||||||
|
from frappe.utils import getdate
|
||||||
|
|
||||||
|
|
||||||
class BisectAccountingStatements(Document):
|
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user