0% found this document useful (0 votes)
16 views3 pages

Odoo Module Development Guide

Uploaded by

tigrinenacer1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Odoo Module Development Guide

Uploaded by

tigrinenacer1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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="{&quot;always_reload&quot;: True,
&quot;highlight_first_line&quot;: 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 [Link])
- Adding an icon
o Cearte a subdir in the module dir static/description/[Link]
- 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="[Link]">
<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="[Link]">
<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 [Link]:
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

Common questions

Powered by AI

Creating a new Odoo app involves several steps: 1. **Step 1 - Creating a new addon module**: This includes setting up the module's skeleton structure using the command `odoo-bin scaffold` and creating a manifest file to define metadata like category, license, and description . 2. **Step 2 - Creating a new application**: This step requires adding a top menu item and defining security groups to manage access rights within the `mymodule_menu.xml` and `mymodule_security.xml` files, respectively . 3. **Step 3 - Adding automated tests (optional)**: This step can be skipped if automated testing isn't required. 4. **Step 4 - Implementing the model layer**: Involves creating a data model by defining classes in `.py` files under the models' directory and importing them in `__init__.py` . 5. **Step 5 - Setting up access security**: This ensures that security rules are enforced by using security files to define role-based permissions . 6. **Step 6 - Implementing the backend view layer**: Focuses on creating form and list views for the module. 7. **Step 7 - Implementing the business logic layer**: Includes writing Python code to implement custom business logic. 8. **Step 8 - Implementing the website UI**: This step involves designing the user interface for client interaction via the web . Each step incrementally builds the functionality and structure needed for a fully-functional Odoo module.

The `implied_ids` attribute in Odoo module development is used to define inheritance of permissions from one security group to another. It allows a security group to inherit and thus imply the permissions of another group. For example, using the `eval` attribute with a tuple like `(4, ref('base.group_user'))` informs Odoo to import the permissions of the `base.group_user` into the current group being defined. This is particularly useful for creating role hierarchies where higher-level roles automatically gain the privileges of lower-level roles without re-declaring those permissions .

To modify an existing Odoo notebook view, you can use XPath expressions to add a new page and field. This involves identifying the correct position within the XML structure of the notebook and specifying the new elements to insert. For example, to add a 'Family Information' page with a group titled 'parents' that contains fields for 'Father's First Name' and 'Mother's First Name', the XML would be structured like this: ``` <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> ``` This XPath expression targets the notebook element and inserts the defined page and fields within it, effectively customizing the view to include new data entries without altering the original structure .

You might also like