diff --git a/addons/base_import/models/base_import.py b/addons/base_import/models/base_import.py index 81f1ffa89f4..041d5ef2dd1 100644 --- a/addons/base_import/models/base_import.py +++ b/addons/base_import/models/base_import.py @@ -723,6 +723,16 @@ class Import(models.TransientModel): if not line[index]: continue thousand_separator, decimal_separator = self._infer_separators(line[index], options) + + if 'E' in line[index] or 'e' in line[index]: + tmp_value = line[index].replace(thousand_separator, '.') + try: + tmp_value = '{:f}'.format(float(tmp_value)) + line[index] = tmp_value + thousand_separator = ' ' + except Exception: + pass + line[index] = line[index].replace(thousand_separator, '').replace(decimal_separator, '.') old_value = line[index] line[index] = self._remove_currency_symbol(line[index]) diff --git a/addons/base_import/tests/test_base_import.py b/addons/base_import/tests/test_base_import.py index 3fe12d4b7bb..d4cbbbd866c 100644 --- a/addons/base_import/tests/test_base_import.py +++ b/addons/base_import/tests/test_base_import.py @@ -468,6 +468,27 @@ class test_convert_import_data(TransactionCase): self.assertEqual(float(result[0][-1]), 5.69) self.assertEqual(str(result[0][-2]), '2017-10-12') + def test_parse_scientific_notation(self): + """ Ensure that scientific notation is correctly converted to decimal """ + import_wizard = self.env['base_import.import'] + + test_options = {} + test_data = [ + ["1E+05"], + ["1.20E-05"], + ["1,9e5"], + ["9,5e-5"], + ] + expected_result = [ + ["100000.000000"], + ["0.000012"], + ["190000.000000"], + ["0.000095"], + ] + + import_wizard._parse_float_from_data(test_data, 0, 'test-name', test_options) + self.assertEqual(test_data, expected_result) + def test_filtered(self): """ If ``False`` is provided as field mapping for a column, that column should be removed from importable data