diff --git a/addons/test_xlsx_export/tests/test_export.py b/addons/test_xlsx_export/tests/test_export.py index d8a3c4eaebd..c8e032487b2 100644 --- a/addons/test_xlsx_export/tests/test_export.py +++ b/addons/test_xlsx_export/tests/test_export.py @@ -6,6 +6,7 @@ from unittest.mock import patch from odoo import http from odoo.tests import common, tagged +from odoo.tools.misc import get_lang from odoo.addons.web.controllers.export import ExportXlsxWriter from odoo.addons.mail.tests.common import mail_new_test_user @@ -373,3 +374,20 @@ class TestGroupedExport(XlsxCreatorCase): [' 1000.0 (1)', '1000.000'], ['3', '1000.00'], ]) + + def test_decimal_separator(self): + """ The decimal separator of the language used shouldn't impact the float representation in the exported xlsx """ + get_lang(self.env).decimal_point = ',' + get_lang(self.env).thousands_sep = '.' + + values = [ + {'int_sum': 1, 'float_min': 86420.864}, + ] + export = self.export(values, fields=['int_sum', 'float_min'], params={'groupby': ['int_sum', 'float_min']}) + + self.assertExportEqual(export, [ + ['Int Sum' ,'Float Min'], + ['1 (1)' ,'86420.86'], + [' 86420.864 (1)','86420.86'], + ['1' ,'86420.86'], + ]) diff --git a/addons/web/controllers/export.py b/addons/web/controllers/export.py index 93eaba4ad6e..e2dc55fe214 100644 --- a/addons/web/controllers/export.py +++ b/addons/web/controllers/export.py @@ -17,7 +17,7 @@ from odoo import http from odoo.exceptions import UserError from odoo.http import content_disposition, request from odoo.tools import lazy_property, osutil, pycompat -from odoo.tools.misc import xlsxwriter, get_lang +from odoo.tools.misc import xlsxwriter from odoo.tools.translate import _ @@ -183,11 +183,10 @@ class ExportXlsxWriter: self.datetime_style = self.workbook.add_format({'text_wrap': True, 'num_format': 'yyyy-mm-dd hh:mm:ss'}) self.worksheet = self.workbook.add_worksheet() self.value = False - decimal_separator = get_lang(request.env).decimal_point - self.float_format = f'0{decimal_separator}00' + self.float_format = '#,##0.00' decimal_places = [res['decimal_places'] for res in request.env['res.currency'].search_read([], ['decimal_places'])] - self.monetary_format = f'0{decimal_separator}{max(decimal_places or [2]) * "0"}' + self.monetary_format = f'#,##0.{max(decimal_places or [2]) * "0"}' if row_count > self.worksheet.xls_rowmax: raise UserError(_('There are too many rows (%s rows, limit: %s) to export as Excel 2007-2013 (.xlsx) format. Consider splitting the export.') % (row_count, self.worksheet.xls_rowmax))