KEMBAR78
Field Parameters in Odoo 18 - Odoo 18 Slides | PPTX
Field Parameters in Odoo 18
Enterprise
Enterprise
Introduction
In this slide we’ll discuss on the field parameters in Odoo 18.
These parameters are essential for customizing and controlling
the behavior of fields in models. We will review some of the most
commonly used parameters and their applications in
development.
Enterprise
1. String
This parameter defines the label that will be displayed in the form
view for the field. If not explicitly defined, Odoo will use the field's
name as the label. Example:
name = fields.Char(string="Name of the field")
2. Required:
Specifies whether the field is mandatory. A user will not be able
to save a record without entering a value for required fields.
Example:
name = fields.Char(string="Name", required=True)
Enterprise
3. Readonly:
Makes the field non-editable in the form view. However, it may still be
altered through code or computed methods. Example:
name = fields.Char(string="Name", readonly=True)
4. Default:
Provides a default value for the field if no value is provided. This can
be a static value or a callable function that computes the default
value based on certain logic. Example:
state = fields.Selection(default='draft')
Enterprise
5. Help:
Adds a tooltip with additional information that is shown when a user
hovers over the field. Example:
name = fields.Char(string="Name", help="Enter the Name")
6. Compute:
Assigns a method that calculates the value of the field. The
method is triggered when the field is accessed or updated.
Example:
total = fields.Float(compute='_compute_total')
Enterprise
7. Store:
Used for computed fields. If set to True, the result of the
computation will be stored in the database, rather than being
recalculated each time the field is accessed. Example:
total = fields.Float(compute='_compute_total', store=True)
8. Copy:
Controls whether the field value should be copied when
duplicating a record. By default, all fields are copied unless
specified otherwise. Example:
sequence = fields.Integer(copy=False)
Enterprise
9. Translate
"Translate" can be set to True to make a field translatable for different
languages. This is useful when you need to present your application
in multiple languages. Example:
name = fields.Char(string="Name", translate=True)
10. Groups:
Restricts the visibility of the field to users in specific groups,
controlling access to sensitive information. Example:
salary = fields.Float(groups="hr.group_hr_manager")
Enterprise
11. Index:
Indicates whether the field should be indexed in the database.
Indexing improves the search speed for the field, especially in
large datasets. Let's explore the different aspects of indexing:
True or "btree": This is the default index type used for many2one
relationships in Odoo. Example:
field_name = fields.Many2one('model.name', index=True)
“btree_not_null": This index type is similar to the "btree" index but
excludes NULL values. It proves particularly valuable when a
significant number of values in the field are NULL or when NULL
values are infrequently searched for. Example:
field_name = fields.Char(index="btree_not_null")
Enterprise
"gin" or "trigram": These index types leverage Generalized Inverted
Indexing (GIN) with trigrams, and they are particularly suitable for
full-text searches. They significantly improve search performance
when dealing with textual data. Example:
field_name = fields.Text(index="gin")
False or None: Setting the "index" attribute to False or None
indicates that no index should be applied to the field. This is the
default behavior in Odoo when the "index" attribute is not
explicitly specified. Example:
field_name = fields.Integer(index=False)
Enterprise
12. Ondelete:
Determines the behavior when a record referenced by a Many2one
field is deleted. Common options are cascade, set null, or restrict.
Example:
partner_id = fields.Many2one('res.partner', ondelete='cascade')
13. Digits:
Used to define precision for fields like Float where exact decimal
places matter. Example:
price = fields.Float(digits=(6, 2))
Enterprise
14. Domain:
Sets conditions that filter which records can be selected in fields like
Many2one or One2many. Example:
partner_id = fields.Many2one('res.partner', domain=[('customer',
'=', True)])
15. Tracking:
Tracks changes to the field's value in the chatter for auditing or
monitoring purposes. Example:
status = fields.Selection(tracking=True)
Enterprise
16. Selection_add
In the case of an overridden field, "Selection_add" extends the
selection list by appending new values to the existing selection in a
specific order.
state = fields.Selection( selection_add=[('approved', 'Approved'),
('rejected', 'Rejected')], )
For More Info.
Check our company website for related blogs
and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com

