From 700fe1e039bfe17c62380b06721deeb5d8c03d1d Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Sat, 2 Jan 2016 19:19:54 +0100 Subject: [PATCH] [FIX] API compatibility of monkeypatched method [IMP] Make _register_hook idempotent as we have to call it in tests --- .../models/basemodel_monkeypatch.py | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/base_technical_features/models/basemodel_monkeypatch.py b/base_technical_features/models/basemodel_monkeypatch.py index 62f4c2661..9cc0bfd17 100644 --- a/base_technical_features/models/basemodel_monkeypatch.py +++ b/base_technical_features/models/basemodel_monkeypatch.py @@ -1,26 +1,31 @@ # -*- coding: utf-8 -*- -from openerp import models +from openerp import models, api class BaseModelMonkeyPatch(models.AbstractModel): _name = 'basemodel.monkeypatch' def _register_hook(self, cr): - models.BaseModel.base_technical_features_user_has_groups = ( - models.BaseModel.user_has_groups) + if not hasattr( + models.BaseModel, 'base_technical_features_user_has_groups'): - def user_has_groups(self, cr, uid, groups, context=None): - """ Return True for users in the technical features group when - membership of the original group is checked, even if debug mode is - not enabled. - """ - if ('base.group_no_one' in groups.split(',') and - self.pool['res.users'].has_group( - cr, uid, - 'base_technical_features.group_technical_features')): - return True - return self.base_technical_features_user_has_groups( - cr, uid, groups, context=context) + models.BaseModel.base_technical_features_user_has_groups = ( + models.BaseModel.user_has_groups) + + @api.cr_uid_context + def user_has_groups(self, cr, uid, groups, context=None): + """ Return True for users in the technical features group when + membership of the original group is checked, even if debug mode + is not enabled. + """ + if ('base.group_no_one' in groups.split(',') and + self.pool['res.users'].has_group( + cr, uid, + 'base_technical_features.group_technical_features')): + return True + return self.base_technical_features_user_has_groups( + cr, uid, groups, context=context) + + models.BaseModel.user_has_groups = user_has_groups - models.BaseModel.user_has_groups = user_has_groups return super(BaseModelMonkeyPatch, self)._register_hook(cr)