chore: Clear Progress section for completed logs & on_submit UX

- Delete `BOM Update Batch` table on 'Completed' log, to save space
- Hide Progress section on 'Completed' log
- Enqueue `on_submit` for 'Update Cost' job, getting leaf boms could take time for huge DBs. Users have to wait for screen to unfreeze.
- Add error handling to `process_boms_cost_level_wise` (Called via cron job and on submit, both in background)
This commit is contained in:
marination 2022-06-20 16:25:34 +05:30
parent 10583eb3ce
commit 0320b59ea6
2 changed files with 42 additions and 27 deletions

View File

@ -7,11 +7,11 @@
"editable_grid": 1, "editable_grid": 1,
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"current_bom",
"new_bom",
"column_break_3",
"update_type", "update_type",
"status", "status",
"column_break_3",
"current_bom",
"new_bom",
"error_log", "error_log",
"progress_section", "progress_section",
"current_level", "current_level",
@ -37,6 +37,7 @@
"options": "BOM" "options": "BOM"
}, },
{ {
"depends_on": "eval:doc.update_type === \"Replace BOM\"",
"fieldname": "column_break_3", "fieldname": "column_break_3",
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
@ -87,6 +88,7 @@
"options": "BOM Update Batch" "options": "BOM Update Batch"
}, },
{ {
"depends_on": "eval:doc.status !== \"Completed\"",
"fieldname": "current_level", "fieldname": "current_level",
"fieldtype": "Int", "fieldtype": "Int",
"label": "Current Level" "label": "Current Level"
@ -96,7 +98,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2022-06-06 15:15:23.883251", "modified": "2022-06-20 15:43:55.696388",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Manufacturing", "module": "Manufacturing",
"name": "BOM Update Log", "name": "BOM Update Log",

View File

@ -77,7 +77,11 @@ class BOMUpdateLog(Document):
now=frappe.flags.in_test, now=frappe.flags.in_test,
) )
else: else:
process_boms_cost_level_wise(self) frappe.enqueue(
method="erpnext.manufacturing.doctype.bom_update_log.bom_update_log.process_boms_cost_level_wise",
update_doc=self,
now=frappe.flags.in_test,
)
def run_replace_bom_job( def run_replace_bom_job(
@ -112,6 +116,7 @@ def process_boms_cost_level_wise(
current_boms = {} current_boms = {}
values = {} values = {}
try:
if update_doc.status == "Queued": if update_doc.status == "Queued":
# First level yet to process. On Submit. # First level yet to process. On Submit.
current_level = 0 current_level = 0
@ -134,6 +139,8 @@ def process_boms_cost_level_wise(
set_values_in_log(update_doc.name, values, commit=True) set_values_in_log(update_doc.name, values, commit=True)
queue_bom_cost_jobs(current_boms, update_doc, current_level) queue_bom_cost_jobs(current_boms, update_doc, current_level)
except Exception:
handle_exception(update_doc)
def queue_bom_cost_jobs( def queue_bom_cost_jobs(
@ -199,16 +206,22 @@ def resume_bom_cost_update_jobs():
current_boms, processed_boms = get_processed_current_boms(log, bom_batches) current_boms, processed_boms = get_processed_current_boms(log, bom_batches)
parent_boms = get_next_higher_level_boms(child_boms=current_boms, processed_boms=processed_boms) parent_boms = get_next_higher_level_boms(child_boms=current_boms, processed_boms=processed_boms)
# Unset processed BOMs if log is complete, it is used for next level BOMs # Unset processed BOMs (it is used for next level BOMs) & change status if log is complete
status = "Completed" if not parent_boms else "In Progress"
processed_boms = json.dumps([] if not parent_boms else processed_boms)
set_values_in_log( set_values_in_log(
log.name, log.name,
values={ values={
"processed_boms": json.dumps([] if not parent_boms else processed_boms), "processed_boms": processed_boms,
"status": "Completed" if not parent_boms else "In Progress", "status": status,
}, },
commit=True, commit=True,
) )
# clear progress section
if status == "Completed":
frappe.db.delete("BOM Update Batch", {"parent": log.name})
if parent_boms: # there is a next level to process if parent_boms: # there is a next level to process
process_boms_cost_level_wise( process_boms_cost_level_wise(
update_doc=frappe.get_doc("BOM Update Log", log.name), parent_boms=parent_boms update_doc=frappe.get_doc("BOM Update Log", log.name), parent_boms=parent_boms