In Odoo development, maintaining consistency, speed, and accuracy is essential, especially when working across complex modules and repetitive coding patterns. Developers often find themselves rewriting the same blocks of code for fields, models, views, and logic, which can slow down productivity and introduce unnecessary errors.
Cybrosys Assista – Odoo Helper for PyCharm solves this by providing a comprehensive set of Python snippet keywords tailored specifically for Odoo 18. These ready-to-use shortcuts are fully integrated into the PyCharm environment, allowing you to quickly generate clean, structured, and error-free code.
This guide includes the complete list of Python snippet keywords supported by the plugin, covering everything from field declarations and model definitions to CRUD methods, decorators, exception handling, and more, making it easier to write consistent and efficient Odoo code directly from your IDE.
Python Field Snippets
These snippets streamline the creation of common Odoo fields:
* odoo_field_boolean – Create a Boolean field:
fields.Boolean(string='Active')
* odoo_field_char – Create a Char field:
fields.Char(string='Name')
* odoo_field_text – Create a Text field:
fields.Text(string='Description')
* odoo_field_float – Create a Float field:
fields.Float(string='Amount', digits=(16, 2))
* odoo_field_integer – Create an Integer field:
fields.Integer(string='Quantity')
* odoo_field_selection – Create a Selection field:
fields.Selection([
('draft', 'Draft'),
('done', 'Done')
], string='Status', default='draft')
* odoo_field_date – Create a Date field:
fields.Date(string='Start Date')
* odoo_field_datetime – Create a Datetime field:
fields.Datetime(string='Timestamp')
* odoo_field_many2one – Create a Many2one relational field:
fields.Many2one('model.name', string='Partner', ondelete='restrict')
* odoo_field_one2many – Create a One2many relational field:
fields.One2many('model.name', 'inverse_field_name', string='Order Lines')
* odoo_field_many2many – Create a Many2many relational field:
fields.Many2many('model.name', string='Tags')
* odoo_field_html – Create an HTML field:
fields.Html(sanitize=True, string='Content')
* odoo_field_binary – Create a Binary field:
fields.Binary(attachment=True, string='File')
API Decorators
* odoo_api_create_multi – For handling multiple record creation:
@api.model_create_multi
* odoo_api_depends – To specify field dependencies for computed fields:
@api.depends('field_name')
* odoo_api_onchange – Trigger method when field value changes in UI:
@api.onchange('field_name')
* odoo_api_constrains – Validate fields when saving the record:
@api.constrains('field_name')
* odoo_api_returns – Specify return type of method:
@api.returns('model.name')
Import Statements
* odoo_import_fields – Import Odoo field declarations:
from odoo import fields
* odoo_import_models – Import base model classes:
from odoo import models
* odoo_import_api – Import decorators and API methods:
from odoo import api
* odoo_import_tools – Import Odoo tools module:
from odoo import tools
* odoo_import_config – Import configuration utilities:
from odoo.tools import config
* odoo_import_date_utils – Import date utility helpers:
from odoo.tools import date_utils
* odoo_import_common – Import commonly used modules:
from odoo import api, fields, models
Exception Handling
* odoo_import_exceptions – Import common Odoo exceptions:
from odoo.exceptions import UserError, ValidationError, AccessError, MissingError
* odoo_user_error – Raise a UserError:
raise UserError(_('Error message'))
* odoo_validation_error – Raise a ValidationError:
raise ValidationError(_('Validation error message'))
* odoo_access_error – Raise an AccessError:
raise AccessError(_('Access error message'))
* odoo_missing_error – Raise a MissingError:
raise MissingError(_('Record not found'))
* odoo_redirect_warning – Raise a RedirectWarning:
raise RedirectWarning(_('Warning message'), action_id, _('Button text'))
Model Class Templates
* odoo_class – Create a new standard Odoo model:
class ModelName(models.Model):
_name = 'model.name'
_description = 'New Model Description'
* odoo_transient_class – Create a transient model (used for wizards):
class ModelName(models.TransientModel):
_name = 'model.name'
_description = 'Wizard Description'
* odoo_abstract_class – Create an abstract model base class:
class ModelName(models.AbstractModel):
_name = 'model.name'
_description = 'Abstract Model Description'
* odoo_extension_inheritance – Extend a model using extension inheritance:
class ModelName(models.Model):
_name = 'model.name'
_inherit = 'model.to.inherit'
* odoo_delegation_inheritance – Inherit fields from another model via delegation:
class ModelName(models.Model):
_name = 'model.name'
_inherits = {'res.partner': 'partner_id'}
* odoo_classical_inheritance – Inherit using classical method:
class ModelName(models.Model):
_inherit = 'model.name'
Common CRUD Methods
* odoo_create_method – Override the create() method:
@api.model_create_multi
def create(self, vals):
return super().create(vals)
* odoo_write_method – Override the write() method:
def write(self, vals):
return super().write(vals)
* odoo_unlink_method – Override the unlink() method:
def unlink(self):
return super().unlink()
* odoo_computed_field – Create a computed field with method:
computed_field=fields.Float(string='ComputedField', compute='_compute_computed_field', store=True)
@api.depends('dependency_field')
def _compute_computed_field(self):
for record in self:
record.computed_field = 0.0
* odoo_onchange_method – Handle field updates dynamically in form views:
@api.onchange('field_name')
def _onchange_field_name(self):
if self.field_name:
self.another_field = self.field_name
Notification Actions
* odoo_rainbow_man_notification – Show rainbow man success effect:
return {
'effect': {
'fadeout': 'slow',
'message': 'Message to Display',
'type': 'rainbow_man',
}
}
* odoo_warning_notification – Show a warning message:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': 'Warning',
'type': 'warning',
'message': 'Check your input values.',
'sticky': True,
},
}
* odoo_success_notification – Show a success message:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': 'Success',
'type': 'success',
'message': 'The operation was successful.',
'sticky': True,
},
}
* odoo_info_notification – Show an informational message:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': 'Info',
'type': 'info',
'message': 'This is a helpful message.',
'sticky': True,
},
}
Conclusion
The Python snippet keywords available in Cybrosys Assista – Odoo Helper for PyCharm are designed to simplify and accelerate common tasks in Odoo development. From defining fields and models to managing exceptions and CRUD logic, these shortcuts help you write cleaner, more consistent code, without starting from scratch each time.
Whether you're building a new module or extending an existing one, these Python snippets provide a reliable foundation for faster, error-free development. By integrating them into your workflow, you can focus more on solving business problems and less on boilerplate code.