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

:pencil: use null when importing empty string on a field with required=False

It looks like it is what the odoo import does, without that, there is no way to differentiate null and the empty string
parent e1b1329e6de1
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@
)
return xmlid_cache[xmlid]
def _get_ttype(model: str, field_name: str) -> str:
def _get_imf(model: str, field_name: str):
imf_ids = imf.search(
[("model", "=", model), ("name", "=", field_name)]
)
......@@ -54,8 +54,8 @@
imf_ids = imf.search(
[("model", "=", model), ("name", "=", field_name)]
)
return imf.browse(imf_ids)[0].ttype
return imf.browse(imf_ids)[0]
def _convert_identity(value):
return value
......@@ -58,7 +58,10 @@
def _convert_identity(value):
return value
def _convert_identity_nullable(value):
return value if value else None
def _convert_bool(value) -> bool:
return value in (1, "1", "True", "true", True)
......@@ -68,7 +71,7 @@
def _convert_float(value) -> float:
return float(value)
def _convert_many2one(xmlid: str) -> int:
def _convert_many2one(xmlid: str) -> Union[None, int]:
if xmlid:
return _ref(xmlid)
return None
......@@ -106,8 +109,9 @@
):
odoo_field_name = column_name[:-3]
if odoo_field_name != "id":
ttype = _get_ttype(model, odoo_field_name)
_logger.debug(
field = _get_imf(model, odoo_field_name)
ttype = field.ttype
_logger.info(
"%s.%s type is %s",
model,
odoo_field_name,
......@@ -121,7 +125,10 @@
"selection",
"date",
):
converter = _convert_identity
if field.required:
converter = _convert_identity
else:
converter = _convert_identity_nullable
elif ttype in ("many2one",):
converter = _convert_many2one
elif ttype in ("many2many",):
......
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