[FIX] base_import: wrong date format
Current behaviour: Wrong format used when importing dates Steps to reproduce: 1. Change your language to German 2. Go to Sales > Orders 3. Export to XLSX 4. Change to dates to german format (ie: 10.09.2023) 5. Favorites > import records > Upload file 6. Click on Test 7. "does not match format '%Y-%m-%d'" Cause of the issue: Only default formats were taken into account because options are empty. opw-3540715 closes odoo/odoo#146744 X-original-commit: bdc006a81f83efddd693a8d4f4ffaec92da36f4a Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
This commit is contained in:
@@ -560,6 +560,9 @@ class Import(models.TransientModel):
|
||||
val = self._remove_currency_symbol(val)
|
||||
if val:
|
||||
if options.get('float_thousand_separator') and options.get('float_decimal_separator'):
|
||||
if options['float_decimal_separator'] == '.' and val.count('.') > 1:
|
||||
# This is not a float so exit this try
|
||||
float('a')
|
||||
val = val.replace(options['float_thousand_separator'], '').replace(options['float_decimal_separator'], '.')
|
||||
# We are now sure that this is a float, but we still need to find the
|
||||
# thousand and decimal separator
|
||||
@@ -1528,7 +1531,7 @@ class Import(models.TransientModel):
|
||||
|
||||
return input_file_data
|
||||
|
||||
_SEPARATORS = [' ', '/', '-', '']
|
||||
_SEPARATORS = [' ', '/', '-', '.', '']
|
||||
_PATTERN_BASELINE = [
|
||||
('%m', '%d', '%Y'),
|
||||
('%d', '%m', '%Y'),
|
||||
|
||||
@@ -476,6 +476,35 @@ class test_convert_import_data(TransactionCase):
|
||||
# if results empty, no errors
|
||||
self.assertItemsEqual(results['messages'], [])
|
||||
|
||||
def test_date_fields_no_options(self):
|
||||
import_wizard = self.env['base_import.import'].with_context(lang='de_DE').create({
|
||||
'res_model': 'res.partner',
|
||||
'file': 'name,date,create_date\n'
|
||||
'"foo","15.10.2023","15.10.2023 15:15:15"\n'.encode('utf-8'),
|
||||
'file_type': 'text/csv',
|
||||
})
|
||||
|
||||
opts = {
|
||||
'date_format': '',
|
||||
'datetime_format': '',
|
||||
'quoting': '"',
|
||||
'separator': ',',
|
||||
'float_decimal_separator': '.',
|
||||
'float_thousand_separator': ',',
|
||||
'has_headers': True
|
||||
}
|
||||
result_parse = import_wizard.parse_preview({**opts})
|
||||
|
||||
opts = result_parse['options']
|
||||
results = import_wizard.execute_import(
|
||||
['name', 'date', 'create_date'],
|
||||
[],
|
||||
{**opts}
|
||||
)
|
||||
|
||||
# if results empty, no errors
|
||||
self.assertItemsEqual(results['messages'], [])
|
||||
|
||||
def test_parse_relational_fields(self):
|
||||
""" Ensure that relational fields float and date are correctly
|
||||
parsed during the import call.
|
||||
|
||||
Reference in New Issue
Block a user