fix: rollback document if reconciliation fails in Documents & Reconcile mode

Previously a JE/PE was left in the database even when reconcile_vouchers threw
an error.  Now the whole transaction (document creation + failed reconciliation)
is rolled back so no orphaned document is created.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ali 2026-03-16 18:31:58 +04:00
parent 87d4578927
commit 97b57c8572
1 changed files with 3 additions and 1 deletions

View File

@ -369,11 +369,13 @@ def _create_and_reconcile_doc(txn, paid_from, paid_to, document_type, multi_curr
)
return {"success": True, "doc_name": doc_name, "reconciled": True}
except Exception as re:
frappe.db.rollback()
frappe.local.message_log = []
frappe.log_error(
f"reconcile_vouchers failed for {doc_name}: {re}\n{frappe.get_traceback()}",
"Kapital Bank Mapping",
)
return {"success": True, "doc_name": doc_name, "reconciled": False, "error": str(re)}
return {"success": False, "error": str(re)}
except Exception as e:
frappe.db.rollback()