diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2019-03-11 16:36:37 +0000 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2019-03-14 13:14:07 +0000 |
| commit | 04f7c650d0e2a727002c2d271c6ad24fc38f74d3 (patch) | |
| tree | ba4f237de9660c3dbe92a28f513a9a660f8184b0 | |
| parent | 1ceb68980512b94aad98472650d9db7ea029a4ed (diff) | |
[FIX] l10n_fr_fec: float representation when summing
Before this commit, it may happen that the the grouped account move lines
sum will be business-wise "zero" but that its representation in SQL will not be
rather, it will be equal to "10^[-high number]"
After this commit, we round the sum to the number of digits of the company's currency
to see if it is equal to zero, or not.
We also need to filter out the specific case of unaffected earnings
OPW 1942177
closes odoo/odoo#31755
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
| -rw-r--r-- | addons/l10n_fr_fec/wizard/account_fr_fec.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/addons/l10n_fr_fec/wizard/account_fr_fec.py b/addons/l10n_fr_fec/wizard/account_fr_fec.py index 88284475764..b9e8af84869 100644 --- a/addons/l10n_fr_fec/wizard/account_fr_fec.py +++ b/addons/l10n_fr_fec/wizard/account_fr_fec.py @@ -9,7 +9,7 @@ from datetime import datetime from odoo import api, fields, models, _ from odoo.exceptions import Warning -from odoo.tools import pycompat, DEFAULT_SERVER_DATE_FORMAT +from odoo.tools import float_is_zero, pycompat, DEFAULT_SERVER_DATE_FORMAT class AccountFrFec(models.TransientModel): @@ -183,14 +183,16 @@ class AccountFrFec(models.TransientModel): sql_query += ''' GROUP BY aml.account_id, aat.type - HAVING sum(aml.balance) != 0 + HAVING round(sum(aml.balance), %s) != 0 AND aat.type not in ('receivable', 'payable') ''' formatted_date_from = self.date_from.replace('-', '') date_from = datetime.strptime(self.date_from, DEFAULT_SERVER_DATE_FORMAT) formatted_date_year = date_from.year + currency_digits = 2 + self._cr.execute( - sql_query, (formatted_date_year, formatted_date_from, formatted_date_from, formatted_date_from, self.date_from, company.id)) + sql_query, (formatted_date_year, formatted_date_from, formatted_date_from, formatted_date_from, self.date_from, company.id, currency_digits)) for row in self._cr.fetchall(): listrow = list(row) @@ -203,6 +205,8 @@ class AccountFrFec(models.TransientModel): current_amount = float(listrow[11].replace(',', '.')) - float(listrow[12].replace(',', '.')) unaffected_earnings_amount = float(unaffected_earnings_results[11].replace(',', '.')) - float(unaffected_earnings_results[12].replace(',', '.')) listrow_amount = current_amount + unaffected_earnings_amount + if float_is_zero(listrow_amount, precision_digits=currency_digits): + continue if listrow_amount > 0: listrow[11] = str(listrow_amount).replace('.', ',') listrow[12] = '0,00' @@ -270,11 +274,11 @@ class AccountFrFec(models.TransientModel): sql_query += ''' GROUP BY aml.account_id, aat.type, rp.ref, rp.id - HAVING sum(aml.balance) != 0 + HAVING round(sum(aml.balance), %s) != 0 AND aat.type in ('receivable', 'payable') ''' self._cr.execute( - sql_query, (formatted_date_year, formatted_date_from, formatted_date_from, formatted_date_from, self.date_from, company.id)) + sql_query, (formatted_date_year, formatted_date_from, formatted_date_from, formatted_date_from, self.date_from, company.id, currency_digits)) for row in self._cr.fetchall(): listrow = list(row) |
