Add custom field to a model.
<field name=” chosen field where to put the new field” position=” after”>
<field name=” our new field”/>
</field>
Add a page to a notebook.
<xpath expr="//notebook" position="inside">
<page string="Family Information">
<group string="parents">
<field name="x_father_firstname" options="{"always_reload": True,
"highlight_first_line": True}"/>
<field name="x_mother_firstlastname"/>
</group>
</page>
</xpath>
Steps to follow to create an odoo app(module).
Step 1 – Creating a new addon module.
Step 2 – Creating a new application.
Step 3 – Adding automated tests (you can skip this).
Step 4 – Implementing the model layer.
Step 5 – Setting up access security.
Step 6 – Implementing the backend view layer.
Step 7 – Implementing the business logic layer.
Step 8 – Implementing the website user interface (UI).
Step 1 – Creating a new addon module.
- Create skeleton structure of a module using pycharm in odoo
python odoo-bin scaffold libraryCompos ./addons-compos
- Creating a manifest file
- Setting the module category
- Choosing a license
- Adding a description (can be html css README.md)
- Adding an icon
o Cearte a subdir in the module dir static/description/icon.png
- Installing a new module and do upgrade when changing the data (xml files)
o If changes made to python code restart the server is required
Step 2 – Creating a new application.
- Adding a top menu item
o create a views/mymodule_menu.xml
<odoo>
<menuitem id="menu_ mymodule " name=" mymodule " />
</odoo>
o Edit the __manifest__.py
"data": [
"views/ mymodule _menu.xml",
],
It will be visible later once we add submenus and the corresponding access
permissions.
- Adding security groups
o add to the security/mymodule _security.xml file.
<odoo>
<data>
<record id=" mymodule _group_user" model="res.groups">
<field name="name">User</field>
<field name="category_id"
ref="base.module_category_services_ mymodule "/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record> </data>
<record id="library_group_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="base.module_category_services_library "/>
<field name="implied_ids" eval="[(4, ref('library_group_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root')), (4,
ref('base.user_admin'))]"/>
</record></odoo>
- <record>: This tag is used to define a record that will be created or modified in the
database.
- id: This is the unique identifier for the record within the module. It’s used to reference
this group elsewhere in the Odoo configuration.
- model: This specifies the model that the record belongs to. In this case res.groups:
refers to the model for user groups in Odoo.
- <field>: This tag defines the value for a field of the record.
o name: This attribute specifies the field’s name within the model. Here, it’s
setting the name of the group.
o The value " User" is the human-readable name for the group that will appear
in the Odoo interface.
- implied_ids: which refers to other security groups that this group should inherit
permissions from.
- eval: This attribute contains a list of tuples that represent commands for the server to
execute.
o (4, ref('base.group_user')): This tuple is a command that tells Odoo to add a
reference to another group.
4: This is the command code for adding an item to a many2many or
one2many field.
ref('base.group_user'): This function retrieves the reference to the
base.group_user, which is the base user group in Odoo.
Step 4 – Implementing the model layer.
- Creating a data model
o create a models/mymodule_className.py
o in models/__init__.py add
from . import mymodule_className
o in mymodule_className.py
from odoo import fields, models
you class definition