Skip to content
Permalink
Browse files

[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 #31755

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
  • Loading branch information...
kebeclibre authored and nim-odoo committed Mar 11, 2019
1 parent 1ceb689 commit 04f7c650d0e2a727002c2d271c6ad24fc38f74d3
Showing with 9 additions and 5 deletions.
  1. +9 −5 addons/l10n_fr_fec/wizard/account_fr_fec.py
@@ -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):
@@ -183,14 +183,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)
@@ -203,6 +205,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'
@@ -270,11 +274,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)

0 comments on commit 04f7c65

Please sign in to comment.
You can’t perform that action at this time.