refactor: create gain/loss on Cr/Dr notes with different exc rates
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 0c23d77..daa6355 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -586,7 +586,9 @@
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,
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
index 2c11ef5..5937a29 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
@@ -14,6 +14,7 @@
)
from erpnext.accounts.utils import (
QueryPaymentLedger,
+ create_gain_loss_journal,
get_outstanding_invoices,
reconcile_against_document,
)
@@ -673,4 +674,28 @@
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,
+ )