⚙️ Odoo Create Method
Used to override the create method in Odoo models, allowing custom logic during record creation.
🚀 What It Does
✅ Lets you:
Modify values before saving
Add logic or checks during creation
Perform actions after records are created
@api.model_create_multi
def create(self, vals_list):
# Pre-create logic (optional)
records = super().create(vals_list)
# Post-create logic (optional)
return records
💡 Why Use the Odoo Create Method?
Automate data processing
Ensure business rule compliance
Streamline custom workflows
⚙️ Odoo Write Method
Customizes the write method to apply logic during record updates.
🚀 What It Does
✅ Enables you to:
Add logic before or after updates
Perform validations during write operations
Implement auditing or custom workflows
def write(self, values):
# Pre-write logic (optional)
res = super().write(values)
# Post-write logic (optional)
return res
💡 Why Use the Odoo Write Method?
Track changes for auditing
Enforce business rules during updates
Automate custom update workflows
⚙️ Odoo Unlink Method
Overrides the unlink method to define custom behavior during record deletion.
🚀 What It Does
✅ Lets you:
Add logic before or after deleting records
Implement soft delete mechanisms
Prevent deletion under specific conditions
def unlink(self):
# Pre-unlink logic (optional)
res = super().unlink()
# Post-unlink logic (optional)
return res
💡 Why Use the Odoo Unlink Method?
Prevent accidental deletions
Log or audit deletions
Manage related records during delete operations
⚙️ Odoo Onchange Method
Adds dynamic behavior to forms by updating fields when dependent values change.
🚀 What It Does
✅ Enables you to:
Automatically update fields when other fields change
Add client-side validations
Improve form usability with dynamic interactions
@api.onchange('field_name')
def onchangefield_name(self):
if self.field_name:
self.target_field = value
💡 Why Use the Odoo Onchange Method?
Enhance user experience with real-time updates
Guide users with dynamic field adjustments
Reduce input errors at the form level
⚙️ Odoo Compute Method
Dynamically calculates field values based on dependencies. Automatically triggers when dependent fields change.
🚀 What It Does
✅ Enables you to:
Compute field values dynamically
Link field values to other fields
Ensure data stays consistent without manual input
field_name = fields.FieldType(
string='Field Label',
compute='_compute_field_name',
store=True
)
@api.depends('dependency_field')
def computefield_name(self):
for rec in self:
# Compute logic
rec.field_name = value
💡 Why Use the Odoo Compute Method?
Automate value updates based on other fields
Keep data synchronized without extra code
Improve accuracy and reduce redundant data entry
⚙️ Odoo Constraints Method
Adds model-level validations that are enforced during create and write operations.
🚀 What It Does
✅ Lets you:
Enforce business rules at the database level
Prevent invalid data from being saved
Validate related fields during create/update
@api.constrains('field_name')
def checkfield_name(self):
for rec in self:
if not rec.field_name:
raise ValidationError("field_name must be set")
💡 Why Use the Odoo Constraints Method?
Ensure data integrity
Block invalid updates at the model level
Provide meaningful validation error messages
⚙️ Odoo Search Method
Implements custom search behavior for your model — ideal for name search or complex domain logic.
🚀 What It Does
✅ Enables you to:
Customize how records are searched
Implement multi-field search logic
Control search behavior for specific fields
@api.model
def searchname(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
args = args or []
domain = []
if name:
domain = ['|', '|',
('name', operator, name),
('field_name', operator, name),
('field_name2', operator, name)]
return self._search(domain + args, limit=limit, access_rights_uid=name_get_uid)
💡 Why Use the Odoo Search Method?
Enhance user search experience
Support advanced lookup scenarios
Make multi-field or conditional search possible
⚙️ Odoo Default Get Method
Sets default values for fields when creating new records.
🚀 What It Does
✅ Lets you:
Pre-fill fields with default values
Customize defaults dynamically based on context
Simplify record creation for users
@api.model
def default_get(self, fields_list):
res = super().default_get(fields_list)
res.update({
'field_name': default_value,
})
return res
💡 Why Use the Odoo Default Get Method?
Improve user experience with smart defaults
Reduce manual data entry
Dynamically set defaults based on logic or context
⚙️ Odoo Action Method
Creates methods that return action dictionaries for opening views or triggering actions.
🚀 What It Does
✅ Enables you to:
Open specific views dynamically
Control domain filters and context
Trigger custom windows or wizards
def action_action_name(self):
self.ensure_one()
return {
'name': ('Action Title'),
'type': 'ir.actions.actwindow',
'res_model': 'model.name',
'view_mode': 'list,form',
'domain': [('field', '=', self.field)],
'context': {'default_field': self.field},
}
💡 Why Use the Odoo Action Method?
Open forms, lists, or wizards with custom logic
Pre-fill fields using context
Filter records dynamically when opening views
⚙️ Odoo SQL Constraints
Adds database-level constraints to ensure data integrity and enforce rules at the database level.
🚀 What It Does
✅ Lets you:
Prevent duplicate records
Enforce unique or custom SQL conditions
Ensure integrity directly in the database
sqlconstraints = [
('constraint_name', 'constraint_type', 'message')
]
💡 Why Use Odoo SQL Constraints?
Enforce rules beyond application logic
Catch data integrity issues at the database level
Improve reliability of your Odoo models
Top comments (0)