Odoo Help


This community 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.


Make Read only field based on current user groups (self.user.has_group not working)

Prihadi Ramadhany
on 10/3/16, 1:42 AM 120 views

Hi community,

In my form (Odoo v9c) , I need several fields to be Read only based on the user group that currently login.  So, I create a function field to hold a boolean value if the current user is a member of base.group_sale_manager or not.

'is_manager' : fields.boolean(compute="_check_user_group")  

and the function is below

def _check_user_group(self):

    is_manager = False

    if self.user.has_group('base.group_sale_manager'):

        is_manager = True

and on XML I use:

     attrs="{'readonly':[('is_manager', '=', False)]}"

 (and I tried also attrs="{'readonly':[('is_manager', '==', False)]}" and attrs="{'readonly':[('is_manager', '=', 'False')]}" and attrs="{'readonly':[('is_manager', '==', 'False')]}")

Apparently is_manager always have False value (so the field always in read only mode) regardless user is in group of base.group_sale_manager or not.

Do I missed anything here?  Any help will be appreciated.

Thank you community :D

Bejaoui Souheil
On 10/3/16, 3:35 AM


First, you have to return the result on the model field:

def _check_user_group(self):
    self.is_manager = self.user.has_group('base.group_sale_manager')

And for attrs use this

attrs="{'readonly':[('is_manager', '=', False)]}"

Best regards

Hi Bejaoui,

Thank you for the reply, I modified the code accordingly , unfortunately the result still the same.... is_manager.self is always returned False. I double check the users group and they are good (one as salesman and one as sale manager).

I wonder what I missed here.... :(

Prihadi Ramadhany
on 10/3/16, 10:25 AM

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 10/3/16, 1:42 AM
Seen: 120 times
Last updated: 10/17/16, 9:36 AM