Skip to Content
Menu
This question has been flagged
2 Replies
3196 Views

Hello, I have following code to make a button invisible on condition ; 

 "button name="button_validate" attrs="{'invisible': ['|', ('x', '=', True), ('show_validate', '=', False)]}" string="Validate" groups="stock.group_stock_user"

It works fine & for all users. However, I wish to override the invisible attribute only for certain group of user, say Account Advisor. Meaning the Account Advisors should see the button even if  'x', '=', True . I though to bring the "groups" within part of "attrs" condition but as far as I learned (maybe wrong), user group can not be part of a condition in "attrs", however that should be achievable with the "eval" (maybe wrong here too). 

I am not yet in Python coding & prefer to achieve this on XML only (if possible). 

I really appreciate any help or advise. 

Thanks very much

Avatar
Discard
Best Answer

Hi,


I Think you should create a new computed field and use it in the invisible attrs.


The computed field should look like :

hide_validate = field.Boolean(compute='_compute_can_see')


The compute method :

def _compute_can_see(self):
for rec in self
rec.hide_validate = not(self.env.user.has_group(the xmlid of your group))

And finally your view, first your need to add the computed field to the view




attrs="{'invisible': [
'|',
,'&', ('x', '=', True),('hide_validate', '=', True),

'&',
('show_validate', '=', False),
('hide_validate', '=', True)
]}"

Avatar
Discard
Author Best Answer

Hi Gustave, 

Thanks a lot for helping. I think I see your approach & will try it soon. Just need to study it a bit since I am fairly new on odoo/XML. 

Thanks again, will surely post my result here. 

Avatar
Discard