Skip to content

Commit

Permalink
l10n_fr_fec: float representation when summing
Browse files Browse the repository at this point in the history
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#31755

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
  • Loading branch information
kebeclibre authored and santostelmo committed Jul 29, 2022
1 parent 0680b98 commit 3db1bd3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions addons/l10n_fr_fec/wizard/account_fr_fec.py
Expand Up @@ -9,7 +9,7 @@

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):
Expand Down Expand Up @@ -170,14 +170,16 @@ def generate_fec(self):

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)
Expand All @@ -190,6 +192,8 @@ def generate_fec(self):
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'
Expand Down Expand Up @@ -256,11 +260,11 @@ def generate_fec(self):

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)
Expand Down

0 comments on commit 3db1bd3

Please sign in to comment.