Hello,
When importing a CSV file into the Timesheet module on Trytond 6.0.0, I encountered an error related to date parsing.
Here is the error:
Warning: Traceback (most recent call last):
File “/lib/python3.7/site-packages/trytond/wsgi.py”, line 117, in dispatch_request return endpoint(request, **request.view_args)
File “/lib/python3.7/site-packages/trytond/protocols/dispatcher.py”, line 48, in rpc request, database_name, *request.rpc_params)
File “/lib/python3.7/site-packages/trytond/wsgi.py”, line 84, in auth_required return wrapped(*args, **kwargs)
File “/lib/python3.7/site-packages/trytond/protocols/wrappers.py”, line 156, in wrapper return func(request, pool, *args, **kwargs)
File “/lib/python3.7/site-packages/trytond/protocols/dispatcher.py”, line 181, in _dispatch result = rpc.result(meth(*c_args, **c_kwargs))
File “/lib/python3.7/site-packages/trytond/model/modelstorage.py”, line 985, in import_data process_lines(data, `[ ]`, fields_def)
File “/lib/python3.7/site-packages/trytond/model/modelstorage.py”, line 899, in process_lines value, ‘%Y-%m-%d’).date()
File “/_strptime.py”, line 577, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File “/_strptime.py”, line 359, in _strptime (data_string, format))
ValueError: time data ‘27.08.2025’ does not match format ‘%Y-%m-%d’
It turns out that Tryton’s importer currently only accepts dates in the YYYY-MM-DD
format because of this piece of code in trytond.model.modelstorage
:
elif field_type == ‘date’:
if isinstance(value, datetime.date):
res = value
elif value:
res = datetime.datetime.strptime(value, ‘%Y-%m-%d’).date()
else:
res = None
To handle European-style dates (DD.MM.YYYY), I solved it by extending the code with an additional try/except:
if isinstance(value, datetime.date):
res = value
elif value:
try:
res = datetime.datetime.strptime(value, ‘%Y-%m-%d’).date()
except ValueError:
# Support European format
res = datetime.datetime.strptime(value, ‘%d.%m.%Y’).date()
else:
res = None
This way, both formats (YYYY-MM-DD
and DD.MM.YYYY
) are supported during import.
I hope this can help others who encounter the same issue when importing CSV data into Tryton.