diff --git a/addons/test_xlsx_export/tests/test_export.py b/addons/test_xlsx_export/tests/test_export.py index 5ba8c0a0de5..22b759e7940 100644 --- a/addons/test_xlsx_export/tests/test_export.py +++ b/addons/test_xlsx_export/tests/test_export.py @@ -116,13 +116,13 @@ class TestGroupedExport(XlsxCreatorCase): self.assertExportEqual(export, [ ['Int Sum' ,'Float Min'], - ['10 (2)' ,'111.0'], - [' 111.0 (1)','111.0'], + ['10 (2)' ,'111.00'], + [' 111.0 (1)','111.00'], ['10' ,'111.0'], - [' 222.0 (1)','222.0'], + [' 222.0 (1)','222.00'], ['10' ,'222.0'], - ['20 (1)' ,'333.0'], - [' 333.0 (1)','333.0'], + ['20 (1)' ,'333.00'], + [' 333.0 (1)','333.00'], ['20' ,'333.0'], ]) @@ -136,13 +136,13 @@ class TestGroupedExport(XlsxCreatorCase): self.assertExportEqual(export, [ ['Int Sum' ,'Float Avg'], - ['10 (2)' ,'150.0'], - [' 100.0 (1)','100.0'], + ['10 (2)' ,'150.00'], + [' 100.0 (1)','100.00'], ['10' ,'100.0'], - [' 200.0 (1)','200.0'], + [' 200.0 (1)','200.00'], ['10' ,'200.0'], - ['20 (1)' ,'300.0'], - [' 300.0 (1)','300.0'], + ['20 (1)' ,'300.00'], + [' 300.0 (1)','300.00'], ['20' ,'300.0'], ]) @@ -157,14 +157,14 @@ class TestGroupedExport(XlsxCreatorCase): self.assertExportEqual(export, [ ['Int Sum' ,'Float Avg'], - ['10 (3)' ,'300.0'], - [' 20 (1)' ,'600.0'], - [' 600.0 (1)','600.0'], + ['10 (3)' ,'300.00'], + [' 20 (1)' ,'600.00'], + [' 600.0 (1)','600.00'], ['10' ,'600.0'], - [' 30 (2)' ,'150.0'], - [' 100.0 (1)','100.0'], + [' 30 (2)' ,'150.00'], + [' 100.0 (1)','100.00'], ['10' ,'100.0'], - [' 200.0 (1)','200.0'], + [' 200.0 (1)','200.00'], ['10' ,'200.0'], ]) @@ -179,12 +179,12 @@ class TestGroupedExport(XlsxCreatorCase): self.assertExportEqual(export, [ ['Int Sum' ,'Float Avg'], - ['10 (3)' ,'0.0'], - [' 20 (1)' ,'0.0'], - [' Undefined (1)','0.0'], + ['10 (3)' ,'0.00'], + [' 20 (1)' ,'0.00'], + [' Undefined (1)','0.00'], ['10' ,'0.0'], - [' 30 (2)' ,'0.0'], - [' Undefined (2)','0.0'], + [' 30 (2)' ,'0.00'], + [' Undefined (2)','0.00'], ['10' ,'0.0'], ['10' ,'0.0'], ]) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 4682842314f..f1095773a6d 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -34,7 +34,7 @@ import odoo import odoo.modules.registry from odoo.api import call_kw, Environment from odoo.modules import get_module_path, get_resource_path -from odoo.tools import image_process, topological_sort, html_escape, pycompat, ustr, apply_inheritance_specs, lazy_property +from odoo.tools import image_process, topological_sort, html_escape, pycompat, ustr, apply_inheritance_specs, lazy_property, float_repr from odoo.tools.mimetypes import guess_mimetype from odoo.tools.translate import _ from odoo.tools.misc import str2bool, xlsxwriter, file_open @@ -843,6 +843,10 @@ class GroupExportXlsxWriter(ExportXlsxWriter): for field in self.fields[1:]: # No aggregates allowed in the first column because of the group title column += 1 aggregated_value = aggregates.get(field['name']) + # Non-stored float fields may not be displayed properly because of float representation + # => we force 2 digits + if not field.get('store') and isinstance(aggregated_value, float): + aggregated_value = float_repr(aggregated_value, 2) self.write(row, column, str(aggregated_value if aggregated_value is not None else ''), self.header_bold_style) return row + 1, 0 diff --git a/addons/web/static/src/js/widgets/data_export.js b/addons/web/static/src/js/widgets/data_export.js index 61b2cffe862..85c6886ea0b 100644 --- a/addons/web/static/src/js/widgets/data_export.js +++ b/addons/web/static/src/js/widgets/data_export.js @@ -119,6 +119,7 @@ var DataExport = Dialog.extend({ let exportedFields = this.defaultExportFields.map(field => ({ name: field, label: this.record.fields[field].string, + store: this.record.fields[field].store, })); this._exportData(exportedFields, 'xlsx', false); },