From 2be8bdd0b35deea380b1ce30c53fc51926dc404e Mon Sep 17 00:00:00 2001 From: sebalix Date: Mon, 14 Nov 2016 15:12:24 +0100 Subject: [PATCH] auditlog - Migrate 'AuditlogRule.create' and 'AuditlogRule.write' methods to the new API --- auditlog/models/rule.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index 8e0b01abf..482358edb 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -171,25 +171,22 @@ class AuditlogRule(models.Model): modules.registry.RegistryManager.signal_registry_change( self.env.cr.dbname) - # Unable to find a way to declare the `create` method with the new API, - # errors occurs with the `_register_hook()` BaseModel method. - def create(self, cr, uid, vals, context=None): + @api.model + def create(self, vals): """Update the registry when a new rule is created.""" - res_id = super(AuditlogRule, self).create( - cr, uid, vals, context=context) - if self._register_hook(cr, [res_id]): - modules.registry.RegistryManager.signal_registry_change(cr.dbname) - return res_id - - # Unable to find a way to declare the `write` method with the new API, - # errors occurs with the `_register_hook()` BaseModel method. - def write(self, cr, uid, ids, vals, context=None): + new_record = super(AuditlogRule, self).create(vals) + if self._model._register_hook(self.env.cr, new_record.ids): + modules.registry.RegistryManager.signal_registry_change( + self.env.cr.dbname) + return new_record + + @api.multi + def write(self, vals): """Update the registry when existing rules are updated.""" - if isinstance(ids, (int, long)): - ids = [ids] - super(AuditlogRule, self).write(cr, uid, ids, vals, context=context) - if self._register_hook(cr, ids): - modules.registry.RegistryManager.signal_registry_change(cr.dbname) + super(AuditlogRule, self).write(vals) + if self._model._register_hook(self.env.cr, self.ids): + modules.registry.RegistryManager.signal_registry_change( + self.env.cr.dbname) return True @api.multi