refactor: barebones functions

This commit is contained in:
ruthra kumar
2025-10-08 11:02:52 +05:30
parent f44c908a8d
commit 1c92b01542
4 changed files with 71 additions and 11 deletions

View File

@@ -1,8 +1,24 @@
// Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
// frappe.ui.form.on("Process Period Closing Voucher", {
// refresh(frm) {
frappe.ui.form.on("Process Period Closing Voucher", {
refresh(frm) {
if (frm.doc.docstatus == 1 && ["Queued"].find((x) => x == frm.doc.status)) {
let execute_btn = __("Start");
// },
// });
frm.add_custom_button(execute_btn, () => {
frm.call({
method: "erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.start_pcv_processing",
args: {
docname: frm.doc.name,
},
}).then((r) => {
if (!r.exc) {
frappe.show_alert(__("Job Started"));
frm.reload_doc();
}
});
});
}
},
});

View File

@@ -7,14 +7,17 @@
"field_order": [
"parent_pcv",
"status",
"dates_to_process"
"dates_to_process",
"amended_from"
],
"fields": [
{
"fieldname": "parent_pcv",
"fieldtype": "Link",
"in_list_view": 1,
"label": "PCV",
"options": "Period Closing Voucher"
"options": "Period Closing Voucher",
"reqd": 1
},
{
"default": "Queued",
@@ -28,12 +31,23 @@
"fieldtype": "Table",
"label": "Dates to Process",
"options": "Process Period Closing Voucher Detail"
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Process Period Closing Voucher",
"print_hide": 1,
"read_only": 1,
"search_index": 1
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2025-10-03 14:29:55.584225",
"modified": "2025-10-08 10:33:43.742974",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Process Period Closing Voucher",

View File

@@ -1,8 +1,11 @@
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
# import frappe
from datetime import timedelta
import frappe
from frappe.model.document import Document
from frappe.utils import add_days, get_datetime
class ProcessPeriodClosingVoucher(Document):
@@ -18,9 +21,33 @@ class ProcessPeriodClosingVoucher(Document):
ProcessPeriodClosingVoucherDetail,
)
amended_from: DF.Link | None
dates_to_process: DF.Table[ProcessPeriodClosingVoucherDetail]
parent_pcv: DF.Link | None
parent_pcv: DF.Link
status: DF.Literal["Queued", "Running", "Completed"]
# end: auto-generated types
pass
def validate(self):
self.status = "Queued"
self.populate_processing_table()
def populate_processing_table(self):
self.dates_to_process = []
pcv = frappe.get_doc("Period Closing Voucher", self.parent_pcv)
start = get_datetime(pcv.period_start_date)
end = get_datetime(pcv.period_end_date)
dates = [start + timedelta(days=x) for x in range((end - start).days + 1)]
for x in dates:
self.append("dates_to_process", {"processing_date": x, "status": "Queued"})
@frappe.whitelist()
def start_pcv_processing(docname: str):
if frappe.db.get_value("Process Period Closing Voucher", docname, "status") == "Queued":
dates_to_process = frappe.db.get_all(
"Process Period Closing Voucher Detail",
filters={"parent": docname, "status": "Queued"},
fields=["processing_date"],
order_by="processing_date",
limit=4,
)

View File

@@ -13,18 +13,21 @@
{
"fieldname": "processing_date",
"fieldtype": "Date",
"in_list_view": 1,
"label": "Processing Date"
},
{
"default": "Queued",
"fieldname": "status",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Status",
"options": "Queued\nRunning\nCompleted"
},
{
"fieldname": "closing_balance",
"fieldtype": "JSON",
"in_list_view": 1,
"label": "Closing Balance"
}
],
@@ -32,7 +35,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2025-10-08 10:19:29.928526",
"modified": "2025-10-08 10:47:50.050341",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Process Period Closing Voucher Detail",