Skip to content
Snippets Groups Projects
Commit 400d8adfacf5 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:pencil: import_jsonrpc: enforce ISO format on date and datetime to avoid potential...

:pencil: import_jsonrpc: enforce ISO format on date and datetime to avoid potential errors with unwanted format due to DB configuration
parent c98cb70554aa
No related branches found
No related tags found
No related merge requests found
......@@ -154,7 +154,6 @@
Import CSV files into an odoo.
import_base_import uses odoo base_import module to import the CSV file.
import_jsonrpc uses jsonrpc calls to import the files.
......@@ -162,6 +161,8 @@
- selection fields must use the technical value, not the displayed value or one of its translation.
- many2one and many2many fields must use the xmlid of the field they are referencing, with the column name in the form field_name/id or field_name:id.
- one2many fields in the same file are not supported for now,
- date and datetime must be in ISO format.
setup.cfg
=========
......
......@@ -7,6 +7,7 @@
import sys
from typing import Callable, Dict, List, Tuple, Union
from dateutil.parser import isoparse
from odoorpc.error import RPCError
from . import logging_from_verbose, odoo_connect_parser, odoo_login
......@@ -63,6 +64,22 @@
def _convert_identity(value):
return value
def _convert_date(value):
# depending on postgres configuration, other format are sometimes
# accepted. To be sure the value is as expected, only ISO format date
# are accepted.
try:
isoparse(value)
except ValueError:
_logger.fatal("Invalid date/datetime value %s", value)
raise
return value
def _convert_date_nullable(value):
if value:
return _convert_date(value)
return None
def _convert_identity_nullable(value):
return value if value else None
......@@ -89,6 +106,7 @@
else [(5, 0, 0)]
)
o.env.context["tz"] = ""
for model, csv_file, lang in model_filenames:
_logger.info(
"Importing - %s in model %s (lang %s)", csv_file, model, lang
......@@ -128,10 +146,9 @@
"char",
"text",
"selection",
"date",
"html",
):
if field.required:
converter = _convert_identity
else:
converter = _convert_identity_nullable
......@@ -132,9 +149,17 @@
"html",
):
if field.required:
converter = _convert_identity
else:
converter = _convert_identity_nullable
elif ttype in (
"date",
"datetime",
):
if field.required:
converter = _convert_date
else:
converter = _convert_date_nullable
elif ttype in ("many2one",):
converter = _convert_many2one
elif ttype in ("many2many",):
......
......@@ -14,6 +14,7 @@
install_requires=[
"odoorpc==0.7.0",
"requests_toolbelt==0.8.0",
"python-dateutil",
# How to indicate to install python3-docker?
],
entry_points={
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment