Odoo 16 - fields explained

Jeevachaithanyan Sivanandan - Oct 9 '23 - - Dev Community

Here is a simplified explanation of various fields in Odoo development

Basic Fields:

Char

Stores a string of characters.

char_field = fields.Char('Char Field', size=128)

example -

class Customer(models.Model):
_name = 'res.partner'

name = fields.Char('Name', size=128)
Enter fullscreen mode Exit fullscreen mode

Text | Stores a large text string. | text_field = fields.Text('Text Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    description = fields.Text('Description')
Enter fullscreen mode Exit fullscreen mode

Integer | Stores an integer value. | integer_field = fields.Integer('Integer Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    age = fields.Integer('Age')
Enter fullscreen mode Exit fullscreen mode

Float | Stores a floating-point value. | float_field = fields.Float('Float Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    height = fields.Float('Height')
Enter fullscreen mode Exit fullscreen mode

Date | Stores a date value. | date_field = fields.Date('Date Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    date_of_birth = fields.Date('Date of Birth')
Enter fullscreen mode Exit fullscreen mode

DateTime | Stores a date and time value. | datetime_field = fields.DateTime('DateTime Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    created_at = fields.DateTime('Created At')
Enter fullscreen mode Exit fullscreen mode

Boolean | Stores a boolean value (True or False). | boolean_field = fields.Boolean('Boolean Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    is_active = fields.Boolean('Is Active')
Enter fullscreen mode Exit fullscreen mode

Binary | Stores a binary file. | binary_field = fields.Binary('Binary Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    profile_picture = fields.Binary('Profile Picture')
Enter fullscreen mode Exit fullscreen mode

Selection | Stores a value from a list of predefined values. | selection_field = fields.Selection([('value1', 'Value 1'), ('value2', 'Value 2')], 'Selection Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    gender = fields.Selection([('male', 'Male'), ('female', 'Female')], 'Gender')
Enter fullscreen mode Exit fullscreen mode

Reference | Stores a reference to another record. | reference_field = fields.Reference('model_name', 'Reference Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    sale_order_id = fields.Reference('sale.order', 'Sale Order')
Enter fullscreen mode Exit fullscreen mode

One2many | Stores a list of records from another model. | one2many_field = fields.One2many('model_name', 'inverse_field_name')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    orders = fields.One2many('sale.order', 'partner_id')
Enter fullscreen mode Exit fullscreen mode

Many2one | Stores a single record from another model. | many2one_field = fields.Many2one('model_name', 'field_name')

Example:

class SaleOrder(models.Model):
    _name = 'sale.order'

    partner_id = fields.Many2one('res.partner', 'Customer')
Enter fullscreen mode Exit fullscreen mode

Many2many | Stores a list of records from another model, with many-to-many relationship. | many2many_field = fields.Many2many('model_name', 'relation_table_name', 'column1', 'column2')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    products = fields.Many2many('product.product', 'customer_product_rel', 'customer_id', 'product_id')
Enter fullscreen mode Exit fullscreen mode

Advanced fields:

Advanced fields are a set of fields in Odoo 16 that provide additional functionality and features beyond the basic fields. They are typically used to create more complex and sophisticated data models.

Monetary

Stores a monetary value, with support for multiple currencies and exchange rates.

monetary_field = fields.Monetary('Monetary Field')

Example:

class Product(models.Model):
    _name = 'product.product'

    price = fields.Monetary('Price')
Enter fullscreen mode Exit fullscreen mode

Html | Stores a text string that can contain HTML code. | html_field = fields.Html('Html Field')

Example:

class Article(models.Model):
    _name = 'website.article'

    content = fields.Html('Content')
Enter fullscreen mode Exit fullscreen mode

Related | Stores the value of a field from another record, related to the current record. | related_field = fields.Related('model_name', 'field_name')

Example:

class SaleOrderLine(models.Model):
    _name = 'sale.order.line'

    product_id = fields.Many2one('product.product', 'Product')

    product_name = fields.Related('product_id', 'name')
Enter fullscreen mode Exit fullscreen mode

Composite | Stores a set of fields as a single unit. | composite_field = fields.Composite([('field_name1', 'Field Name 1'), ('field_name2', 'Field Name 2')], 'Composite Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    address = fields.Composite([('street', 'Street'), ('city', 'City'), ('zip', 'Zip Code')], 'Address')
Enter fullscreen mode Exit fullscreen mode

ReferenceMany | Stores a list of references to other records. | reference_many_field = fields.ReferenceMany('model_name', 'field_name')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    invoices = fields.ReferenceMany('account.invoice', 'partner_id')
Enter fullscreen mode Exit fullscreen mode

Image | Stores an image file. | image_field = fields.Image('Image Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    profile_picture = fields.Image('Profile Picture')
Enter fullscreen mode Exit fullscreen mode

Sign | Stores a signature image. | sign_field = fields.Sign('Sign Field')

Example:

class Contract(models.Model):
    _name = 'contract'

    customer_signature = fields.Sign('Customer Signature')
Enter fullscreen mode Exit fullscreen mode

Property | Stores a property value. | property_field = fields.Property('Property Field')

Example:

class Product(models.Model):
    _name = 'product.product'

    sale_price_list = fields.Property('Sale Pricelist')
Enter fullscreen mode Exit fullscreen mode

Geospatial | Stores a geographic location. | geo_field = fields.GeoPoint('Geo Field')

Example:

class Customer(models.Model):
    _name = 'res.partner'

    location = fields.GeoPoint('Location')
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player