Skip to content

Commit

Permalink
pattern_import_export: allow to reference fk with multiple cols
Browse files Browse the repository at this point in the history
  • Loading branch information
hparfr committed Apr 14, 2023
1 parent addaaf0 commit 6fea527
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pattern_import_export/models/ir_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,30 @@ def _str_to_many2many(self, model, field, value):
def _str_to_many2one(self, model, field, value):
if isinstance(value, dict):
# odoo expect a list with one item
value = [value]
if len(value) == 1:
one_value = [value]
return super()._str_to_many2one(model, field, one_value)
else:
domain = model._convert_value_to_domain(None, value)
tosearch = field._related_comodel_name
record = self.env[tosearch].search(domain)
if len(record) > 1:
# TODO improve here
raise self._format_import_error(
ValueError,
_("%s Too many records found for %s in field '%s'"),
(_(record._description), domain, tosearch),
)
if len(record) == 0:
raise self._format_import_error(
ValueError,
_("%s No matching record found for %s in field '%s'"),
(_(record._description), domain, tosearch),
)

# call core function to be sure not to miss something
an_id, donotcare, w2 = self.db_id_for(model, field, ".id", record.id)
return an_id, [] + w2
return super()._str_to_many2one(model, field, value)

@api.model
Expand Down

0 comments on commit 6fea527

Please sign in to comment.