Odoo Help


how can set permission for a button in a form of a module?

on 7/17/16, 12:10 AM 546 views

I want set a permission for a button in a form of a module. this button defined in xml file of module view with this code:

<button name="tender_validate_special_access" groups="internal_services.group_internal_services_special_access_validator" states="manager_approve" string="Validate Special Access" type="object" icon="gtk-jump-to" />


but I want say when form state is != darft and department_second_id.manager_id.user_id = user.id , this button for example show "readonly" or "invisible" format.

I type a attr for button in this case:

attrs="{'readonly': ['&',('state','!=','draft'),('department_second_id.manager_id.user_id','!=',user.id)]}"


( department_second_idis a many2one field in this module from hr module and use in this form. user.id is current user(login user))

but does not work!

I dont know what is problem?


if I type this code:

attrs="{'readonly': [('state','!=',' draft ')]}"

it is work well.

--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 7/17/16, 2:59 AM


I think I it wn't work, because in some cases you can't access filed with dot notation in the domain the simple workaround

you can make a functional [computed] "invisible" field with type boolean then then you can make the calculations if the  

it will return true otherwise false

then change your domain to:

attrs="{'readonly': ['&',('state','!=','draft'),('new_computed_fields','!=',True)]}"

Hope this could helps ...

thank for your help

I read this page for user your solution:


but in my code when I use :




this error display:


NameError: name 'api' is not defined


I serach and understand that I have write "from openerp import api" in my .py file.

but again I see this error:

from openerp import api

ImportError: cannot import name api


my openerp version is 6.1

you think in this version I shoud use other code?

thanks so much

on 7/21/16, 3:54 AM

Hi, Yes you can't use api in v6.1 you can just use old API pattern in v6.1

Ahmed M.Elmubarak
on 7/23/16, 2:47 AM


but how? :(


now my code is this:

_columns = {

'check_button': fields.boolean(compute='_get_value'),


def _get_value(self):

if self.department_second_id.manager_id.user_id == user.id:

self.check_button = True


self.check_button = False


but the field "check_button" is alwayse :False

It seems that any time 'if self.department_second_id.manager_id.user_id == user.id:' does not work or not called.

I don not know what is problem!

so sorry! ... :(

on 7/23/16, 3:34 AM

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: 7/17/16, 12:10 AM
Seen: 546 times
Last updated: 7/21/16, 3:59 AM