summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorJulien Castiaux <juc@odoo.com>2020-05-27 09:21:38 +0000
committerRaphael Collet <rco@odoo.com>2020-06-22 16:05:56 +0000
commit5d5a3d7fa455a93d89688cfb613afeb97f0073d5 (patch)
tree9cb08de23263ca58a3d649491a42dbf90d317dfe /odoo
parent8d75b794c49e6c05bbb70c5ba19636f576950894 (diff)
[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>
Diffstat (limited to 'odoo')
-rw-r--r--odoo/addons/base/models/ir_model.py11
-rw-r--r--odoo/models.py3
2 files changed, 13 insertions, 1 deletions
diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py
index 37acf600cae..85bf6f97c05 100644
--- a/odoo/addons/base/models/ir_model.py
+++ b/odoo/addons/base/models/ir_model.py
@@ -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})
diff --git a/odoo/models.py b/odoo/models.py
index 0a84b260c4e..42b1344e2e4 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -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