Build your first app
You'll build a small module that adds a new model and screens to a workspace. By the end you'll have an app in the menu.
1. Scaffold the module
A module is a folder in the addons path with a manifest. Create
addons/my_app/:
my_app/
├── __init__.py
├── __manifest__.py
├── models/
│ ├── __init__.py
│ └── my_record.py
├── security/
│ └── ir.model.access.csv
└── views/
└── my_record_views.xml
__manifest__.py declares the app:
{
"name": "My App",
"version": "19.0.1.0.0",
"depends": ["base"],
"data": [
"security/ir.model.access.csv",
"views/my_record_views.xml",
],
"application": True,
"license": "LGPL-3",
}
2. Define a model
models/my_record.py:
from odoo import fields, models
class MyRecord(models.Model):
_name = "my.record"
_description = "My Record"
name = fields.Char(required=True)
note = fields.Text()
done = fields.Boolean()
Wire up the __init__.py files to import models, and models to import
my_record.
3. Grant access
security/ir.model.access.csv gives users rights to the model:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_my_record,my.record,model_my_record,base.group_user,1,1,1,1
4. Add screens and a menu
views/my_record_views.xml defines a list, a form, an action, and a menu:
<odoo>
<record id="my_record_action" model="ir.actions.act_window">
<field name="name">My Records</field>
<field name="res_model">my.record</field>
<field name="view_mode">list,form</field>
</record>
<menuitem id="my_app_root" name="My App"/>
<menuitem id="my_app_menu" parent="my_app_root"
action="my_record_action"/>
</odoo>
5. Install it
Install the module on your workspace from the command line (-i my_app) or from
Settings → Apps. It appears in the app menu.
Hot reload
During development, update the module (-u my_app) to apply changes to XML
and data. Python changes need a server restart.
Next
Need a hand with this? company@everjust.co — a human answers.