[FIX] models: remove ir.model.fields that no longer exist in registry

This fixes the following issue.  Assume a custom field F is created on
`res.partner`.  This field will appear on `res.users` as an inherited field,
and will be reflected in `ir.model.fields` as a 'base' field.  When F is
removed from the parent model, it no longer appears on the child model in
registry, but remains in `ir.model.fields`.

The patch allows the proper removal of the no-longer-inherited field from
`ir.model.fields`.
This commit is contained in:
Raphael Collet
2017-04-26 15:11:07 +02:00
parent 831322bb92
commit 4287a70110
+9
View File
@@ -368,6 +368,15 @@ class BaseModel(object):
field_id = cr.fetchone()[0]
self._context['todo'].append((20, Fields.browse(field_id).modified, [names]))
if not self.pool._init:
# remove ir.model.fields that are not in self._fields
fields = Fields.browse([col['id']
for name, col in cols.iteritems()
if name not in self._fields])
# add key '_force_unlink' in context to (1) force the removal of the
# fields and (2) not reload the registry
fields.with_context(_force_unlink=True).unlink()
self.invalidate_cache()
@api.model