I want to override a function called 'user_has_groups' in the class from the file openerp/models.py (line no 1365)
I tried the code from this post and this question
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
But it results the following error.
TypeError: my_user_has_groups() takes at least 4 arguments (2 given)
and also i tried this line
BaseModel.user_has_groups = lambda cr, uid, groups, context: my_user_has_groups(cr, uid, groups, context)
It results the following error
QWebException: <lambda>() got multiple values for keyword argument 'groups'
I also tried the code from this post. But it doesn't work.
How I can achieve this? Please enlighten me.
I solved this in another way around, which is given below
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)
JeyChou
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
来源:https://stackoverflow.com/questions/34725611/how-to-override-method-of-basemodel-openerp-models-py-in-odoo-v9