[FIX] module deinstallation: do not prevent ir.model.field deletion

Some code prevents to modify or delete an `ir.model.field` if another field
depends on it (like one2many depending on many2one).  Make a special case when
the code is executed during a module deinstallation.

OPW 694009
This commit is contained in:
Raphael Collet
2016-12-16 17:09:28 +01:00
parent e91a8d428f
commit 1cfbbfafb8
+6
View File
@@ -435,6 +435,12 @@ class IrModelFields(models.Model):
model = self.env[record.model]
field = model._fields[record.name]
if field.type == 'many2one' and model._field_inverses.get(field):
if self._context.get(MODULE_UNINSTALL_FLAG):
# automatically unlink the corresponding one2many field(s)
inverses = self.search([('relation', '=', field.model_name),
('relation_field', '=', field.name)])
inverses.unlink()
continue
msg = _("The field '%s' cannot be removed because the field '%s' depends on it.")
raise UserError(msg % (field, model._field_inverses[field][0]))