[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
This commit is contained in:
Anh Thao Pham (pta)
2020-07-31 14:44:58 +00:00
parent 9213cd3508
commit cea6cb7183
+8 -1
View File
@@ -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