Types of field in Odoo

Types of Field in Odoo :

  • A Field represents a specific type of data to be collected in a Form.
  • Fields also define the type of data that is stored within them.

​1) Integer

​2) Char

​3) Float

​4) Date

​5) Datetime

​6) Text

​7) Boolean

​8) Selection

​9) Binary


1) Integer

  • it is used for numeric value and integer value.
  • It does not contain floating point or fraction part.
  • The Integer field is used for all integer numbers (positive, negative, or zero, without a decimal).
  • Like we can use 3 but can not use 3.4 number
  • syntax: 
  • field_name=fields.Integer(‘label name’,optional parameters)

  • example:

        age = fields.Integer(‘Your age’)


2) Float

  • It is used for numeric values in which we want to add a fraction part and floating point.
  • A float is a floating-point number, which means it is a number that has a decimal place. 
  • We can use it for 3.4 numbers.
  • tax , discount for  these field  we can use it
  • syntax:  

field_name=fields.Float(‘label name’,optional parameters)

  • example:

discount = fields.Float(‘Discount’)


3) Char

  • we can use it for text as well as string 
  • we can use it for writing names , addresses etc..
  • we can set length of char in optional parameters
  • syntax:

field_name= fields.Char(‘label name’,optional parameters)

  • example

name=fields.Char(‘Name’)


4) Text

  • It is also used for text 
  • it can have unlimited length.
  • Syntax:

​field_name= fields.Text(‘label name’,optional parameters)

  • example:

note = fields.Text(‘Note’)


5) Boolean

  • It is used to give true or false value.
  • If we want to choose either true or false then this is used.
  • It only gives output like true or false 
  • syntax: 

field_name= fields.Boolean(‘label name’,optional parameters)

  • example:

active=fields.Boolean(‘Active’)


6) Selection

  • It is used to select from predefined values that we write
  • It shows  value like drop down menu
  • syntax: 
  • field_name= fields.Selection(‘lable_name’,selection= [(‘key_or_value’,’string_to_display’),(‘key_or_value’,’string_to_display’)]

  • example:

select = fields.Selection(‘Gender’,selection=[(‘m’,’Male’),(‘f’,’Female’)(‘o’,’Other’)])


7) Date

  • By this we can choose date 
  • we have to choose date from dialog box
  • syntax: 

  ​field_name= fields.Date(‘label name’,optional parameters)

  • example:

date=fields.Date(‘Date’)


8) Datetime

  • By this we can choose date and time
  • we can choose date as well as time from dialog box
  • syntax:

field_name=  fields.Datetime(‘label name’,optional parameters)

  • example:

datetime=fields.Datetime(‘Date_time’)


9) Binary

  • By this field we can add photo or document
  • syntax

​field_name=  fields.Binary(‘label name’,optional parameters)

  • example:

document=fields.Binary(‘Document’)



Administrator February 1, 2024
Share this post
Archive
Sign in to leave a comment