refactor: create gain/loss on Cr/Dr notes with different exc rates

This commit is contained in:
ruthra kumar 2023-07-26 16:46:50 +05:30
parent 1ea1bfebc4
commit ba1f065765
2 changed files with 29 additions and 2 deletions

View File

@ -586,7 +586,9 @@ class JournalEntry(AccountsController):
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,

View File

@ -14,6 +14,7 @@ from erpnext.accounts.doctype.process_payment_reconciliation.process_payment_rec
)
from erpnext.accounts.utils import (
QueryPaymentLedger,
create_gain_loss_journal,
get_outstanding_invoices,
reconcile_against_document,
)
@ -673,4 +674,28 @@ def reconcile_dr_cr_note(dr_cr_notes, company):
jv.flags.ignore_mandatory = True
jv.flags.ignore_exchange_rate = True
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,
)