[FIX] models: move wrongly forward-ported code to model ir.model.fields

This commit is contained in:
Raphael Collet
2017-04-28 11:49:14 +02:00
parent f265359187
commit 26bfc119b7
2 changed files with 10 additions and 9 deletions
+10
View File
@@ -784,6 +784,16 @@ class IrModelFields(models.Model):
for field in model._fields.itervalues():
self._reflect_field(field)
if not self.pool._init:
# remove ir.model.fields that are not in self._fields
fields_data = self._existing_field_data(model._name)
extra_names = set(fields_data) - set(model._fields)
if extra_names:
# add key MODULE_UNINSTALL_FLAG in context to (1) force the
# removal of the fields and (2) not reload the registry
records = self.browse([fields_data.pop(name)['id'] for name in extra_names])
records.with_context(**{MODULE_UNINSTALL_FLAG: True}).unlink()
def _instanciate_attrs(self, field_data, partial):
""" Return the parameters for a field instance for ``field_data``. """
attrs = {
-9
View File
@@ -266,15 +266,6 @@ class BaseModel(object):
self.env['ir.model']._reflect_model(self)
self.env['ir.model.fields']._reflect_model(self)
self.env['ir.model.constraint']._reflect_model(self)
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