Smart Suggestions
The Smart Suggestion feature enhances your Odoo development experience by offering intelligent, context-aware code completions. It significantly improves productivity and reduces errors by suggesting relevant model names, field names, and class attributes based on the context in both Python and XML files.
Key Features
- Context-aware completions for common Odoo patterns
- Auto-suggestions for model and field names in both Python and XML
- Reduces manual errors and accelerates development workflows
- Compatible with Odoo's ORM, API decorators, and XML view definitions
Python Suggestions
Model Names
The plugin provides intelligent completions in the following Python contexts:
_inherit
Attribute
Inheritance suggestions help you extend existing Odoo models by providing available model names that can be inherited from. This ensures you reference valid models and helps establish proper inheritance relationships.
# Single inheritance
class MyModel(models.Model):
_inherit = '|' # Suggests existing model names
# Multiple inheritance
class MyModel(models.Model):
_inherit = ['|'] # Suggests existing model names for multiple inheritance
Relational Fields
Relational field suggestions provide model names that can be used as target models for Many2one, One2many, and Many2many relationships. This ensures you reference valid models and helps establish proper data relationships between your models.
class MyModel(models.Model):
partner_id = fields.Many2one('|') # Suggests model names for comodel_name
line_ids = fields.One2many('|') # Suggests model names and inverse field name
tag_ids = fields.Many2many('|') # Suggests model names and inverse field name
Environment Access
Environment access suggestions help you quickly reference models through Odoo's environment object. This is particularly useful when you need to access models dynamically or perform operations on different models within your methods.
def my_method(self):
self.env['|'] # Suggests model names when accessing through env
def controller_method(self):
request.env['|'] # Suggests model names when accessing through request.env
Field Names
API Decorators
API decorator suggestions help you specify the correct field names for dependency tracking, onchange triggers, and constraint validations. This ensures your computed fields update properly and your business logic executes at the right times.
@api.depends('|') # Suggests field names
@api.onchange('|') # Suggests field names
@api.constrains('|') # Suggests field names
Record Access
Record access suggestions provide field names when accessing related records through relational fields or using ORM methods. This helps you navigate through related data structures and access the correct fields on linked models.
def my_method(self):
self.relational_field_id.| # Suggests field names when accessing records
self.env['model.name'].mapped('|') # Suggests field names for mapped operation
class MyModel(models.Model):
line_ids = fields.One2many('model.name', '|') # Suggests inverse field name
Module Dependencies
Manifest Depends
Manifest dependency suggestions help you specify the correct module dependencies in your __manifest__.py
file. This ensures your module has access to all required functionality and prevents dependency-related issues during installation.
# In __manifest__.py
{
'depends': ['|'], # Suggests available modules for dependencies
}
XML Suggestions
View Definitions
Model Names
Model name suggestions in XML help you reference the correct models when defining views, actions, and other XML elements. This ensures your views are properly associated with the intended models and display the correct data.
<record model="|" id="view_id"> <!-- Suggests model names -->
<field name="model">|</field> <!-- Suggests model names -->
Field Names
Field name suggestions in XML provide context-aware completions based on the model being referenced in the view. This helps you add the correct fields to your views and ensures they exist on the target model.
<field name="|"> <!-- Suggests field names based on model context -->
Template IDs
Template ID suggestions help you reference existing QWeb templates when using the t-call
directive. This ensures you use valid template names and helps maintain consistency in your view rendering.
<t t-call="|"> <!-- Suggests template IDs -->
Action Definitions
Model Names
Action model suggestions provide model names that can be used as the target model for window actions. This ensures your actions open the correct views and display the intended data.
<record model="ir.actions.act_window" id="action_id">
<field name="res_model">|</field> <!-- Suggests model names -->
</record>
Widgets
Widget suggestions provide the available Odoo widgets that can be applied to fields in views. These widgets enhance field display and user interaction, such as date pickers, image viewers, and progress bars.
<field name="name" widget="|"/> <!-- Suggests Widgets -->
Css Class
CSS class suggestions provide custom CSS classes that are defined in your project. These suggestions help you apply consistent styling to your views and maintain a cohesive user interface design.
<field name="name" class="|"/> <!-- Suggests classes declared in your Project -->
Benefits
Productivity
- Faster code writing
- Reduced typing
- Quick access to common patterns
Accuracy
- Prevents typos
- Ensures correct model/field names
- Maintains consistency
Learning
- Discover available models
- Learn field names
- Understand Odoo patterns
Tips for Effective Use
Context Awareness
- Suggestions adapt to your current context
- Different suggestions for Python vs XML
- Model-aware field suggestions
Keyboard Shortcuts
- Use
Ctrl+Space
to trigger suggestions Tab
to accept suggestionsEsc
to dismiss suggestions
- Use
Next Steps
- Explore Code Snippets for more code generation features
- Learn about Code Inspection for quality checks
- Check out Best Practices for development guidelines