Skip to Content
Menu
This question has been flagged

I want to override a function called 'user_has_groups'  in the class from the file openerp/models.py  (line no 1365),


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 says 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)

and now the error is

QWebException: <lambda>() got multiple values for keyword argument 'groups'

How I can achieve this? Please enlighten me.

Avatar
Discard

I've cleaned up your question since the code was a mess and full of '\' characters. Know that a nicely formatted question will get you more reactions :)

I suggest looking at the environment. Looks like an issue with the passing of the cr and uid. Perhaps you could try passing them to the my_user_has_groups explicitly. Something like: BaseModel.user_has_groups = my_user_has_groups(self, cr, uid, context=none) Either that or try converting the whole environment context to the new model. I am not entirely sure how to achieve this though. Refer to the ORM on api changes: The big differences between the old and new APIs are: values of the Environment (cursor, user id and context) are passed explicitly to methods instead

Author

@Yenthe.. thanks bro..

Author

@Mai Ecarde Thanks for the reply.. Now I tried this code BaseModel.user_has_groups = lambda cr, uid, groups, context: my_user_has_groups(cr, uid, groups, context) But results the following error QWebException: () got multiple values for keyword argument 'groups'

Author Best Answer

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)

Avatar
Discard
Related Posts Replies Views Activity
5
Jun 17
4491
1
Jun 16
3281
1
Nov 20
1603
5
Jun 20
30119
0
Jan 17
3691