refactor: simplify logging logic bulk_transaction
diff --git a/erpnext/utilities/bulk_transaction.py b/erpnext/utilities/bulk_transaction.py
index fcee265..fd8e722 100644
--- a/erpnext/utilities/bulk_transaction.py
+++ b/erpnext/utilities/bulk_transaction.py
@@ -3,6 +3,7 @@
import frappe
from frappe import _
+from frappe.utils import today
@frappe.whitelist()
@@ -38,7 +39,7 @@
except Exception as e:
frappe.db.rollback(save_point="before_creation_state")
fail_count += 1
- update_logger(
+ create_log(
doc_name,
str(frappe.get_traceback()),
from_doctype,
@@ -47,7 +48,7 @@
log_date=str(date.today()),
)
else:
- update_logger(
+ create_log(
doc_name, None, from_doctype, to_doctype, status="Success", log_date=str(date.today())
)
@@ -108,45 +109,18 @@
obj.insert(ignore_mandatory=True)
-def check_logger_doc_exists(log_date):
- return frappe.db.exists("Bulk Transaction Log", log_date)
-
-
-def get_logger_doc(log_date):
- return frappe.get_doc("Bulk Transaction Log", log_date)
-
-
-def create_logger_doc():
- log_doc = frappe.new_doc("Bulk Transaction Log")
- log_doc.set_new_name(set_name=str(date.today()))
- log_doc.log_date = date.today()
-
- return log_doc
-
-
-def append_data_to_logger(log_doc, doc_name, error, from_doctype, to_doctype, status, restarted):
- row = log_doc.append("logger_data", {})
- row.transaction_name = doc_name
- row.date = date.today()
+def create_log(doc_name, e, from_doctype, to_doctype, status, log_date=None, restarted=0):
+ transaction_log = frappe.new_doc("Bulk Transaction Log Detail")
+ transaction_log.transaction_name = doc_name
+ transaction_log.date = today()
now = datetime.now()
- row.time = now.strftime("%H:%M:%S")
- row.transaction_status = status
- row.error_description = str(error)
- row.from_doctype = from_doctype
- row.to_doctype = to_doctype
- row.retried = restarted
-
-
-def update_logger(doc_name, e, from_doctype, to_doctype, status, log_date=None, restarted=0):
- if not check_logger_doc_exists(log_date):
- log_doc = create_logger_doc()
- append_data_to_logger(log_doc, doc_name, e, from_doctype, to_doctype, status, restarted)
- log_doc.insert()
- else:
- log_doc = get_logger_doc(log_date)
- if record_exists(log_doc, doc_name, status):
- append_data_to_logger(log_doc, doc_name, e, from_doctype, to_doctype, status, restarted)
- log_doc.save()
+ transaction_log.time = now.strftime("%H:%M:%S")
+ transaction_log.transaction_status = status
+ transaction_log.error_description = str(e)
+ transaction_log.from_doctype = from_doctype
+ transaction_log.to_doctype = to_doctype
+ transaction_log.retried = restarted
+ transaction_log.save()
def show_job_status(fail_count, deserialized_data_count, to_doctype):
@@ -176,23 +150,3 @@
title="Failed",
indicator="red",
)
-
-
-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":
- return True
- else:
- return True
-
-
-def mark_retrired_transaction(log_doc, doc_name):
- record = 0
- for d in log_doc.get("logger_data"):
- if d.transaction_name == doc_name and d.transaction_status == "Failed":
- frappe.db.set_value("Bulk Transaction Log Detail", d.name, "retried", 1)
- record = record + 1
-
- return record