Skip to content

Commit

Permalink
refactor: added cancelled status to the log doctype
Browse files Browse the repository at this point in the history
1. Moved the status section to the bottom in parent doc
2. Using alerts to indicate Job trigger status
  • Loading branch information
ruthra-kumar committed Apr 21, 2023
1 parent b46aa3e commit f99d479
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ frappe.ui.form.on("Process Payment Reconciliation", {
}
}).then(r => {
if(!r.exc) {
frappe.show_alert(__("Job Started"));
frm.reload_doc();
}
});
Expand All @@ -70,7 +71,7 @@ frappe.ui.form.on("Process Payment Reconciliation", {
if (r.message.processed) {
progress = (r.message.processed/r.message.total) * 100;
description = r.message.processed + "/" + r.message.total + " processed";
} else if (r.message.total == 0) {
} else if (r.message.total == 0 && frm.doc.status == "Completed") {
progress = 100;
}

Expand All @@ -90,6 +91,7 @@ frappe.ui.form.on("Process Payment Reconciliation", {
}
}).then(r => {
if (!r.exc) {
frappe.show_alert(__("Job Paused"));
frm.reload_doc()
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"status",
"section_break_gasn",
"company",
"party_type",
"column_break_io6c",
Expand All @@ -25,7 +23,9 @@
"cost_center",
"bank_cash_account",
"section_break_2n02",
"status",
"error_log",
"section_break_a8yx",
"amended_from"
],
"fields": [
Expand All @@ -37,10 +37,6 @@
"options": "\nQueued\nRunning\nPaused\nCompleted\nPartially Reconciled\nFailed\nCancelled",
"read_only": 1
},
{
"fieldname": "section_break_gasn",
"fieldtype": "Section Break"
},
{
"fieldname": "company",
"fieldtype": "Link",
Expand Down Expand Up @@ -124,7 +120,8 @@
},
{
"fieldname": "section_break_2n02",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Status"
},
{
"depends_on": "eval:doc.error_log",
Expand All @@ -140,12 +137,16 @@
"options": "Process Payment Reconciliation",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "section_break_a8yx",
"fieldtype": "Section Break"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-04-21 13:41:35.834457",
"modified": "2023-04-21 17:19:30.912953",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Process Payment Reconciliation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def on_submit(self):

def on_cancel(self):
self.db_set("status", "Cancelled")
log = frappe.db.get_value(
"Process Payment Reconciliation Log", filters={"process_pr": self.name}
)
if log:
frappe.db.set_value("Process Payment Reconciliation Log", log, "status", "Cancelled")


@frappe.whitelist()
Expand Down Expand Up @@ -132,7 +137,7 @@ def trigger_job_for_doc(docname: str | None = None):
enqueue_after_commit=True,
doc=docname,
)
frappe.msgprint(_("Job triggered"))

elif frappe.db.get_value("Process Payment Reconciliation", docname, "status") == "Paused":
frappe.db.set_value("Process Payment Reconciliation", docname, "status", "Running")
log = frappe.db.get_value("Process Payment Reconciliation Log", filters={"process_pr": docname})
Expand All @@ -149,7 +154,6 @@ def trigger_job_for_doc(docname: str | None = None):
job_name=job_name,
doc=docname,
)
frappe.msgprint(_("Job triggered"))
else:
frappe.msgprint(_("Scheduler is Inactive. Can't trigger job now."))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

frappe.ui.form.on("Process Payment Reconciliation Log", {
refresh(frm) {
let progress = 0;
if (frm.doc.reconciled_entries != 0) {
progress = frm.doc.reconciled_entries / frm.doc.total_allocations * 100;
} else if(frm.doc.total_allocations == 0){
progress = 100;
if (['Completed', 'Running', 'Paused', 'Partially Reconciled'].find(x => x == frm.doc.status)) {
let progress = 0;
if (frm.doc.reconciled_entries != 0) {
progress = frm.doc.reconciled_entries / frm.doc.total_allocations * 100;
} else if(frm.doc.total_allocations == 0 && frm.doc.status == "Completed"){
progress = 100;
}
frm.dashboard.add_progress(__('Reconciliation Progress'), progress);
}
frm.dashboard.add_progress(__('Reconciliation Progress'), progress);

},
});
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "Running\nReconciled\nPartially Reconciled\nFailed",
"options": "Running\nPaused\nReconciled\nPartially Reconciled\nFailed\nCancelled",
"read_only": 1
}
],
"in_create": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-04-18 19:47:33.076023",
"modified": "2023-04-21 17:36:26.642617",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Process Payment Reconciliation Log",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ frappe.listview_settings['Process Payment Reconciliation Log'] = {
'Paused': 'orange',
'Reconciled': 'green',
'Failed': 'red',
'Cancelled': 'red',
'Running': 'blue',
};
let status = doc.status;
Expand Down

0 comments on commit f99d479

Please sign in to comment.