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 @@ ...@@ -50,7 +50,7 @@
) )
return xmlid_cache[xmlid] 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( imf_ids = imf.search(
[("model", "=", model), ("name", "=", field_name)] [("model", "=", model), ("name", "=", field_name)]
) )
...@@ -54,8 +54,8 @@ ...@@ -54,8 +54,8 @@
imf_ids = imf.search( imf_ids = imf.search(
[("model", "=", model), ("name", "=", field_name)] [("model", "=", model), ("name", "=", field_name)]
) )
return imf.browse(imf_ids)[0].ttype return imf.browse(imf_ids)[0]
def _convert_identity(value): def _convert_identity(value):
return value return value
...@@ -58,7 +58,10 @@ ...@@ -58,7 +58,10 @@
def _convert_identity(value): def _convert_identity(value):
return value return value
def _convert_identity_nullable(value):
return value if value else None
def _convert_bool(value) -> bool: def _convert_bool(value) -> bool:
return value in (1, "1", "True", "true", True) return value in (1, "1", "True", "true", True)
...@@ -68,7 +71,7 @@ ...@@ -68,7 +71,7 @@
def _convert_float(value) -> float: def _convert_float(value) -> float:
return float(value) return float(value)
def _convert_many2one(xmlid: str) -> int: def _convert_many2one(xmlid: str) -> Union[None, int]:
if xmlid: if xmlid:
return _ref(xmlid) return _ref(xmlid)
return None return None
...@@ -106,8 +109,9 @@ ...@@ -106,8 +109,9 @@
): ):
odoo_field_name = column_name[:-3] odoo_field_name = column_name[:-3]
if odoo_field_name != "id": if odoo_field_name != "id":
ttype = _get_ttype(model, odoo_field_name) field = _get_imf(model, odoo_field_name)
_logger.debug( ttype = field.ttype
_logger.info(
"%s.%s type is %s", "%s.%s type is %s",
model, model,
odoo_field_name, odoo_field_name,
...@@ -121,7 +125,10 @@ ...@@ -121,7 +125,10 @@
"selection", "selection",
"date", "date",
): ):
converter = _convert_identity if field.required:
converter = _convert_identity
else:
converter = _convert_identity_nullable
elif ttype in ("many2one",): elif ttype in ("many2one",):
converter = _convert_many2one converter = _convert_many2one
elif ttype in ("many2many",): 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