Browse Source

remove relations when purging models

avoid ''NoneType' object has no attribute 'exists'' error when purging models
fix my change guewen.baconnier@camptocamp.com-20140203103254-v1mzu2uib047xb9h, wrong lines replaced...
pull/1408/head
Guewen Baconnier 11 years ago
committed by Martin Trigaux
parent
commit
8f62ece151
  1. 13
      database_cleanup/model/purge_models.py

13
database_cleanup/model/purge_models.py

@ -51,6 +51,7 @@ class CleanupPurgeLineModel(orm.TransientModel):
model_pool = self.pool['ir.model']
attachment_pool = self.pool['ir.attachment']
constraint_pool = self.pool['ir.model.constraint']
fields_pool = self.pool['ir.model.fields']
local_context=(context or {}).copy()
local_context.update({
@ -68,14 +69,20 @@ class CleanupPurgeLineModel(orm.TransientModel):
attachment_ids = attachment_pool.search(
cr, uid, [('res_model', '=', line.name)], context=context)
if attachment_ids:
attachment_pool.write(
cr, uid, attachment_ids, {'res_model': False},
context=context)
cr.execute(
"UPDATE ir_attachment SET res_model = FALSE "
"WHERE id in %s",
(tuple(attachment_ids), ))
constraint_ids = constraint_pool.search(
cr, uid, [('model', '=', line.name)], context=context)
if constraint_ids:
constraint_pool.unlink(
cr, uid, constraint_ids, context=context)
relation_ids = fields_pool.search(
cr, uid, [('relation', '=', row[1])], context=context)
if relation_ids:
fields_pool.unlink(cr, uid, relation_ids,
context=local_context)
model_pool.unlink(cr, uid, [row[0]], context=local_context)
line.write({'purged': True})
cr.commit()

Loading…
Cancel
Save