Skip to content

Commit

Permalink
fix: not able to submit LCV entry (backport #42303) (#42304)
Browse files Browse the repository at this point in the history
fix: not able to submit LCV entry (#42303)

(cherry picked from commit 9cf92ea)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Jul 12, 2024
1 parent 4c9ce1b commit 6d098b7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
37 changes: 37 additions & 0 deletions erpnext/accounts/doctype/journal_entry/test_journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,43 @@ def check_gl_entries(self):
for field in self.fields:
self.assertEqual(self.expected_gle[i][field], gl_entries[i][field])

def test_negative_debit_and_credit_with_same_account_head(self):
from erpnext.accounts.general_ledger import process_gl_map

# Create JV with defaut cost center - _Test Cost Center
frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 0)

jv = make_journal_entry("_Test Bank - _TC", "_Test Bank - _TC", 100 * -1, save=True)
jv.append(
"accounts",
{
"account": "_Test Cash - _TC",
"debit": 100 * -1,
"credit": 100 * -1,
"debit_in_account_currency": 100 * -1,
"credit_in_account_currency": 100 * -1,
"exchange_rate": 1,
},
)
jv.flags.ignore_validate = True
jv.save()

self.assertEqual(len(jv.accounts), 3)

gl_map = jv.build_gl_map()

for row in gl_map:
if row.account == "_Test Cash - _TC":
self.assertEqual(row.debit_in_account_currency, 100 * -1)
self.assertEqual(row.credit_in_account_currency, 100 * -1)

gl_map = process_gl_map(gl_map, False)

for row in gl_map:
if row.account == "_Test Cash - _TC":
self.assertEqual(row.debit_in_account_currency, 100)
self.assertEqual(row.credit_in_account_currency, 100)


def make_journal_entry(
account1,
Expand Down
12 changes: 12 additions & 0 deletions erpnext/accounts/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ def check_if_in_list(gle, gl_map):
def toggle_debit_credit_if_negative(gl_map):
for entry in gl_map:
# toggle debit, credit if negative entry
if flt(entry.debit) < 0 and flt(entry.credit) < 0 and flt(entry.debit) == flt(entry.credit):
entry.credit *= -1
entry.debit *= -1

if (
flt(entry.debit_in_account_currency) < 0
and flt(entry.credit_in_account_currency) < 0
and flt(entry.debit_in_account_currency) == flt(entry.credit_in_account_currency)
):
entry.credit_in_account_currency *= -1
entry.debit_in_account_currency *= -1

if flt(entry.debit) < 0:
entry.credit = flt(entry.credit) - flt(entry.debit)
entry.debit = 0.0
Expand Down

0 comments on commit 6d098b7

Please sign in to comment.