Skip to Content
Menu
This question has been flagged
1 Reply
4754 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.


Avatar
Discard
Best Answer

Hello,

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  

'department_second_id.manager_id.user_id','!=',user.id 
it will return true otherwise false

then change your domain to:

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

Hope this could helps ...

Avatar
Discard
Author

thank for your help

I read this page for user your solution:

https://www.odoo.com/forum/help-1/question/how-to-make-a-field-invisible-using-compute-field-based-on-a-condition-98226

but in my code when I use :

@api.one

@api.depends()

--------------------------

this error display:

@api.one

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

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

Author

Thanks.

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

else:

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