From aed8e199ce5798dbfe8392695646fbdeb78f45f4 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 21 Mar 2018 11:55:55 +0100 Subject: [PATCH] [FIX] base_import: import empty date/datetime When a user imports a file with a datetime field set to a blank space, the value is computed as 1900-01-01 00:00:00. However, when converted in the user's TZ, this can lead to a value < 1900-01-01, which is not recognized at the JS level as a valid value. This makes the access to the record impossible, and possibly makes the access to an app impossible. It is for example the case with Purchase, where the order date is displayed on the default's action view (list view). We strip the value before testing if the value exists to avoid this case. opw-1826344 --- addons/base_import/models/base_import.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/base_import/models/base_import.py b/addons/base_import/models/base_import.py index 83c9c76cb1e..dbff99fab88 100644 --- a/addons/base_import/models/base_import.py +++ b/addons/base_import/models/base_import.py @@ -622,9 +622,11 @@ class Import(models.TransientModel): # versions, for both data and pattern user_format = pycompat.to_native(options.get('%s_format' % field['type'])) for num, line in enumerate(data): + if line[index]: + line[index] = line[index].strip() if line[index]: try: - line[index] = dt.strftime(dt.strptime(pycompat.to_native(line[index].strip()), user_format), server_format) + line[index] = dt.strftime(dt.strptime(pycompat.to_native(line[index]), user_format), server_format) except ValueError as e: raise ValueError(_("Column %s contains incorrect values. Error in line %d: %s") % (name, num + 1, e)) except Exception as e: