Odoo Help


How to override method of BaseModel (openerp/models.py) in odoo v9 ?

on 1/11/16, 10:39 AM 794 views

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.

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

on 1/11/16, 12:28 PM

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

Mai Ecarde
on 1/11/16, 6:01 PM

@Yenthe.. thanks bro..

on 1/13/16, 6:10 AM

@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'

on 1/13/16, 6:14 AM
On 1/18/16, 7:26 AM

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


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)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 1/11/16, 10:39 AM
Seen: 794 times
Last updated: 1/18/16, 7:26 AM