[FIX] base_import: handle fallback values of relational fields when import data

Before this commit:
=====================
KeyError 'selection_values' that occur in base_import/_handle_fallback_values()
while importing a data file. If any field(s) is many2one or many2many and we
tried to import the value of that field(s) that is not created in the database.
In that case when we set the 'Prevent Import' option.
It will raise an error like KeyError: 'selection_values'.

After this commit:
=====================
Solved the issue when there is a many2one or many2many field(s) and the import
value of that field(s) which is not available in the database. also, the method
is only for the 'selection' field and 'boolean' field so the code works when
there is a selection field and their selection_values only.

sentry - 3958065223

closes odoo/odoo#115056

X-original-commit: 0ef930cd7598bd15227ff025d2662d4331f8e45b
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
This commit is contained in:
Archana Vaghasiya
2023-03-13 14:20:21 +01:00
parent ae8bf42ca6
commit 6a1b2ff7be
+1 -1
View File
@@ -1515,7 +1515,7 @@ class Import(models.TransientModel):
if fallback_values[field]['field_type'] == "boolean":
value = value if value.lower() in ('0', '1', 'true', 'false') else fallback_value
# Selection
elif value.lower() not in fallback_values[field]["selection_values"]:
elif fallback_values[field]['field_type'] == "selection" and value.lower() not in fallback_values[field]["selection_values"]:
value = fallback_value if fallback_value != 'skip' else None # don't set any value if we skip
input_file_data[record_index][column_index] = value