From 91055151ce053bcba6009867f3d751c0714982c1 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Mon, 3 Oct 2022 10:59:53 +0530 Subject: [PATCH] fix: (bulk transaction) key error and better error logging (#32445) * fix: (bulk transaction) key error and better error logging * chore: pre-commit * chore: linter - missing comma --- erpnext/utilities/bulk_transaction.py | 36 +++++++++++---------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/erpnext/utilities/bulk_transaction.py b/erpnext/utilities/bulk_transaction.py index bfcba0766e..eed7c12763 100644 --- a/erpnext/utilities/bulk_transaction.py +++ b/erpnext/utilities/bulk_transaction.py @@ -9,7 +9,6 @@ from frappe import _ def transaction_processing(data, from_doctype, to_doctype): if isinstance(data, str): deserialized_data = json.loads(data) - else: deserialized_data = data @@ -30,30 +29,29 @@ def transaction_processing(data, from_doctype, to_doctype): def job(deserialized_data, from_doctype, to_doctype): - failed_history = [] - i = 0 + fail_count = 0 for d in deserialized_data: - failed = [] - try: - i += 1 doc_name = d.get("name") frappe.db.savepoint("before_creation_state") task(doc_name, from_doctype, to_doctype) - except Exception as e: frappe.db.rollback(save_point="before_creation_state") - failed_history.append(e) - failed.append(e) + fail_count += 1 update_logger( - doc_name, e, from_doctype, to_doctype, status="Failed", log_date=str(date.today()) + doc_name, + str(frappe.get_traceback()), + from_doctype, + to_doctype, + status="Failed", + log_date=str(date.today()), ) - if not failed: + else: update_logger( doc_name, None, from_doctype, to_doctype, status="Success", log_date=str(date.today()) ) - show_job_status(failed_history, deserialized_data, to_doctype) + show_job_status(fail_count, len(deserialized_data), to_doctype) def task(doc_name, from_doctype, to_doctype): @@ -94,7 +92,7 @@ def task(doc_name, from_doctype, to_doctype): "Purchase Invoice": purchase_order.make_purchase_invoice, "Purchase Receipt": purchase_order.make_purchase_receipt, }, - "Purhcase Invoice": { + "Purchase Invoice": { "Purchase Receipt": purchase_invoice.make_purchase_receipt, "Payment": payment_entry.get_payment_entry, }, @@ -150,15 +148,14 @@ def update_logger(doc_name, e, from_doctype, to_doctype, status, log_date=None, log_doc.save() -def show_job_status(failed_history, deserialized_data, to_doctype): - if not failed_history: +def show_job_status(fail_count, deserialized_data_count, to_doctype): + if not fail_count: frappe.msgprint( _("Creation of {0} successful").format(to_doctype), title="Successful", indicator="green", ) - - if len(failed_history) != 0 and len(failed_history) < len(deserialized_data): + elif fail_count != 0 and fail_count < deserialized_data_count: frappe.msgprint( _( """Creation of {0} partially successful. @@ -167,8 +164,7 @@ def show_job_status(failed_history, deserialized_data, to_doctype): title="Partially successful", indicator="orange", ) - - if len(failed_history) == len(deserialized_data): + else: frappe.msgprint( _( """Creation of {0} failed. @@ -180,9 +176,7 @@ def show_job_status(failed_history, deserialized_data, to_doctype): def record_exists(log_doc, doc_name, status): - record = mark_retrired_transaction(log_doc, doc_name) - if record and status == "Failed": return False elif record and status == "Success":