Key Concepts of an Odoo Module
- An Odoo module is a set of business logic that either enhances existing Odoo functionality or adds new features.
- Modules are the fundamental building blocks for customizing Odoo.
Building the 'School Management' Module
This tutorial walks through creating a custom module to manage student records.
Important
All custom modules should be placed in a separate directory (e.g.,
custom_addons), and this directory's path must be added to theaddons_pathin yourodoo.conffile.
1. Directory & File Structure
A typical module contains several standard directories and files:
__init__.py: A required file that marks the directory as a Python package. It's used to import sub-packages (like themodelsdirectory).__manifest__.py: Contains metadata about the module, such as its name, version, dependencies, and data files. This file is essential for Odoo to recognize and display the module in the Apps list.models/: This directory holds the Python files that define the module's business objects (database models).models/__init__.py: Imports all the model files within the directory.models/school.py: Defines theschool.studentmodel.
views/: Contains XML files that define how the data is displayed in the user interface, including menus, actions, forms, and list views.views/school.xml: Defines the UI for the School Management module.
security/: This directory is used to manage access rights.security/ir.model.access.csv: A CSV file that defines which user groups can perform read, write, create, and delete operations on a model.
- Other Directories:
wizard/: For creating transient models that appear as pop-up windows.report/: For defining PDF reports and their templates.data/: For loading initial or necessary data.demo/: For loading demonstration data.controllers/: For managing frontend and backend web routes and actions.
2. The Model (school.py)
The model defines the data structure and business logic.
- The
school.studentmodel is created by inheriting frommodels.Model. - The
_nameattribute is crucial as it defines the unique name of the model in the Odoo database (e.g.,_name = 'school.student'). - Fields are defined as class attributes using the
fieldsAPI.
3. The View (school.xml)
The view defines the user interface elements. The XML file typically contains:
- Menu Items (
ir.ui.menu): To create new menus in the Odoo navigation bar. - Actions (
ir.actions.act_window): To define what happens when a menu is clicked, specifying the target model and views. - Views (
ir.ui.view): To structure the layout of forms, lists (trees), and other view types for a model.
4. Security (ir.model.access.csv)
Access control is mandatory for models to be usable by non-admin users.
- The CSV file defines access rules for each model.
- Columns:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink. - The
model_iduses the formatmodel_<model_name_with_underscores>(e.g.,model_school_student). - Permissions are set using
1for True or0for False. - Example: Granting full access to internal users (
base.group_user).
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_school_student,access.student,model_school_student,base.group_user,1,1,1,1
### 5. The Manifest File (`__manifest__.py`)
This file acts as the module's "ID card."
* **`name`**: The human-readable name of the module.
* **`summary`**: A short tagline describing the module's purpose.
* **`version`**: The module version.
* **`depends`**: A list of other modules that this module depends on.
* **`data`**: A list of XML and CSV files to be loaded, in order. This must include security files and view files.
```python
'data': [
'security/ir.model.access.csv',
'views/school.xml',
],
```
* **`installable` & `application`**: Set to `True` to make the module installable as a main application.
## Installation Process
1. Add the path to your custom modules folder (e.g., `custom_addons`) to the `addons_path` in your `odoo.conf` file.
2. Restart the Odoo server.
3. Go to the Odoo UI and activate Developer Mode.
4. Navigate to **Apps** and click **Update Apps List**.
5. Search for your module by its name (e.g., "School Management").
6. Click **Install**.
