Odoo Help

Welcome!

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.

0

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

By
nasim
on 7/17/16, 12:10 AM 207 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.


0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


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

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

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

nasim
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

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

nasim
on 7/23/16, 3:34 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)

Stats

Asked: 7/17/16, 12:10 AM
Seen: 207 times
Last updated: 7/21/16, 3:59 AM