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

Question: I'm encountering issues while trying to use conditional statements (t-if, invisible) in my XML view based on the status field defined in the Python file. Despite trying multiple approaches, including t-if and invisible, the button visibility doesn't change as expected based on the status field.


status = fields.Selection(
    string="Status",
    selection=[('draft', 'Draft'), ('pending_approval', 'Pending Approval'), ...],
    default='draft'
)




Issue Description:

  • status field is properly defined in the Python file.
  • Attempts to use t-if, invisible, and other methods based on the status field haven't yielded the expected outcome in the view.
  • Seeking guidance on the correct way to conditionally show/hide buttons based on the value of the status field.


Avatar
Discard

Hi, in odoo 17 attrs are no more used. 
so here is an example of hiding a button based on states. 

 

Best Answer
 HI  Technology Pill Business Solution, 


After seeing your code we understood that , you want to make button invisible into xml view side.

So here it is a code ,

button name = “action_send_approval”

string = “Send To Approval 1”

type = “object”

class= “oe_highlight”

            Invisible = “status != ‘draft’ ”

/>

#This Button is only display in draft status.

  I hope this is helpful to you.


Thanks & Regards,

 Email: odoo@devintellecs.com

 Skype: devintelle

Avatar
Discard
Best Answer

Hi

Try this:

<button name="action_send_approval" string="Send to Approval 1" invisible="state in ['draft']" type="object" class="oe_highlight"/>


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 23
2531
0
Nov 21
1847
4
Oct 21
78980
0
Apr 21
4968
1
Dec 19
3284