Type of Fields Attributes in Odoo/Openerp

Hello Odooers, Odoogig and Odoo Lovers,

In this odoo technical tutorial, I would like to explain about what type of fields attributes in odoo  and how to use the attribute or parameter for particular field by example.

  • We have already seen What type of  fields in Odoo  Check here
  • Different fields have different attributes which changes the behaviour of the field
  • such as if you want to set that, the value of field should not be empty. So at that time you can use attributes in field
  • in other words you can say that, attributes are ‘Optional Parameters’ of the field
  • In odoo, you can use below attributes in fields
        1. String
        2. Default
        3. Required
        4. Readonly
        5. Digits
        6. Domain
        7. Store
        8. Help
        9. Compute
        10. Copy
        11. Index
        12. track_visibility
        13. Inverse

#odoo #openerp #odoo12.0  #learnodoo #odootuturial  #odoofields 

1.String Fields Attributes in Odoo

  • This attribute is used to display a label near your filed, so you can easily  recognize  the field

Syntax

Example

 

2.Default Fields Attributes in Odoo

  • If you want to set default value of a field at that time you can use this parameter

Syntax

Example

  • After doing this, in age field you will find 18 is set by default
  • you can also pass ‘method’ to the default to get value for the field
  • such as to calculate age you can pass a simple method to the default as shown in below example

Example

 

3.Required Fields Attributes in Odoo

  • Sometimes, you need that type of field which value will be mandatory
  • means it’s require user input to fill compulsory into field
  • for example in some forms you have seen that Phone Number is required
  • so make particular field required, you can use required parameter on field
  • accepted value for required are 0, 1 or True/ False
  • 1 or True is used to make field required and 0 or False is used to make field non required

Syntax

Example

 

4.Readonly Fields Attributes in Odoo

  • when field is not editable then its called Readonly Field
  • means user can only read the value of field but can not edit or delete it into field.
  • to set this type of restriction, you can use Readonly parameter on a field
  • accepted value for readonly are 0, 1, True and False
  • 1 or True is used to make field readonly and 0 or False is used to make field editable
  • you can pass value to the readonly field by using Default attribute of field or or readonly field’s value can be changed by back end code manipulation

Syntax

Examples

  • After doing this, company_name field will be readonly
  • You can pass default value for the readonly field as shown below

 

5.Digits Fields Attributes in Odoo

  • Its mostly used with float type field
  • Digits is used to control precision of a value
  • precision of a value means, setting how value will display
  • for example some writes 10.0 some writes 10.00 so this difference is called different precisions
  • so you can set specific precision for field value using Digits in Odoo

Syntax

Example

 

6.Domain Fields Attributes in Odoo

  •  Its mostly used on Relational Fields(many2many, many2one)
  • Its used to filter record while setting values of the field
  • such as in one form there is a Many2one field ‘Employee’ and from all the employee just need those employees who are from ‘Management Department’ so you can use domain in it
  • so when user fills value for the employee field he/she can see only employees from ‘Management Department’
  • in short it filters record on the fly

Syntax

Example

  • You can use domain on Many2many also

 

7.Store Fields Attributes in Odoo

  • This attribute store will save value of field forcefully into database
  • sometime value of the field is not stored into database so at that time store is used to store value forcefully into database
  • while you use compute field at that time compute field’s value will not be stored into database, so you can use store there
  • Note : if you use store with compute field then compute field will be calculated only once
  • Store parameter accepts only True and False

Syntax

Example

  • now total_gross field’s value will be stored forcefully in database

 

8.Help Fields Attributes in Odoo

  • This attribute is used to make a field more user friendly
  • using this attribute you can add little help message, so user can easily understand usage of the field
  • This help or tip will only appear when user hover over the field

Syntax

Example

 

9.Compute Fields Attributes in Odoo

  • Compute attribute is used to change value of the field automatically by back-end code
  • You just have to pass a method in compute attribute and that method will calculate value of the field
  • Note : if you use this attribute than fields value can’t be changed manually, it will only updated by back-end code which is written in method

Syntax

Example

 

10.Copy Fields Attributes in Odoo

  • Copy attribute accepts either True or False
  • If false, then this field’s value will not be copied when you duplicate record in odoo
  • If true, then this field’s value will be copied when you duplicate record in odoo
  • If you not mention this attribute then by default field’s value will be copied when you duplicate record in odoo

Syntax

Example

 

11.Index Fields Attributes in Odoo

  • Index attribute accepts either True or False
  • If true, then field’s index will be created in database
  • If false, then field’s index will not be created in database
  • Note : If field’s index is created in database then as a developer it will be easier to search field in database

Syntax

Example

 

12.track_visibility Fields Attributes in Odoo

  • This attribute accepts ‘onchange’ parameter
  • If you specify this attribute in field then whenever field’s value changes, one log message will be automatically printed in chatter of the record
  • Note : Chatter is located at the end of the record, before adding this attribute make sure that chatter is available for specific model

Syntax

Example

Chatter Screen

chatter in odoo

 

13.Inverse Fields Attributes in Odoo

  • Inverse is used to trigger a method whenever field’s value changes
  • Pass name of the method into field’s parameter and that method will call each time when field’s value changes

Syntax

Example

 


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 *