From 6a1b2ff7be161077068b91c9b657a7a3cb19697a Mon Sep 17 00:00:00 2001 From: Archana Vaghasiya Date: Fri, 3 Mar 2023 13:05:28 +0000 Subject: [PATCH] [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) --- addons/base_import/models/base_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base_import/models/base_import.py b/addons/base_import/models/base_import.py index 162fc8c678c..8d85266ed60 100644 --- a/addons/base_import/models/base_import.py +++ b/addons/base_import/models/base_import.py @@ -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