Browse Source

Merge PR #1787 into 12.0

Signed-off-by JordiBForgeFlow
12.0-mig-module_prototyper_last
OCA-git-bot 5 years ago
parent
commit
0350112c00
  1. 9
      excel_import_export/models/common.py
  2. 13
      excel_import_export/models/xlsx_import.py

9
excel_import_export/models/common.py

@ -268,13 +268,12 @@ def _get_cell_value(cell, field_type=False):
datemode = 0 # From book.datemode, but we fix it for simplicity datemode = 0 # From book.datemode, but we fix it for simplicity
if field_type in ['date', 'datetime']: if field_type in ['date', 'datetime']:
ctype = xlrd.sheet.ctype_text.get(cell.ctype, 'unknown type') ctype = xlrd.sheet.ctype_text.get(cell.ctype, 'unknown type')
if ctype == 'number':
if ctype in ('xldate', 'number'):
is_datetime = cell.value % 1 != 0.0
time_tuple = xlrd.xldate_as_tuple(cell.value, datemode) time_tuple = xlrd.xldate_as_tuple(cell.value, datemode)
date = dt(*time_tuple) date = dt(*time_tuple)
if field_type == 'date':
value = date.strftime("%Y-%m-%d")
elif field_type == 'datetime':
value = date.strftime("%Y-%m-%d %H:%M:%S")
value = (date.strftime("%Y-%m-%d %H:%M:%S")
if is_datetime else date.strftime("%Y-%m-%d"))
else: else:
value = cell.value value = cell.value
elif field_type in ['integer', 'float']: elif field_type in ['integer', 'float']:

13
excel_import_export/models/xlsx_import.py

@ -203,14 +203,19 @@ class XLSXImport(models.AbstractModel):
'encoding': '', 'encoding': '',
'separator': '', 'separator': '',
'quoting': '"', 'quoting': '"',
'date_style': '',
'datetime_style': '%Y-%m-%d %H:%M:%S',
'date_format': '%Y-%m-%d',
'datetime_format': '%Y-%m-%d %H:%M:%S',
'float_thousand_separator': ',', 'float_thousand_separator': ',',
'float_decimal_separator': '.', 'float_decimal_separator': '.',
'fields': []}) 'fields': []})
if errors.get('messages'): if errors.get('messages'):
message = errors['messages']['message'].encode('utf-8')
raise ValidationError(message)
message = _('Error importing data')
messages = errors['messages']
if isinstance(messages, dict):
message = messages['message']
if isinstance(messages, list):
message = ', '.join([x['message'] for x in messages])
raise ValidationError(message.encode('utf-8'))
return self.env.ref(xml_id) return self.env.ref(xml_id)
except xlrd.XLRDError: except xlrd.XLRDError:
raise ValidationError( raise ValidationError(

Loading…
Cancel
Save