Skip to content

Instantly share code, notes, and snippets.

@josemoralesp
Created July 31, 2017 16:33
Show Gist options
  • Save josemoralesp/93e34332c6fa1496be60ea8bc31cd55e to your computer and use it in GitHub Desktop.
Save josemoralesp/93e34332c6fa1496be60ea8bc31cd55e to your computer and use it in GitHub Desktop.
# Available locals:
# - time, datetime, dateutil: Python libraries
# - env: Odoo Environement
# - model: Model of the record on which the action is triggered
# - object: Record on which the action is triggered if there is one, otherwise None
# - workflow: Workflow engine
# - Warning: Warning Exception to use with raise
# To return an action, assign: action = {...}
ids = []
for i in env['ir.model'].search([]):
try:
a = env[i.model]
except:
ids.append(i.id)
if ids:
cr.execute('DELETE FROM ir_model_relation WHERE model IN %s', (tuple(ids), ))
cr.execute('DELETE FROM ir_model_constraint WHERE model IN %s', (tuple(ids), ))
cr.execute('UPDATE hr_job SET alias_id=null WHERE alias_id IN (SELECT id FROM mail_alias WHERE alias_model_id IN %s )' % (tuple(ids),))
cr.execute('DELETE FROM ir_model WHERE id in %s', (tuple(ids),) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment