From d84b5c4c499d2c926cf868df83fa3f6895ee715d Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 14 Mar 2017 17:42:08 +0100 Subject: [PATCH] [FIX] base: unlinking ir.model.constraint When unlinking an ir.model, all the ir.model.constraint linked to this ir.model must be removed to avoid to call unexisting model. The ir.model.constraint records, are created with module = the module where the related field has been declared. But when unlinking the ir.model in function _module_data_uninstall, the related ir.model.constraint to remove were chosen according to the removed modules. So with models declaring constraints on inherited fields, some problems occured because the model could be removed and not all the related constraints. opw:716032 --- odoo/addons/base/ir/ir_model.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/odoo/addons/base/ir/ir_model.py b/odoo/addons/base/ir/ir_model.py index 9cd07f64386..90ac8d794c8 100644 --- a/odoo/addons/base/ir/ir_model.py +++ b/odoo/addons/base/ir/ir_model.py @@ -167,9 +167,6 @@ class IrModel(models.Model): # prevent screwing up fields that depend on these models' fields model.field_id._prepare_update() - imc = self.env['ir.model.constraint'].search([('model', 'in', self.ids)]) - imc.unlink() - self._drop_table() res = super(IrModel, self).unlink() @@ -811,7 +808,7 @@ class IrModelConstraint(models.Model): name = fields.Char(string='Constraint', required=True, index=True, help="PostgreSQL constraint or foreign key name.") definition = fields.Char(help="PostgreSQL constraint definition") - model = fields.Many2one('ir.model', required=True, index=True) + model = fields.Many2one('ir.model', required=True, ondelete="cascade", index=True) module = fields.Many2one('ir.module.module', required=True, index=True) type = fields.Char(string='Constraint Type', required=True, size=1, index=True, help="Type of the constraint: `f` for a foreign key, "