Skip to content

Commit

Permalink
refactor: create gain/loss on Cr/Dr notes with different exc rates
Browse files Browse the repository at this point in the history
(cherry picked from commit ba1f065)
  • Loading branch information
ruthra-kumar authored and mergify[bot] committed Aug 14, 2023
1 parent 22dbe52 commit 72a507f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion erpnext/accounts/doctype/journal_entry/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,9 @@ def validate_reference_doc(self):
else:
party_account = against_voucher[1]

if against_voucher[0] != cstr(d.party) or party_account != d.account:
if (
against_voucher[0] != cstr(d.party) or party_account != d.account
) and self.voucher_type != "Exchange Gain Or Loss":
frappe.throw(
_("Row {0}: Party / Account does not match with {1} / {2} in {3} {4}").format(
d.idx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from erpnext.accounts.utils import (
QueryPaymentLedger,
create_gain_loss_journal,
get_outstanding_invoices,
reconcile_against_document,
)
Expand Down Expand Up @@ -671,4 +672,28 @@ def get_difference_row(inv):
jv.flags.ignore_exchange_rate = True
>>>>>>> c87332d5da (refactor: cr/dr note will be on single exchange rate)
jv.submit()
jv.make_exchange_gain_loss_journal(args=[inv])

# make gain/loss journal
if inv.party_type == "Customer":
dr_or_cr = "credit" if inv.difference_amount < 0 else "debit"
else:
dr_or_cr = "debit" if inv.difference_amount < 0 else "credit"

reverse_dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"

create_gain_loss_journal(
company,
inv.party_type,
inv.party,
inv.account,
inv.difference_account,
inv.difference_amount,
dr_or_cr,
reverse_dr_or_cr,
inv.against_voucher_type,
inv.against_voucher,
None,
inv.voucher_type,
inv.voucher_no,
None,
)

0 comments on commit 72a507f

Please sign in to comment.