Merge lp:~openerp-dev/openobject-server/7.0-uninstall-module-constraint-mat into lp:openobject-server/7.0

Proposed by Martin Trigaux (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/7.0-uninstall-module-constraint-mat
Merge into: lp:openobject-server/7.0
Diff against target: 43 lines (+10/-7)
2 files modified
openerp/addons/base/ir/ir_model.py (+10/-3)
openerp/addons/base/module/module.py (+0/-4)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-uninstall-module-constraint-mat
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Pending
Review via email: mp+213245@code.launchpad.net

Description of the change

When uninstalling a module, remove the ir.model.constraint after removing the non-model records and before fields and model definition

To post a comment you must log in.

Unmerged revisions

5268. By Martin Trigaux (OpenERP)

[FIX] uninstall: when uninstalling a module, remove the ir.model.constraint after removing the non-model records and before fields and model definition

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/ir/ir_model.py'
2--- openerp/addons/base/ir/ir_model.py 2014-02-24 16:19:18 +0000
3+++ openerp/addons/base/ir/ir_model.py 2014-03-28 12:26:38 +0000
4@@ -1085,13 +1085,20 @@
5
6 # Remove non-model records first, then model fields, and finish with models
7 unlink_if_refcount((model, res_id) for model, res_id in to_unlink
8- if model not in ('ir.model','ir.model.fields'))
9+ if model not in ('ir.model','ir.model.fields','ir.model.constraint'))
10+ unlink_if_refcount((model, res_id) for model, res_id in to_unlink
11+ if model == 'ir.model.constraint')
12+
13+ ir_module_module = self.pool['ir.module.module']
14+ ir_model_constraint = self.pool['ir.model.constraint']
15+ modules_to_remove_ids = ir_module_module.search(cr, uid, [('name', 'in', modules_to_remove)], context=context)
16+ constraint_ids = ir_model_constraint.search(cr, uid, [('module', 'in', modules_to_remove_ids)], context=context)
17+ ir_model_constraint._module_data_uninstall(cr, uid, constraint_ids, context)
18+
19 unlink_if_refcount((model, res_id) for model, res_id in to_unlink
20 if model == 'ir.model.fields')
21
22 ir_model_relation = self.pool.get('ir.model.relation')
23- ir_module_module = self.pool.get('ir.module.module')
24- modules_to_remove_ids = ir_module_module.search(cr, uid, [('name', 'in', modules_to_remove)])
25 relation_ids = ir_model_relation.search(cr, uid, [('module', 'in', modules_to_remove_ids)])
26 ir_model_relation._module_data_uninstall(cr, uid, relation_ids, context)
27
28
29=== modified file 'openerp/addons/base/module/module.py'
30--- openerp/addons/base/module/module.py 2014-01-14 15:44:26 +0000
31+++ openerp/addons/base/module/module.py 2014-03-28 12:26:38 +0000
32@@ -432,11 +432,7 @@
33 including the deletion of all database structures created by the module:
34 tables, columns, constraints, etc."""
35 ir_model_data = self.pool.get('ir.model.data')
36- ir_model_constraint = self.pool.get('ir.model.constraint')
37 modules_to_remove = [m.name for m in self.browse(cr, uid, ids, context)]
38- modules_to_remove_ids = [m.id for m in self.browse(cr, uid, ids, context)]
39- constraint_ids = ir_model_constraint.search(cr, uid, [('module', 'in', modules_to_remove_ids)])
40- ir_model_constraint._module_data_uninstall(cr, uid, constraint_ids, context)
41 ir_model_data._module_data_uninstall(cr, uid, modules_to_remove, context)
42 self.write(cr, uid, ids, {'state': 'uninstalled'})
43 return True