Frappe.exceptions.ValidationError: Debit and Credit not equal for Journal Entry after Latest Bench Update

I get the following error on bench update:

Executing erpnext.patches.v6_4.fix_journal_entries_due_to_reconciliation
.....

frappe.exceptions.ValidationError: Debit and Credit not equal for Journal Entry #JV-00058. Difference is 686.0.

I checked tabJournal Entry and the Journal Entry balances, there isn’t a difference, even the tabGL Entry also records the debit and credit transaction and balances.

Can you please provide the document object for that Journal Entry? To do that run this command:

bench --site {sitename} console
import frappe
print frappe.get_doc("Journal Entry" , "{journal_entry_id}").as_dict()

{u’write_off_amount’: None, u’naming_series’: u’JV-’, u’creation’: datetime.datetime(2015, 9, 30, 18, 34, 1, 547290), u’voucher_type’: u’Bank Entry’, u’modified’: datetime.datetime(2015, 9, 30, 18, 36, 28, 63227), u’owner’: u’bohlian@gmail.com’, u’letter_head’: u’Company XYZ’, u’accounts’: [{u’account_type’: u’Payable’, u’parent’: u’JV-00058’, u’reference_name’: u’PINV-00049-1’, u’creation’: datetime.datetime(2015, 9, 30, 18, 34, 1, 547290), u’debit_in_account_currency’: 885.0, u’party_balance’: 0.0, u’exchange_rate’: 1.0, u’is_advance’: u’Yes’, u’docstatus’: 1L, u’owner’: u’bohlian@gmail.com’, u’account_currency’: u’MYR’, u’cost_center’: u’Main - SCSB’, u’account’: u’Creditors - SCSB’, u’modified_by’: u’bohlian@gmail.com’, u’name’: u’51cbd1b71d’, u’idx’: 1L, u’party_type’: u’Supplier’, u’reference_type’: u’Purchase Invoice’, u’doctype’: u’Journal Entry Account’, u’modified’: datetime.datetime(2015, 9, 30, 18, 36, 28, 63227), u’credit’: 0.0, u’parenttype’: u’Journal Entry’, u’debit’: 885.0, u’party’: u’TEXAS FRIED CHICKEN’, u’balance’: -129063.83, u’credit_in_account_currency’: None, u’against_account’: u’Maybank 123456789000 - SCSB’, u’parentfield’: u’accounts’}, {u’account_type’: u’Bank’, u’parent’: u’JV-00058’, u’reference_name’: None, u’creation’: datetime.datetime(2015, 9, 30, 18, 34, 1, 547290), u’debit_in_account_currency’: None, u’party_balance’: None, u’exchange_rate’: 1.0, u’is_advance’: u’No’, u’docstatus’: 1L, u’owner’: u’bohlian@gmail.com’, u’account_currency’: u’MYR’, u’cost_center’: u’Main - SCSB’, u’account’: u’Maybank 123456789000 - SCSB’, u’modified_by’: u’bohlian@gmail.com’, u’name’: u’d027818928’, u’idx’: 2L, u’party_type’: None, u’reference_type’: None, u’doctype’: u’Journal Entry Account’, u’modified’: datetime.datetime(2015, 9, 30, 18, 36, 28, 63227), u’credit’: 885.0, u’parenttype’: u’Journal Entry’, u’debit’: 0.0, u’party’: None, u’balance’: 80088.57, u’credit_in_account_currency’: 885.0, u’against_account’: u’TEXAS FRIED CHICKEN’, u’parentfield’: u’accounts’}, {u’account_type’: u’Payable’, u’parent’: u’JV-00058’, u’reference_name’: u’PO-00051’, u’creation’: datetime.datetime(2015, 9, 30, 18, 34, 1, 547290), u’debit_in_account_currency’: 686.0, u’party_balance’: None, u’exchange_rate’: 1.0, u’is_advance’: u’Yes’, u’docstatus’: 1L, u’owner’: u’bohlian@gmail.com’, u’account_currency’: None, u’cost_center’: u’Main - SCSB’, u’account’: u’Creditors - SCSB’, u’modified_by’: u’bohlian@gmail.com’, u’name’: u’b71995dd3f’, u’idx’: 3L, u’party_type’: u’Supplier’, u’reference_type’: u’Purchase Order’, u’doctype’: u’Journal Entry Account’, u’modified’: datetime.datetime(2015, 9, 30, 18, 36, 28, 63227), u’credit’: None, u’parenttype’: u’Journal Entry’, u’debit’: 0.0, u’party’: u’TEXAS FRIED CHICKEN’, u’balance’: -129063.83, u’credit_in_account_currency’: None, u’against_account’: u’Maybank 123456789000 - SCSB’, u’parentfield’: u’accounts’}], u’cheque_no’: u’-’, u’bill_no’: None, u’user_remark’: None, u’modified_by’: u’bohlian@gmail.com’, u’title’: u’TEXAS FRIED CHICKEN’, u’amended_from’: None, u’docstatus’: 1L, u’total_amount_in_words’: u’MYR Eight Hundred And Eighty Five only.’, u’bill_date’: None, u’due_date’: None, u’clearance_date’: None, u’parent’: None, u’multi_currency’: 0, u’company’: u’Company XYZ’, u’fiscal_year’: u’2015’, u’total_credit’: 885.0, u’difference’: 0.0, u’pay_to_recd_from’: u’TEXAS FRIED CHICKEN’, u’name’: u’JV-00058’, u’remark’: u’Reference #- dated 30-09-2015\n0.00 against Purchase Order PO-00051’, u’total_amount’: 885.0, u’idx’: None, u’cheque_date’: datetime.date(2015, 9, 30), u’doctype’: u’Journal Entry’, u’write_off_based_on’: u’Accounts Receivable’, u’payee’: None, u’parenttype’: None, u’select_print_heading’: None, u’stock_entry’: None, u’total_debit’: 885.0, u’is_opening’: u’No’, u’posting_date’: datetime.date(2015, 9, 30), u’parentfield’: None}

HI @nabinhait, any updates on this?

If not, is there a way to rollback changes temporarily?

@bohlian As per the data, the Journal Entry JV-00058 has the wrong entries. If you are still stuck, then remove the patch “fix_journal_entries_due_to_reconciliation” from patches.txt temporarily. Then go to your erpnext instance, and correct the Journal Entry. Then include the patch again and run bench migrate.

@nabinhait Thank you. You were right, there was an imbalance of the Journal Entry. Managed to overcome it by temporarily removing the patch and fixing the JE then allowing the patching to be done after.

We actually found a potential bug that allowed us to to unbalance a JE and will raise an issue once we have tested further.