mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-18 09:05:00 +00:00
refactor: stable start, pause, resume and completion stages
(cherry picked from commit c839ebf593)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
frappe.ui.form.on("Process Period Closing Voucher", {
|
||||
refresh(frm) {
|
||||
if (frm.doc.docstatus == 1 && ["Queued"].find((x) => x == frm.doc.status)) {
|
||||
if (frm.doc.docstatus == 1 && ["Queued", "Paused"].find((x) => x == frm.doc.status)) {
|
||||
let execute_btn = __("Start");
|
||||
|
||||
frm.add_custom_button(execute_btn, () => {
|
||||
@@ -20,5 +20,23 @@ frappe.ui.form.on("Process Period Closing Voucher", {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (frm.doc.docstatus == 1 && ["Running"].find((x) => x == frm.doc.status)) {
|
||||
let execute_btn = __("Pause");
|
||||
|
||||
frm.add_custom_button(execute_btn, () => {
|
||||
frm.call({
|
||||
method: "erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.pause_pcv_processing",
|
||||
args: {
|
||||
docname: frm.doc.name,
|
||||
},
|
||||
}).then((r) => {
|
||||
if (!r.exc) {
|
||||
frappe.show_alert(__("Job Started"));
|
||||
frm.reload_doc();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ from datetime import timedelta
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import add_days, get_datetime
|
||||
from frappe.utils.scheduler import is_scheduler_inactive
|
||||
|
||||
|
||||
class ProcessPeriodClosingVoucher(Document):
|
||||
@@ -43,11 +44,54 @@ class ProcessPeriodClosingVoucher(Document):
|
||||
|
||||
@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(
|
||||
if frappe.db.get_value("Process Period Closing Voucher", docname, "status") in ["Queued", "Paused"]:
|
||||
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Running")
|
||||
if 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,
|
||||
):
|
||||
if not is_scheduler_inactive():
|
||||
for x in dates_to_process:
|
||||
frappe.enqueue(
|
||||
method="erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.process_individual_date",
|
||||
queue="long",
|
||||
is_async=True,
|
||||
enqueue_after_commit=True,
|
||||
docname=docname,
|
||||
date=x.processing_date,
|
||||
)
|
||||
else:
|
||||
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def pause_pcv_processing(docname: str):
|
||||
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Paused")
|
||||
|
||||
|
||||
def process_individual_date(docname: str, date: str):
|
||||
if frappe.db.get_value("Process Period Closing Voucher", docname, "status") == "Running":
|
||||
frappe.db.set_value(
|
||||
"Process Period Closing Voucher Detail", {"processing_date": date}, "status", "Completed"
|
||||
)
|
||||
if next_date_to_process := frappe.db.get_all(
|
||||
"Process Period Closing Voucher Detail",
|
||||
filters={"parent": docname, "status": "Queued"},
|
||||
fields=["processing_date"],
|
||||
order_by="processing_date",
|
||||
limit=1,
|
||||
):
|
||||
if not is_scheduler_inactive():
|
||||
frappe.enqueue(
|
||||
method="erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.process_individual_date",
|
||||
queue="long",
|
||||
is_async=True,
|
||||
enqueue_after_commit=True,
|
||||
docname=docname,
|
||||
date=next_date_to_process[0].processing_date,
|
||||
)
|
||||
else:
|
||||
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Status",
|
||||
"options": "Queued\nRunning\nCompleted"
|
||||
"options": "Queued\nRunning\nPaused\nCompleted"
|
||||
},
|
||||
{
|
||||
"fieldname": "closing_balance",
|
||||
@@ -35,7 +35,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-10-08 10:47:50.050341",
|
||||
"modified": "2025-10-09 16:46:37.778199",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Process Period Closing Voucher Detail",
|
||||
|
||||
@@ -19,7 +19,7 @@ class ProcessPeriodClosingVoucherDetail(Document):
|
||||
parentfield: DF.Data
|
||||
parenttype: DF.Data
|
||||
processing_date: DF.Date | None
|
||||
status: DF.Literal["Queued", "Running", "Completed"]
|
||||
status: DF.Literal["Queued", "Running", "Paused", "Completed"]
|
||||
# end: auto-generated types
|
||||
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user