From cea6cb71832e0eea2ef0c721b53543fa82c1dbb2 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Wed, 22 Jul 2020 07:51:55 +0000 Subject: [PATCH] [FIX] base: fix create option of import for Many2one in One2many - Install Inventory - Create an excel file with the following values : -------------------------------------------------------------------------------------------------------------------------------------------------------- location_id | location_dest_id | Operation Type / database ID | Stock moves / product | Stock moves / unit of measure | Stock moves / name -------------------------------------------------------------------------------------------------------------------------------------------------------- Partner Locations/Vendors | WH/Stock | 1 | Non existent product | Units | Test -------------------------------------------------------------------------------------------------------------------------------------------------------- - Go to Inventory > Operations > Transfers and import the file - Check the "Create if doesn't exist" option for "Stock moves / Product" and click on "TEST" button Import fails because Product does not exist and is not created. "name_create_enabled_fields" is used in frontend to store which fields have to be created if they don't exist. The issue comes from the fact that the keys used in "name_create_enabled_fields" contain the full path to the related field (i.e. move_lines/product_id), but only the final field name is used when checking "name_create_enabled_fields" in the backend (i.e. product_id). The prefix from the keys in "name_create_enabled_fields" should be removed when parsing fields from One2many. opw-2282087 X-original-commit: fadce5c117e3a14ec659cf0accee85502214120d --- odoo/addons/base/models/ir_fields.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_fields.py b/odoo/addons/base/models/ir_fields.py index 116e4c9aaa6..ad0b00fe2cf 100644 --- a/odoo/addons/base/models/ir_fields.py +++ b/odoo/addons/base/models/ir_fields.py @@ -439,6 +439,13 @@ class IrFieldsConverter(models.AbstractModel): @api.model def _str_to_one2many(self, model, field, records): + name_create_enabled_fields = self._context.get('name_create_enabled_fields') or {} + prefix = field.name + '/' + relative_name_create_enabled_fields = { + k[len(prefix):]: v + for k, v in name_create_enabled_fields.items() + if k.startswith(prefix) + } commands = [] warnings = [] @@ -460,7 +467,7 @@ class IrFieldsConverter(models.AbstractModel): raise exception warnings.append(exception) - convert = self.for_model(self.env[field.comodel_name]) + convert = self.with_context(name_create_enabled_fields=relative_name_create_enabled_fields).for_model(self.env[field.comodel_name]) for record in records: id = None