As an Odoo developer, I was tired of writing the same boilerplate code every single day.
Every time I created a new model, I had to write:
from odoo import models, fields, api
class MyModel(models.Model):
_name = 'my.model'
_description = 'My Model'
name = fields.Char(string='Name', required=True)
And every time I needed a form view, I had to write the entire XML structure from scratch.
So I decided to do something about it β I built a free VS Code extension called Odoo Dev Snippets!
What is Odoo Dev Snippets?
It is a VS Code extension that provides 20+ code snippets for Odoo developers. Just type a short prefix, press Tab, and your boilerplate code is ready in seconds!
Python Snippets
| Prefix | What you get |
|---|---|
omodel |
Complete Odoo model class |
ocompute |
Computed field with @api.depends
|
oonchange |
Onchange method decorator |
om2o |
Many2one relational field |
oo2m |
One2many relational field |
om2m |
Many2many relational field |
obtn |
Button action method |
oerror |
Raise UserError |
osearch |
Search query |
owizard |
TransientModel wizard |
Example
Type omodel + Tab:
from odoo import models, fields, api
class SaleOrder(models.Model):
_name = 'sale.order'
_description = 'Sale Order'
name = fields.Char(string='Name', required=True)
# cursor lands here β ready to code!
Type ocompute + Tab:
total_amount = fields.Float(
string='Total Amount',
compute='_compute_total_amount'
)
@api.depends('order_line')
def _compute_total_amount(self):
for rec in self:
rec.total_amount = # cursor lands here
XML Snippets
| Prefix | What you get |
|---|---|
oform |
Complete form view |
otree |
Tree / list view |
okanban |
Kanban view |
osearchview |
Search view with filter and group by |
oaction |
Window action |
omenu |
Menu item |
obtnheader |
Header with button and statusbar |
osmartbtn |
Smart button |
onote |
Notebook with page tab |
ogroup2 |
Two-column group layout |
oinherit |
View inherit with XPath |
ochatter |
Chatter widget |
omodulexml |
Base XML file wrapper |
Example
Type oform + Tab:
<record id="sale_order_form_view" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="arch" type="xml">
<form string="Sale Order">
<sheet>
<group>
<field name="name"/>
<!-- cursor lands here -->
</group>
</sheet>
</form>
</field>
</record>
Type oinherit + Tab:
<record id="sale_order_form_view_inherit" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<!-- cursor lands here -->
</xpath>
</field>
</record>
How to Install
From VS Code Marketplace
- Open VS Code
- Press
Ctrl+Shift+X - Search "Odoo Dev Snippets"
- Click Install
From GitHub
π github.com/amankum02/odoo-snippets
Pro Tip
Just type o in any Python or XML file and VS Code IntelliSense will show you all available Odoo snippets in a dropdown!
What's Next?
I am planning to add more snippets:
-
__manifest__.pytemplate - Security
ir.model.access.csvtemplate - Controller routes
- QWeb templates
- Pivot and graph views
Contribute
This is an open source project and contributions are welcome!
If you use Odoo daily and have snippets you always write β please open a PR or suggest in the issues. Let's build this together for the Odoo community! π
π GitHub Repository
About Me
I am Aman Kumar Singh, an Odoo developer from India. I build open source tools to make Odoo development faster and easier.
- GitHub: @amankum02
- LinkedIn: Aman Kumar Singh
If this extension saves you even 10 minutes a day β give it a β on GitHub and a review on the Marketplace! It means a lot as a solo developer. π
Top comments (0)