[FIX] base: missing xmlid for mixin fields
We want to create a XMLID for every first exhibition of a field in a model. That is, we just want one XMLID by field by model and not one XMLID by field by class. Previous implementation was determining the "first field exhibition" by making sure the field was created and used as part of the same module. This assumption is invalid when we consider mixins. A mixin is an abstract model that define fields and methods to be included in other models. As it is abstract, it does not exhibits the field by itself. The field will only be exhibited when included in a concrete model via inheritance. When it is included in another module, the XMLID creation is discarded. Take a module M1 that defines a model A, take another module M2 that defines a mixin X with a field X1. In a third module M3, extend A to inherit from X. While M3.A is the first model module to exhibit the field X1, the XMLID creation was discarded because `"M2" != "M3"`. See https://github.com/odoo/odoo/issues/49354#issuecomment-614093767 Task: 2235368 Closes #49354 closes odoo/odoo#53435 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
committed by
Raphael Collet
parent
8d75b794c4
commit
5d5a3d7fa4
@@ -1044,7 +1044,16 @@ class IrModelFields(models.Model):
|
||||
for (field_model, field_name), field_id in field_ids.items():
|
||||
model = self.env[field_model]
|
||||
field = model._fields.get(field_name)
|
||||
if field and (module == model._original_module or module in field._modules):
|
||||
if field and (
|
||||
module == model._original_module
|
||||
or module in field._modules
|
||||
or any(
|
||||
# module introduced field on model by inheritance
|
||||
field_name in self.env[parent]._fields
|
||||
for parent, parent_module in model._inherit_module.items()
|
||||
if module == parent_module
|
||||
)
|
||||
):
|
||||
xml_id = field_xmlid(module, field_model, field_name)
|
||||
record = self.browse(field_id)
|
||||
data_list.append({'xml_id': xml_id, 'record': record})
|
||||
|
||||
@@ -514,6 +514,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
||||
'_name': name,
|
||||
'_register': False,
|
||||
'_original_module': cls._module,
|
||||
'_inherit_module': dict(), # map parent to introducing module
|
||||
'_inherit_children': OrderedSet(), # names of children models
|
||||
'_inherits_children': set(), # names of children models
|
||||
'_fields': OrderedDict(), # populated in _setup_base()
|
||||
@@ -532,7 +533,9 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
||||
else:
|
||||
check_parent(cls, parent_class)
|
||||
bases.add(parent_class)
|
||||
ModelClass._inherit_module[parent] = cls._module
|
||||
parent_class._inherit_children.add(name)
|
||||
|
||||
ModelClass.__bases__ = tuple(bases)
|
||||
|
||||
# determine the attributes of the model's class
|
||||
|
||||
Reference in New Issue
Block a user