[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>
This commit is contained in:
Lucas Perais (lpe)
2019-03-14 13:14:07 +00:00
committed by Nicolas Martinelli
parent 1ceb689805
commit 04f7c650d0
+9 -5
View File
@@ -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)