Skip to Content
Menu
This question has been flagged
8 Replies
3829 Views

hi

(odoo11)

I have a "state" field and some button on it. I want a button invisible  in a specific state .

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

@api.depends('parent_id')
def _compute_is_valid(self):
for order in self:
order.is_valid = False
if order.parent_id.user_id.id == self.env.uid:
order.is_valid = True
else:
order.is_valid = False
parent_id = fields.Many2one('hr.employee', 'Manager', readonly=True)
state = fields.Selection([('draft', 'Draft'), ('manager_approve','Manager Approved'),
('validate_special_access','Validate Special Access'), ('support_team_approve','Support Agent Validated'),
('support_manager_done','Support Manager Validated/Done'),('cancel', 'Cancelled')],
'Status', track_visibility=True, required=True,
copy=False, default='draft')
is_valid = fields.Boolean(compute="_compute_is_valid")
in xml :
<button name="action_validate_special_access" attrs="{'invisible': [('is_valid','=',True)]}" groups="support_services.group_sspecial_manager" states="manager_approve" string="Validate Special Access" type="object"/>
(attrs="{'invisible': [('is_valid','=',True)]}")
the "is_valid" field automaticaly compute ,
but this "invisible attr" only work when I change "parent_id" manualy.then the button "Validate Special Access" visible or invisible
what is problem? it is related to @api in my function? or what?
thanks
Avatar
Discard

Hi,

If you need to make a button on specific states then use states="the states which you need the button visible"

for eg: <button name="action_invoice_cancel" states="draft,open"/> , here the button will visible on the states draft and open

Best Answer

The states attribute and attrs are incompatible.


Thanks

iWesabe

Avatar
Discard
Best Answer

if you need to compute your valid field whenever the view loaded, then remove @api.depends('parent_id').

If you out depends decorator for a compute function,
then this will compute only when any changes triggerd for the specified 
field inside decorator.
Avatar
Discard
Author

thanks

but my valid field compute whenever the view loaded. my problem is that the button don't invisible base on this field!

(of course I set other condition's for invisible this button and those conditions didn't work either.for example: base on other fields)

:(

have you removed depends decorator?

Author

yes!

Author

I solved it :)

It seemed like there was a conflict on states="manager_approve" and attrs="{'invisible...

I delete states="manager_approve", and then write this:

<button name="action_validate_special_access" attrs="{'invisible': ['|','|','|',('is_valid','=',True),('state','=','validate_special_access'),('state','=','support_team_approve'),('state','=','support_manager_done')]}" groups="support_services.group_sspecial_manager" string="Validate Special Access" type="object"/>

and work fine!! :)

of course I don't know if this way is standard or not?! :(