Merge pull request #35620 from ruthra-kumar/err_higher_allowance_for_debit_credit_diff

fix: allow custom rounding loss allowance in Exchange Rate Revaluation
This commit is contained in:
ruthra kumar 2023-06-13 09:46:08 +05:30 committed by GitHub
commit b672616617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 6 deletions

View File

@ -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) { get_entries: function(frm, account) {
frappe.call({ frappe.call({
method: "get_accounts_data", method: "get_accounts_data",
@ -126,7 +141,8 @@ var get_account_details = function(frm, cdt, cdn) {
company: frm.doc.company, company: frm.doc.company,
posting_date: frm.doc.posting_date, posting_date: frm.doc.posting_date,
party_type: row.party_type, party_type: row.party_type,
party: row.party party: row.party,
rounding_loss_allowance: frm.doc.rounding_loss_allowance
}, },
callback: function(r){ callback: function(r){
$.extend(row, r.message); $.extend(row, r.message);

View File

@ -8,6 +8,7 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"posting_date", "posting_date",
"rounding_loss_allowance",
"column_break_2", "column_break_2",
"company", "company",
"section_break_4", "section_break_4",
@ -96,11 +97,18 @@
{ {
"fieldname": "column_break_10", "fieldname": "column_break_10",
"fieldtype": "Column Break" "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, "is_submittable": 1,
"links": [], "links": [],
"modified": "2022-12-29 19:38:24.416529", "modified": "2023-06-12 21:02:09.818208",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Exchange Rate Revaluation", "name": "Exchange Rate Revaluation",

View File

@ -18,8 +18,13 @@ from erpnext.setup.utils import get_exchange_rate
class ExchangeRateRevaluation(Document): class ExchangeRateRevaluation(Document):
def validate(self): def validate(self):
self.validate_rounding_loss_allowance()
self.set_total_gain_loss() 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): def set_total_gain_loss(self):
total_gain_loss = 0 total_gain_loss = 0
@ -92,7 +97,12 @@ class ExchangeRateRevaluation(Document):
def get_accounts_data(self): def get_accounts_data(self):
self.validate_mandatory() self.validate_mandatory()
account_details = self.get_account_balance_from_gle( 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( accounts_with_new_balance = self.calculate_new_account_balance(
self.company, self.posting_date, account_details self.company, self.posting_date, account_details
@ -104,7 +114,9 @@ class ExchangeRateRevaluation(Document):
return accounts_with_new_balance return accounts_with_new_balance
@staticmethod @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 = [] account_details = []
if company and posting_date: if company and posting_date:
@ -172,10 +184,18 @@ class ExchangeRateRevaluation(Document):
) )
# round off balance based on currency precision # round off balance based on currency precision
# and consider debit-credit difference allowance
currency_precision = get_currency_precision() currency_precision = get_currency_precision()
rounding_loss_allowance = rounding_loss_allowance or 0.05
for acc in account_details: for acc in account_details:
acc.balance_in_account_currency = flt(acc.balance_in_account_currency, currency_precision) 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) acc.balance = flt(acc.balance, currency_precision)
if abs(acc.balance) <= rounding_loss_allowance:
acc.balance = 0
acc.zero_balance = ( acc.zero_balance = (
True if (acc.balance == 0 or acc.balance_in_account_currency == 0) else False 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() @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): if not (company and posting_date):
frappe.throw(_("Company and Posting Date is mandatory")) 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_currency": account_currency,
} }
account_balance = ExchangeRateRevaluation.get_account_balance_from_gle( 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 ( if account_balance and (