Skip to content

Commit

Permalink
fix: (bulk transaction) key error and better error logging (#32445)
Browse files Browse the repository at this point in the history
* fix: (bulk transaction) key error and better error logging

* chore: pre-commit

* chore: linter - missing comma

(cherry picked from commit 9105515)
  • Loading branch information
rtdany10 authored and mergify[bot] committed Oct 3, 2022
1 parent ba80ba0 commit 6acd49c
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions erpnext/utilities/bulk_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
def transaction_processing(data, from_doctype, to_doctype):
if isinstance(data, str):
deserialized_data = json.loads(data)

else:
deserialized_data = data

Expand All @@ -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):
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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":
Expand Down

0 comments on commit 6acd49c

Please sign in to comment.