Skip to Content
Menú
This question has been flagged
3 Respostes
14130 Vistes

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

Avatar
Descartar
Best Answer

Hi,

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

@api.one
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


Avatar
Descartar
Autor

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.... :(

Autor Best Answer

SOLVED!


In order to work, I need to give default value for is_manager (boolean field) , I set the default as False and its work well :D


Thank you Community :D

Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de set. 15
4150
1
de juny 24
4727
3
de gen. 24
13319
3
de des. 21
15627
23
d’abr. 23
48124