Browse Source

[RFR] Only apply monkeypatching when the module is installed

pull/321/head
Stefan Rijnhart 9 years ago
parent
commit
ae3f4ef856
  1. 2
      base_technical_features/models/__init__.py
  2. 18
      base_technical_features/models/basemodel.py
  3. 26
      base_technical_features/models/basemodel_monkeypatch.py

2
base_technical_features/models/__init__.py

@ -1,2 +1,2 @@
from . import basemodel
from . import basemodel_monkeypatch
from . import ir_ui_menu

18
base_technical_features/models/basemodel.py

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
from openerp.models import BaseModel
BaseModel.base_technical_features_user_has_groups = BaseModel.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 this 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)
BaseModel.user_has_groups = user_has_groups

26
base_technical_features/models/basemodel_monkeypatch.py

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from openerp import models
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)
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
return super(BaseModelMonkeyPatch, self)._register_hook(cr)
Loading…
Cancel
Save