Skip to content

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

python
class MyModel(models.Model):
    _inherit = '|'  # Suggests existing model names

Relational Fields

python
class MyModel(models.Model):
    partner_id = fields.Many2one('|')  # Suggests model names for comodel_name
    line_ids = fields.One2many('|', 'inverse_field')  # Suggests model names and inverse field name

Environment Access

python
def my_method(self):
    self.env['|']  # Suggests model names when accessing through env

Field Names

API Decorators

python
@api.depends('|')  # Suggests field names
@api.onchange('|')  # Suggests field names
@api.constrains('|')  # Suggests field names

Record Access

python
def my_method(self):
    self.relational_field_id.|  # Suggests field names when accessing records

Imports and Dependencies

  • Suggests common Odoo imports
  • Completes import statements
  • Offers relevant module suggestions

XML Suggestions

View Definitions

Model Names

xml
<record model="|" id="view_id">  <!-- Suggests model names -->

Field Names

xml
<field name="|">  <!-- Suggests field names based on model context -->

Action Definitions

Model Names

xml
<record model="ir.actions.act_window" id="action_id">
    <field name="res_model">|</field>  <!-- Suggests model names -->
</record>

View Types

xml
<field name="view_mode">|</field>  <!-- Suggests view modes (form, tree, etc.) -->

Widgets

xml
<field name="name" widget="|"/> <!-- Suggests Widgets -->

Css Class

xml
<field name="name" class="|"/> <!-- Suggests classes declared in your Project -->

Benefits

  1. Productivity

    • Faster code writing
    • Reduced typing
    • Quick access to common patterns
  2. Accuracy

    • Prevents typos
    • Ensures correct model/field names
    • Maintains consistency
  3. Learning

    • Discover available models
    • Learn field names
    • Understand Odoo patterns

Tips for Effective Use

  1. Context Awareness

    • Suggestions adapt to your current context
    • Different suggestions for Python vs XML
    • Model-aware field suggestions
  2. Keyboard Shortcuts

    • Use Ctrl+Space to trigger suggestions
    • Tab to accept suggestions
    • Esc to dismiss suggestions

Next Steps