Field Parameters in Odoo 18 - Odoo 18 Slides

  • 1.
    Field Parameters inOdoo 18 Enterprise
  • 2.
    Enterprise Introduction In this slidewe’ll discuss on the field parameters in Odoo 18. These parameters are essential for customizing and controlling the behavior of fields in models. We will review some of the most commonly used parameters and their applications in development.
  • 3.
    Enterprise 1. String This parameterdefines the label that will be displayed in the form view for the field. If not explicitly defined, Odoo will use the field's name as the label. Example: name = fields.Char(string="Name of the field") 2. Required: Specifies whether the field is mandatory. A user will not be able to save a record without entering a value for required fields. Example: name = fields.Char(string="Name", required=True)
  • 4.
    Enterprise 3. Readonly: Makes thefield non-editable in the form view. However, it may still be altered through code or computed methods. Example: name = fields.Char(string="Name", readonly=True) 4. Default: Provides a default value for the field if no value is provided. This can be a static value or a callable function that computes the default value based on certain logic. Example: state = fields.Selection(default='draft')
  • 5.
    Enterprise 5. Help: Adds atooltip with additional information that is shown when a user hovers over the field. Example: name = fields.Char(string="Name", help="Enter the Name") 6. Compute: Assigns a method that calculates the value of the field. The method is triggered when the field is accessed or updated. Example: total = fields.Float(compute='_compute_total')
  • 6.
    Enterprise 7. Store: Used forcomputed fields. If set to True, the result of the computation will be stored in the database, rather than being recalculated each time the field is accessed. Example: total = fields.Float(compute='_compute_total', store=True) 8. Copy: Controls whether the field value should be copied when duplicating a record. By default, all fields are copied unless specified otherwise. Example: sequence = fields.Integer(copy=False)
  • 7.
    Enterprise 9. Translate "Translate" canbe set to True to make a field translatable for different languages. This is useful when you need to present your application in multiple languages. Example: name = fields.Char(string="Name", translate=True) 10. Groups: Restricts the visibility of the field to users in specific groups, controlling access to sensitive information. Example: salary = fields.Float(groups="hr.group_hr_manager")
  • 8.
    Enterprise 11. Index: Indicates whetherthe field should be indexed in the database. Indexing improves the search speed for the field, especially in large datasets. Let's explore the different aspects of indexing: True or "btree": This is the default index type used for many2one relationships in Odoo. Example: field_name = fields.Many2one('model.name', index=True) “btree_not_null": This index type is similar to the "btree" index but excludes NULL values. It proves particularly valuable when a significant number of values in the field are NULL or when NULL values are infrequently searched for. Example: field_name = fields.Char(index="btree_not_null")
  • 9.
    Enterprise "gin" or "trigram":These index types leverage Generalized Inverted Indexing (GIN) with trigrams, and they are particularly suitable for full-text searches. They significantly improve search performance when dealing with textual data. Example: field_name = fields.Text(index="gin") False or None: Setting the "index" attribute to False or None indicates that no index should be applied to the field. This is the default behavior in Odoo when the "index" attribute is not explicitly specified. Example: field_name = fields.Integer(index=False)
  • 10.
    Enterprise 12. Ondelete: Determines thebehavior when a record referenced by a Many2one field is deleted. Common options are cascade, set null, or restrict. Example: partner_id = fields.Many2one('res.partner', ondelete='cascade') 13. Digits: Used to define precision for fields like Float where exact decimal places matter. Example: price = fields.Float(digits=(6, 2))
  • 11.
    Enterprise 14. Domain: Sets conditionsthat filter which records can be selected in fields like Many2one or One2many. Example: partner_id = fields.Many2one('res.partner', domain=[('customer', '=', True)]) 15. Tracking: Tracks changes to the field's value in the chatter for auditing or monitoring purposes. Example: status = fields.Selection(tracking=True)
  • 12.
    Enterprise 16. Selection_add In thecase of an overridden field, "Selection_add" extends the selection list by appending new values to the existing selection in a specific order. state = fields.Selection( selection_add=[('approved', 'Approved'), ('rejected', 'Rejected')], )
  • 13.
    For More Info. Checkour company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com