From d8cf6ba38d42e401888a9018eb18afcd89d0aae9 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 1 Mar 2024 17:46:42 +0530 Subject: [PATCH] fix: allow gain/loss for Journals against Journals (cherry picked from commit 5b67631d40ddebcc6111aecb9c2f8882903d88f9) --- .../doctype/journal_entry/journal_entry.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 4537dede923..f06fafcc5cf 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -559,17 +559,28 @@ class JournalEntry(AccountsController): elif d.party_type == "Supplier" and flt(d.credit) > 0: frappe.throw(_("Row {0}: Advance against Supplier must be debit").format(d.idx)) + def system_generated_gain_loss(self): + return ( + self.voucher_type == "Exchange Gain Or Loss" + and self.multi_currency + and self.is_system_generated + ) + def validate_against_jv(self): for d in self.get("accounts"): if d.reference_type == "Journal Entry": account_root_type = frappe.get_cached_value("Account", d.account, "root_type") - if account_root_type == "Asset" and flt(d.debit) > 0: + if account_root_type == "Asset" and flt(d.debit) > 0 and not self.system_generated_gain_loss(): frappe.throw( _( "Row #{0}: For {1}, you can select reference document only if account gets credited" ).format(d.idx, d.account) ) - elif account_root_type == "Liability" and flt(d.credit) > 0: + elif ( + account_root_type == "Liability" + and flt(d.credit) > 0 + and not self.system_generated_gain_loss() + ): frappe.throw( _( "Row #{0}: For {1}, you can select reference document only if account gets debited" @@ -601,7 +612,7 @@ class JournalEntry(AccountsController): for jvd in against_entries: if flt(jvd[dr_or_cr]) > 0: valid = True - if not valid: + if not valid and not self.system_generated_gain_loss(): frappe.throw( _("Against Journal Entry {0} does not have any unmatched {1} entry").format( d.reference_name, dr_or_cr