[FIX] base_import: handling of scientific notation
Steps to reproduce: -install sales -try to import a product file with volumes set to scientific notation (9.2e-05 for example) Previous behavior: scientific notation is not recognized by the base_import module and raises a small warning Current behavior: scientific notation is converted to decimal notation on the fly when possible opw-2162353 closes odoo/odoo#42591 X-original-commit: 9acd76c5d116abd07207af3b548658ad983ff82d Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user