mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-28 01:14:46 +00:00
refactor: barebones functions
This commit is contained in:
@@ -1,8 +1,24 @@
|
|||||||
// Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
// frappe.ui.form.on("Process Period Closing Voucher", {
|
frappe.ui.form.on("Process Period Closing Voucher", {
|
||||||
// refresh(frm) {
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
@@ -7,14 +7,17 @@
|
|||||||
"field_order": [
|
"field_order": [
|
||||||
"parent_pcv",
|
"parent_pcv",
|
||||||
"status",
|
"status",
|
||||||
"dates_to_process"
|
"dates_to_process",
|
||||||
|
"amended_from"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldname": "parent_pcv",
|
"fieldname": "parent_pcv",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "PCV",
|
"label": "PCV",
|
||||||
"options": "Period Closing Voucher"
|
"options": "Period Closing Voucher",
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "Queued",
|
"default": "Queued",
|
||||||
@@ -28,12 +31,23 @@
|
|||||||
"fieldtype": "Table",
|
"fieldtype": "Table",
|
||||||
"label": "Dates to Process",
|
"label": "Dates to Process",
|
||||||
"options": "Process Period Closing Voucher Detail"
|
"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,
|
"grid_page_length": 50,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2025-10-03 14:29:55.584225",
|
"modified": "2025-10-08 10:33:43.742974",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Process Period Closing Voucher",
|
"name": "Process Period Closing Voucher",
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
# import frappe
|
from datetime import timedelta
|
||||||
|
|
||||||
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.utils import add_days, get_datetime
|
||||||
|
|
||||||
|
|
||||||
class ProcessPeriodClosingVoucher(Document):
|
class ProcessPeriodClosingVoucher(Document):
|
||||||
@@ -18,9 +21,33 @@ class ProcessPeriodClosingVoucher(Document):
|
|||||||
ProcessPeriodClosingVoucherDetail,
|
ProcessPeriodClosingVoucherDetail,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
amended_from: DF.Link | None
|
||||||
dates_to_process: DF.Table[ProcessPeriodClosingVoucherDetail]
|
dates_to_process: DF.Table[ProcessPeriodClosingVoucherDetail]
|
||||||
parent_pcv: DF.Link | None
|
parent_pcv: DF.Link
|
||||||
status: DF.Literal["Queued", "Running", "Completed"]
|
status: DF.Literal["Queued", "Running", "Completed"]
|
||||||
# end: auto-generated types
|
# 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,
|
||||||
|
)
|
||||||
|
|||||||
@@ -13,18 +13,21 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "processing_date",
|
"fieldname": "processing_date",
|
||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Processing Date"
|
"label": "Processing Date"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "Queued",
|
"default": "Queued",
|
||||||
"fieldname": "status",
|
"fieldname": "status",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Status",
|
"label": "Status",
|
||||||
"options": "Queued\nRunning\nCompleted"
|
"options": "Queued\nRunning\nCompleted"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "closing_balance",
|
"fieldname": "closing_balance",
|
||||||
"fieldtype": "JSON",
|
"fieldtype": "JSON",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Closing Balance"
|
"label": "Closing Balance"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -32,7 +35,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2025-10-08 10:19:29.928526",
|
"modified": "2025-10-08 10:47:50.050341",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Process Period Closing Voucher Detail",
|
"name": "Process Period Closing Voucher Detail",
|
||||||
|
|||||||
Reference in New Issue
Block a user