Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
11972 Lượt xem

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.


Ảnh đại diện
Huỷ bỏ

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

 

Câu trả lời hay nhất
 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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 23
3169
0
thg 11 21
2265
4
thg 10 21
79879
0
thg 4 21
5358
1
thg 12 19
3599