diff options
| author | Andrea Grazioso (agr-odoo) <agr@odoo.com> | 2021-02-10 18:34:25 +0000 |
|---|---|---|
| committer | Andrea Grazioso (agr-odoo) <agr@odoo.com> | 2021-03-09 15:12:15 +0000 |
| commit | 2a3722d52d1059d9b747077f9660ecd932579de2 (patch) | |
| tree | 5875108b38bc009221cf2c7c09391bf1d6d4c8be /addons/web/controllers | |
| parent | 4b2f0ddcbe859ec8453e537aec9d5b0685876eca (diff) | |
[FIX] web: fix float value representation in export
- Create a product with:
Cost: 60.80
Quantity On Hand: 999.0
- Go to Inventory / Reporting / Inventory Valuation
- Click on export all (little button next to "Inventory at date")
The field "Total value" have too many decimals: 60739.2000000004
This occur because of the multiplication: it yield the correct value
(60739.2), but every rounding attempt done, even in the ORM, will
mess up the representation
https://github.com/odoo/odoo/blob/042298f8c949fba470eda6ad90f94c95ca291030/odoo/fields.py#L1333
opw-2438384
closes odoo/odoo#67543
X-original-commit: 67cf82962688360cfe25c6b2118a7dbd17a6ee95
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
Diffstat (limited to 'addons/web/controllers')
| -rw-r--r-- | addons/web/controllers/main.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index b15247f1ccd..80cf3fb5d79 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -854,13 +854,25 @@ class GroupExportXlsxWriter(ExportXlsxWriter): label = '%s%s (%s)' % (' ' * group_depth, label, group.count) self.write(row, column, label, self.header_bold_style) + if any(f.get('type') == 'monetary' for f in self.fields[1:]): + + decimal_places = [res['decimal_places'] for res in group._model.env['res.currency'].search_read([], ['decimal_places'])] + decimal_places = max(decimal_places) if decimal_places else 2 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) + # Float fields may not be displayed properly because of float + # representation issue with non stored fields or with values + # that, even stored, cannot be rounded properly and it is not + # acceptable to display useless digits (i.e. monetary) + # + # non stored field -> we force 2 digits + # stored monetary -> we force max digits of installed currencies + if isinstance(aggregated_value, float): + if field.get('type') == 'monetary': + aggregated_value = float_repr(aggregated_value, decimal_places) + elif not field.get('store'): + 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 |
