You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
File "/home/interpod/Development/odoo/13.0/odoo/addons/base/models/ir_actions.py", line 171, in _compute_search_view
fvg = self.env[act.res_model].fields_view_get(act.search_view_id.id, 'search')
File "/home/interpod/Development/odoo/13.0/odoo/api.py", line 463, in __getitem__
return self.registry[model_name]._browse(self, (), ())
File "/home/interpod/Development/odoo/13.0/odoo/modules/registry.py", line 177, in __getitem__
return self.models[model_name]
KeyError: 'audit.log'
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.
The text was updated successfully, but these errors were encountered:
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 . importmodelsfromodooimportapi, SUPERUSER_IDimportlogging_logger=logging.getLogger(__name__)
defuninstall_hook(cr, registry):
# Delete actions linked to audit.log modelcr.execute(""" DELETE FROM ir_act_window where res_model='audit.log' RETURNING id """)
deleted_action_ids= [r[0] forrincr.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 sefeguardtry:
rules=self.sudo().search([
'|',
('group_id', '=', False),
('group_id', 'in', group_ids),
])
return {rule.model_id.model:
{method.replace('_', ''): rule.idformethodinself._methodsifgetattr(rule, 'log_%s'%method.replace('_', ''))}
forruleinrules}
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.
The text was updated successfully, but these errors were encountered: