我想从文件openerp / models.py(第1365行)覆盖类中名为'user_has_groups'的函数
中的代码from openerp.models import BaseModel
def my_user_has_groups(self, cr, uid, groups, context=None):
#my code
BaseModel.user_has_groups = my_user_has_groups
但是会导致以下错误。
TypeError: my_user_has_groups() takes at least 4 arguments (2 given)
我也试过这行
BaseModel.user_has_groups = lambda cr, uid, groups, context: my_user_has_groups(cr, uid, groups, context)
导致以下错误
QWebException: <lambda>() got multiple values for keyword argument 'groups'
我还尝试了this post的代码。但它不起作用。
我怎么能做到这一点?请赐教。
答案 0 :(得分:2)
我用另一种方式解决了这个问题,见下文
from openerp import models, api
class BaseModelExtend(models.AbstractModel):
_name = 'basemodel.extend'
def _register_hook(self, cr):
@api.cr_uid_context
def user_has_groups(self, cr, uid, groups, context=None):
#My code
models.BaseModel.user_has_groups = user_has_groups
return super(BaseModelExtend, self)._register_hook(cr)
答案 1 :(得分:1)
from openerp.models import BaseModel,api
@api.guess
def my_user_has_groups(self, cr, uid, groups, context=None):
# your code
BaseModel.user_has_groups = my_user_has_groups