diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 4e0079abf02..c769b54648e 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -663,6 +663,7 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False): d["allocated_amount"] = d["allocated_amount"] * -1 d["unadjusted_amount"] = d["unadjusted_amount"] * -1 + insert_position = -1 if flt(d["unadjusted_amount"]) - flt(d["allocated_amount"]) != 0: # adjust the unreconciled balance amount_in_account_currency = flt(d["unadjusted_amount"]) - flt(d["allocated_amount"]) @@ -674,9 +675,10 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False): ) else: journal_entry.remove(jv_detail) + insert_position += jv_detail.idx # new row with references - new_row = journal_entry.append("accounts") + new_row = journal_entry.append("accounts", position=insert_position) # Copy field values into new row [