Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
10604 Vistas

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
Descartar

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

 

Mejor respuesta
 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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
ago 23
2532
0
nov 21
1849
4
oct 21
78981
0
abr 21
4969
1
dic 19
3284