attrs in Odoo (invisible, readonly or required)

Hello Odooers, Odoogig and Odoo Lovers,

In this Odoo Technical Tutorial, I would like to explain how to use attrs in Odoo

    • In odoo attrs is used to change behavior of the field on the fly(on run time or real time)
    • attrs view  field attribute which defines in .xml view file
    • There are 3 keys of attrs:
      1. invisible attrs
      2. readonly attrs
      3. required attrs
    • invisible : field will be hidden
    • readonly : you can not change value of the field
    • required : you must have to provide value for a field, in short field can’t be empty
  • The structure of ‘ attrs’ is a dictionary where the key is client attribute and value will be set of domain(s). If you do not know what is domain in odoo then first refer this
  • You can do 3 main thing using attrs:
    1. Making field readonly or editable on the fly based on condition
    2. Making field visible or invisible on the fly based on condition
    3. Making field required or optional on the fly based on condition
  • If you want to hide ‘odoo_developer’ field when age is less than 18 then you can use attrs with invisible key Like below :

  • If you want to make ‘odoo_developer’ field required when age is 18 or greater than that then you can use attrs with required key

  • If you want to make ‘claim_amount’ field readonly when record’s state not in draft then you can use attrs with readonly key

How  to use attrs attribute in Odoo to with multiple attributes (invisible, readonly or required) into a single field?

You can also use attrs attribute in odoo with multiple attribute like below

 

GET IN TOUCH.!

We’d Love to Hear from You! We are happy to answer any questions, you have regarding My Training.

Mail : getodootraining@gmail.com

Skype : mayur_maheshwari1

What’s app : +919924542042

LEAVE A REPLY

Leave a Reply

Your email address will not be published. Required fields are marked *