Closed ghost closed 3 years ago
To solve the Issue I added an uninstall hook to the module that cleans all the actions leftover from previous uninstallations in the modules init.py
from . import models
from odoo import api, SUPERUSER_ID
import logging
_logger = logging.getLogger(__name__)
def uninstall_hook(cr, registry):
# Delete actions linked to audit.log model
cr.execute("""
DELETE FROM ir_act_window where res_model='audit.log' RETURNING id
""")
deleted_action_ids = [r[0] for r in cr.fetchall()]
_logger.warning("The following actions have been deleted on 'smile_audit' module uninstallation: %s" % deleted_action_ids)
registered it in the manifest.py
'uninstall_hook': 'uninstall_hook'
And finally a more subtle version of #87 solution is in the audit_rule.py
@api.model
@tools.ormcache()
def _check_audit_rule(self, group_ids):
# During Uninstall this function is called after the audit.rule model
# has been deleted from the registry, so we put a sefeguard
try:
rules = self.sudo().search([
'|',
('group_id', '=', False),
('group_id', 'in', group_ids),
])
return {rule.model_id.model:
{method.replace('_', ''): rule.id
for method in self._methods
if getattr(rule, 'log_%s' % method.replace('_', ''))}
for rule in rules}
except:
return {}
After using #87 to uninstall I noticed that the models that had rules registered prior to uninstalling the module where still trying to check for audit rules, raising an exception in the process
For some reason the actions linked to the rules are left over after the installation and are referencing the audit.log model that no longer exists.