How to use ATTRS in odoo17 ?
- The can be used to dynamically change the value of the field.
- he attrs attribute is used within the XML views of Odoo modules to specify when a field should be visible, invisible, readonly, or required based on certain conditions.
- There are three attributes available.
- invisible
- required
- readonly
invisible :-
- This attribute is used to make a field invisible based on certain conditions..
required :-
- This attribute is used to make a field required based on certain conditions.
readonly :-
- This attribute is used to make a field read-only based on certain conditions.
Example :
1. invisible :-
<field name="card_number" invisible=”state != 'draft' "/>
- It’s in invisible attributes so, you can not see the card_number.
2. required :-
<field name="purchase_date" required=”state == 'draft' "/>
- It’s in the required attributes so, you can not blank this field.
3. readonly :-
<field name="gift_price" readonly=”state != 'draft' "/>
- It's read only is fixed attributes so, you can not change or edit values.
now we add this in the button for our specific condition like this,
<button string=“Confirm” type= “object” name=“move_on_confirm” class=“oe_highlight”
invisible=”state == ‘confirm’ ” />
How to use attrs in odoo17 ?