From 33e835c4d32276922a27d75ced8cf5fa95bc2c58 Mon Sep 17 00:00:00 2001 From: Vishakh Desai Date: Sat, 28 Sep 2024 12:48:14 +0530 Subject: [PATCH] fix: Get Entries not showing accounts with no gain or loss in Exchange Rate Revaluation issue (cherry picked from commit 6de6f55b390c1e2180a4698ce25ceba920578b2c) --- .../exchange_rate_revaluation.py | 82 +++++++++++-------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py index 24a325b9164..67e16eb6d8e 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py @@ -52,6 +52,21 @@ class ExchangeRateRevaluation(Document): if not (self.company and self.posting_date): frappe.throw(_("Please select Company and Posting Date to getting entries")) + def on_submit(self): + self.remove_accounts_without_gain_loss() + + def remove_accounts_without_gain_loss(self): + self.accounts = [account for account in self.accounts if account.gain_loss] + + if not self.accounts: + frappe.throw(_("At least one account with exchange gain or loss is required")) + + frappe.msgprint( + _("Removing rows without exchange gain or loss"), + alert=True, + indicator="yellow", + ) + def on_cancel(self): self.ignore_linked_doctypes = "GL Entry" @@ -226,23 +241,23 @@ class ExchangeRateRevaluation(Document): new_exchange_rate = get_exchange_rate(d.account_currency, company_currency, posting_date) new_balance_in_base_currency = flt(d.balance_in_account_currency * new_exchange_rate) gain_loss = flt(new_balance_in_base_currency, precision) - flt(d.balance, precision) - if gain_loss: - accounts.append( - { - "account": d.account, - "party_type": d.party_type, - "party": d.party, - "account_currency": d.account_currency, - "balance_in_base_currency": d.balance, - "balance_in_account_currency": d.balance_in_account_currency, - "zero_balance": d.zero_balance, - "current_exchange_rate": current_exchange_rate, - "new_exchange_rate": new_exchange_rate, - "new_balance_in_base_currency": new_balance_in_base_currency, - "new_balance_in_account_currency": d.balance_in_account_currency, - "gain_loss": gain_loss, - } - ) + + accounts.append( + { + "account": d.account, + "party_type": d.party_type, + "party": d.party, + "account_currency": d.account_currency, + "balance_in_base_currency": d.balance, + "balance_in_account_currency": d.balance_in_account_currency, + "zero_balance": d.zero_balance, + "current_exchange_rate": current_exchange_rate, + "new_exchange_rate": new_exchange_rate, + "new_balance_in_base_currency": new_balance_in_base_currency, + "new_balance_in_account_currency": d.balance_in_account_currency, + "gain_loss": gain_loss, + } + ) # Handle Accounts with '0' balance in Account/Base Currency for d in [x for x in account_details if x.zero_balance]: @@ -266,23 +281,22 @@ class ExchangeRateRevaluation(Document): current_exchange_rate * d.balance_in_account_currency ) - if gain_loss: - accounts.append( - { - "account": d.account, - "party_type": d.party_type, - "party": d.party, - "account_currency": d.account_currency, - "balance_in_base_currency": d.balance, - "balance_in_account_currency": d.balance_in_account_currency, - "zero_balance": d.zero_balance, - "current_exchange_rate": current_exchange_rate, - "new_exchange_rate": new_exchange_rate, - "new_balance_in_base_currency": new_balance_in_base_currency, - "new_balance_in_account_currency": new_balance_in_account_currency, - "gain_loss": gain_loss, - } - ) + accounts.append( + { + "account": d.account, + "party_type": d.party_type, + "party": d.party, + "account_currency": d.account_currency, + "balance_in_base_currency": d.balance, + "balance_in_account_currency": d.balance_in_account_currency, + "zero_balance": d.zero_balance, + "current_exchange_rate": current_exchange_rate, + "new_exchange_rate": new_exchange_rate, + "new_balance_in_base_currency": new_balance_in_base_currency, + "new_balance_in_account_currency": new_balance_in_account_currency, + "gain_loss": gain_loss, + } + ) return accounts