summaryrefslogtreecommitdiff
path: root/addons/web/controllers
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2020-11-20 11:14:23 +0000
committerNicolas Martinelli <nim@odoo.com>2020-11-24 15:36:15 +0000
commitaf14148b69ad1a7704a759e6ec33b035b88df8c9 (patch)
treeb68fd246ec1ba3bbc1f2c17417acf2e8578312b6 /addons/web/controllers
parent478a42beb5876171afeab7df27fa69548edbf849 (diff)
[FIX] web: grouped export
- Create a product with: Cost: 60.80 Quantity On Hand: 999.0 - Go to Inventory / Reporting / Inventory Report - Export as XLS The header values have too many decimals: 60739.2000000007 The root cause is `convert_to_cache` returns this value: https://github.com/odoo/odoo/blob/042298f8c949fba470eda6ad90f94c95ca291030/odoo/fields.py#L1333 In this case, `currency.round()` keeps the extra digits. Since the field is not stored, the useless digits are kept. A simple solution is to use `float_repr` on the non-stored float fields to make sure that doesn't happen. Another solution could be to not convert the floats to strings, but that doesn't seem intended. opw-2378895 closes odoo/odoo#62260 X-original-commit: 2ebcbb16f113dee1416097b7a52f8068a40a34cf Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons/web/controllers')
-rw-r--r--addons/web/controllers/main.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 6cac30fea6a..d09f5401786 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