diff --git a/auditlog/__init__.py b/auditlog/__init__.py index 81ad0d90e..15e9ca739 100644 --- a/auditlog/__init__.py +++ b/auditlog/__init__.py @@ -20,3 +20,17 @@ ############################################################################## from . import models + + +def pre_init_hook(cr): + cr.execute("SELECT 1 FROM pg_class WHERE relname = 'audittrail_rule'") + if cr.fetchall(): + migrate_from_audittrail(cr) + + +def migrate_from_audittrail(cr): + cr.execute('ALTER TABLE audittrail_rule RENAME TO auditlog_rule') + cr.execute('ALTER TABLE auditlog_rule RENAME COLUMN object_id TO model_id') + cr.execute('ALTER TABLE audittrail_log RENAME TO auditlog_log') + cr.execute('ALTER TABLE auditlog_log RENAME COLUMN object_id TO model_id') + cr.execute('ALTER TABLE audittrail_log_line RENAME TO auditlog_log_line') diff --git a/auditlog/__openerp__.py b/auditlog/__openerp__.py index 8283c36dc..ecfe0a28f 100644 --- a/auditlog/__openerp__.py +++ b/auditlog/__openerp__.py @@ -35,4 +35,5 @@ 'application': True, 'installable': True, 'active': False, + 'pre_init_hook': 'pre_init_hook', } diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index 338eb7f47..56c8ebc5c 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -123,6 +123,9 @@ class auditlog_rule(models.Model): for rule in self: if rule.state != 'subscribed': continue + if not self.pool.get(rule.model_id.model): + # ignore rules for models not loadable currently + continue model_model = self.env[rule.model_id.model] # CRUD # -> create