[FIX] odoo: Import data with falsy many2one fields

Steps to reproduce:

- Export a partner with country set to False, using EXCELL
- Try to import it with the xls file

Bug:

It raised: "No matching record found for name 'False' in field 'Country' at row 2"

opw:2080376

closes odoo/odoo#38379

X-original-commit: 01caf1e44f653a8e9bf5edd583bc2421905d9464
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Goffin Simon
2019-10-10 11:28:09 +00:00
committed by fw-bot
parent d77a8de5f9
commit f520ee8f7b
+6
View File
@@ -321,6 +321,8 @@ class IrFieldsConverter(models.AbstractModel):
RelatedModel = self.env[field.comodel_name]
if subfield == '.id':
field_type = _(u"database id")
if isinstance(value, str) and not self._str_to_boolean(model, field, value)[0]:
return False, field_type, warnings
try: tentative_id = int(value)
except ValueError: tentative_id = value
try:
@@ -335,6 +337,8 @@ class IrFieldsConverter(models.AbstractModel):
{'moreinfo': action})
elif subfield == 'id':
field_type = _(u"external id")
if not self._str_to_boolean(model, field, value)[0]:
return False, field_type, warnings
if '.' in value:
xmlid = value
else:
@@ -343,6 +347,8 @@ class IrFieldsConverter(models.AbstractModel):
id = self.env['ir.model.data'].xmlid_to_res_id(xmlid, raise_if_not_found=False) or None
elif subfield is None:
field_type = _(u"name")
if value == '':
return False, field_type, warnings
flush()
ids = RelatedModel.name_search(name=value, operator='=')
if ids: