diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.js b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.js index f72ecc9e501f..733a7616b210 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.js +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.js @@ -35,6 +35,21 @@ frappe.ui.form.on('Exchange Rate Revaluation', { } }, + validate_rounding_loss: function(frm) { + allowance = frm.doc.rounding_loss_allowance; + if (!(allowance > 0 && allowance < 1)) { + frappe.throw(__("Rounding Loss Allowance should be between 0 and 1")); + } + }, + + rounding_loss_allowance: function(frm) { + frm.events.validate_rounding_loss(frm); + }, + + validate: function(frm) { + frm.events.validate_rounding_loss(frm); + }, + get_entries: function(frm, account) { frappe.call({ method: "get_accounts_data", @@ -126,7 +141,8 @@ var get_account_details = function(frm, cdt, cdn) { company: frm.doc.company, posting_date: frm.doc.posting_date, party_type: row.party_type, - party: row.party + party: row.party, + rounding_loss_allowance: frm.doc.rounding_loss_allowance }, callback: function(r){ $.extend(row, r.message); diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.json b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.json index 0d198ca12012..2310d1272cde 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.json +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.json @@ -8,6 +8,7 @@ "engine": "InnoDB", "field_order": [ "posting_date", + "rounding_loss_allowance", "column_break_2", "company", "section_break_4", @@ -96,11 +97,18 @@ { "fieldname": "column_break_10", "fieldtype": "Column Break" + }, + { + "default": "0.05", + "description": "Only values between 0 and 1 are allowed. \nEx: If allowance is set at 0.07, accounts that have balance of 0.07 in either of the currencies will be considered as zero balance account", + "fieldname": "rounding_loss_allowance", + "fieldtype": "Float", + "label": "Rounding Loss Allowance" } ], "is_submittable": 1, "links": [], - "modified": "2022-12-29 19:38:24.416529", + "modified": "2023-06-12 21:02:09.818208", "modified_by": "Administrator", "module": "Accounts", "name": "Exchange Rate Revaluation", 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 b528ee58e233..043fbdd5d6c3 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py @@ -18,8 +18,13 @@ class ExchangeRateRevaluation(Document): def validate(self): + self.validate_rounding_loss_allowance() self.set_total_gain_loss() + def validate_rounding_loss_allowance(self): + if not (self.rounding_loss_allowance > 0 and self.rounding_loss_allowance < 1): + frappe.throw(_("Rounding Loss Allowance should be between 0 and 1")) + def set_total_gain_loss(self): total_gain_loss = 0 @@ -92,7 +97,12 @@ def check_journal_entry_condition(self): def get_accounts_data(self): self.validate_mandatory() account_details = self.get_account_balance_from_gle( - company=self.company, posting_date=self.posting_date, account=None, party_type=None, party=None + company=self.company, + posting_date=self.posting_date, + account=None, + party_type=None, + party=None, + rounding_loss_allowance=self.rounding_loss_allowance, ) accounts_with_new_balance = self.calculate_new_account_balance( self.company, self.posting_date, account_details @@ -104,7 +114,9 @@ def get_accounts_data(self): return accounts_with_new_balance @staticmethod - def get_account_balance_from_gle(company, posting_date, account, party_type, party): + def get_account_balance_from_gle( + company, posting_date, account, party_type, party, rounding_loss_allowance + ): account_details = [] if company and posting_date: @@ -172,10 +184,18 @@ def get_account_balance_from_gle(company, posting_date, account, party_type, par ) # round off balance based on currency precision + # and consider debit-credit difference allowance currency_precision = get_currency_precision() + rounding_loss_allowance = rounding_loss_allowance or 0.05 for acc in account_details: acc.balance_in_account_currency = flt(acc.balance_in_account_currency, currency_precision) + if abs(acc.balance_in_account_currency) <= rounding_loss_allowance: + acc.balance_in_account_currency = 0 + acc.balance = flt(acc.balance, currency_precision) + if abs(acc.balance) <= rounding_loss_allowance: + acc.balance = 0 + acc.zero_balance = ( True if (acc.balance == 0 or acc.balance_in_account_currency == 0) else False ) @@ -531,7 +551,9 @@ def calculate_exchange_rate_using_last_gle(company, account, party_type, party): @frappe.whitelist() -def get_account_details(company, posting_date, account, party_type=None, party=None): +def get_account_details( + company, posting_date, account, party_type=None, party=None, rounding_loss_allowance=None +): if not (company and posting_date): frappe.throw(_("Company and Posting Date is mandatory")) @@ -549,7 +571,12 @@ def get_account_details(company, posting_date, account, party_type=None, party=N "account_currency": account_currency, } account_balance = ExchangeRateRevaluation.get_account_balance_from_gle( - company=company, posting_date=posting_date, account=account, party_type=party_type, party=party + company=company, + posting_date=posting_date, + account=account, + party_type=party_type, + party=party, + rounding_loss_allowance=rounding_loss_allowance, ) if account_balance and (