feat: order failed import log by creation, handle rollbacks and commits
This commit is contained in:
parent
0805307514
commit
1b5eea691c
@ -29,6 +29,11 @@ VOUCHER_CHUNK_SIZE = 500
|
|||||||
|
|
||||||
|
|
||||||
class TallyMigration(Document):
|
class TallyMigration(Document):
|
||||||
|
def validate(self):
|
||||||
|
failed_import_log = json.loads(self.failed_import_log)
|
||||||
|
sorted_failed_import_log = sorted(failed_import_log, key=lambda row: row["doc"]["creation"])
|
||||||
|
self.failed_import_log = json.dumps(sorted_failed_import_log)
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
if not self.name:
|
if not self.name:
|
||||||
self.name = "Tally Migration on " + format_datetime(self.creation)
|
self.name = "Tally Migration on " + format_datetime(self.creation)
|
||||||
@ -320,9 +325,11 @@ class TallyMigration(Document):
|
|||||||
|
|
||||||
self.set_account_defaults()
|
self.set_account_defaults()
|
||||||
self.is_master_data_imported = 1
|
self.is_master_data_imported = 1
|
||||||
|
frappe.db.commit()
|
||||||
|
|
||||||
except:
|
except:
|
||||||
self.publish("Import Master Data", _("Process Failed"), -1, 5)
|
self.publish("Import Master Data", _("Process Failed"), -1, 5)
|
||||||
|
frappe.db.rollback()
|
||||||
self.log()
|
self.log()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -343,7 +350,9 @@ class TallyMigration(Document):
|
|||||||
processed_voucher = function(voucher)
|
processed_voucher = function(voucher)
|
||||||
if processed_voucher:
|
if processed_voucher:
|
||||||
vouchers.append(processed_voucher)
|
vouchers.append(processed_voucher)
|
||||||
|
frappe.db.commit()
|
||||||
except:
|
except:
|
||||||
|
frappe.db.rollback()
|
||||||
self.log(voucher)
|
self.log(voucher)
|
||||||
return vouchers
|
return vouchers
|
||||||
|
|
||||||
@ -545,7 +554,9 @@ class TallyMigration(Document):
|
|||||||
voucher_doc.insert()
|
voucher_doc.insert()
|
||||||
voucher_doc.submit()
|
voucher_doc.submit()
|
||||||
self.publish("Importing Vouchers", _("{} of {}").format(index, total), index, total)
|
self.publish("Importing Vouchers", _("{} of {}").format(index, total), index, total)
|
||||||
|
frappe.db.commit()
|
||||||
except:
|
except:
|
||||||
|
frappe.db.rollback()
|
||||||
self.log(voucher_doc)
|
self.log(voucher_doc)
|
||||||
|
|
||||||
if is_last:
|
if is_last:
|
||||||
@ -576,14 +587,14 @@ class TallyMigration(Document):
|
|||||||
if sys.exc_info()[1].__class__ != frappe.DuplicateEntryError:
|
if sys.exc_info()[1].__class__ != frappe.DuplicateEntryError:
|
||||||
failed_import_log = json.loads(self.failed_import_log)
|
failed_import_log = json.loads(self.failed_import_log)
|
||||||
doc = data.as_dict()
|
doc = data.as_dict()
|
||||||
doc_fields = { x.fieldname for x in frappe.get_doc("DocType", doc.doctype).fields }
|
|
||||||
stripped_doc = { k: v for k, v in doc.items() if k in doc_fields }
|
|
||||||
failed_import_log.append({
|
failed_import_log.append({
|
||||||
"doc": stripped_doc,
|
"doc": doc,
|
||||||
"exc": traceback.format_exc()
|
"exc": traceback.format_exc()
|
||||||
})
|
})
|
||||||
self.failed_import_log = json.dumps(failed_import_log, separators=(',', ':'))
|
self.failed_import_log = json.dumps(failed_import_log, separators=(',', ':'))
|
||||||
self.save()
|
self.save()
|
||||||
|
frappe.db.commit()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
data = data or self.status
|
data = data or self.status
|
||||||
message = "\n".join(["Data:", json.dumps(data, default=str, indent=4), "--" * 50, "\nException:", traceback.format_exc()])
|
message = "\n".join(["Data:", json.dumps(data, default=str, indent=4), "--" * 50, "\nException:", traceback.format_exc()])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user