summaryrefslogtreecommitdiff
path: root/addons/test_xlsx_export
diff options
context:
space:
mode:
authorAndrea Grazioso (agr-odoo) <agr@odoo.com>2021-02-10 18:34:25 +0000
committerAndrea Grazioso (agr-odoo) <agr@odoo.com>2021-03-09 15:12:15 +0000
commit2a3722d52d1059d9b747077f9660ecd932579de2 (patch)
tree5875108b38bc009221cf2c7c09391bf1d6d4c8be /addons/test_xlsx_export
parent4b2f0ddcbe859ec8453e537aec9d5b0685876eca (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/test_xlsx_export')
-rw-r--r--addons/test_xlsx_export/models.py2
-rw-r--r--addons/test_xlsx_export/tests/test_export.py29
2 files changed, 31 insertions, 0 deletions
diff --git a/addons/test_xlsx_export/models.py b/addons/test_xlsx_export/models.py
index 99d96ba63cb..830917c0664 100644
--- a/addons/test_xlsx_export/models.py
+++ b/addons/test_xlsx_export/models.py
@@ -20,6 +20,8 @@ class GroupOperator(models.Model):
int_max = fields.Integer(group_operator='max')
float_min = fields.Float(group_operator='min')
float_avg = fields.Float(group_operator='avg')
+ float_monetary = fields.Monetary(currency_field='currency_id',group_operator='sum')
+ currency_id = fields.Many2one('res.currency')
date_max = fields.Date(group_operator='max')
bool_and = fields.Boolean(group_operator='bool_and')
bool_or = fields.Boolean(group_operator='bool_or')
diff --git a/addons/test_xlsx_export/tests/test_export.py b/addons/test_xlsx_export/tests/test_export.py
index 22b759e7940..0ee3a05d087 100644
--- a/addons/test_xlsx_export/tests/test_export.py
+++ b/addons/test_xlsx_export/tests/test_export.py
@@ -50,6 +50,7 @@ class XlsxCreatorCase(common.HttpCase):
params['fields'] = [{
'name': self.model._fields[f].name,
'label': self.model._fields[f].string,
+ 'type': self.model._fields[f].type,
} for f in fields]
with patch.object(ExportXlsxWriter, 'write', self._mock_write):
@@ -340,3 +341,31 @@ class TestGroupedExport(XlsxCreatorCase):
[' Undefined (1)' ,''],
['10' ,''],
])
+
+ def test_float_representation(self):
+ currency = self.env['res.currency'].create({
+ 'name': "bottlecap",
+ 'symbol': "b",
+ 'rounding': 0.001,
+ 'decimal_places': 3,
+ })
+
+ values = [
+ {'int_sum': 1, 'currency_id': currency.id, 'float_monetary': 60739.2000000004},
+ {'int_sum': 2, 'currency_id': currency.id, 'float_monetary': 2.0},
+ {'int_sum': 3, 'currency_id': currency.id, 'float_monetary': 999.9995999},
+ ]
+ export = self.export(values, fields=['int_sum', 'float_monetary'], params={'groupby': ['int_sum', 'float_monetary']})
+
+ self.assertExportEqual(export, [
+ ['Int Sum', 'Float Monetary'],
+ ['1 (1)','60739.200'],
+ [' 60739.2 (1)','60739.200'],
+ ['1','60739.2'],
+ ['2 (1)','2.000'],
+ [' 2.0 (1)','2.000'],
+ ['2','2.0'],
+ ['3 (1)','1000.000'],
+ [' 1000.0 (1)','1000.000'],
+ ['3','1000.0'],
+ ])