在 Odoo 中禁用基于条件的按钮?

Disable a button based on CONDITION in Odoo?

如何根据条件向字段添加禁用的 class 属性?

我尝试了以下方法,

1)

<t t-if="product.qty_available &lt;= 0">
    <attribute name="class">btn btn-primary btn-lg mt8 js_check_product a-submit disabled</attribute>
</t>

2)

<attribute name="class" t-if="product.qty_available &gt; 0">btn btn-primary btn-lg mt8 js_check_product a-submit disabled</attribute>

3)

<attribute name="class" >product.qty_available &gt; 0 and 'btn btn-primary btn-lg mt8 js_check_product a-submit' or 'btn btn-primary btn-lg mt8 js_check_product a-submit disabled'</attribute>

有人可以帮我实现这个目标吗?

试试这个:

<attribute name="t-att-disabled" > "1 if product.qty_available else 0" </attribute>

做了位置="replace"

<xpath expr="//a[@id='add_to_cart']" position="replace">
      <a id="add_to_cart" t-attf-class="btn btn-primary btn-lg mt8 js_check_product a-submit #{product.qty_available &lt;= 0 and 'disabled'}" href="#" >Add to Cart</a>
  </xpath>