Prj701 10 ~ Creating an Odoo Module

October 10, 2018
PRJ701 Python Odoo Azure PostgreSQL XML Open source

PRJ701 - Creating an Odoo Module

One of the most powerful things that Odoo brings is the fact that it is open-source. This allows developers like myself to extend the existing structure to fit any use case. To make it even better, Odoo has taken it a step further and provided a built in way to generating the skeleton of an entirely new module. This is done via the scaffold flag when executing odoo-bin. Before I do that let’s break down the components of a module and what we can expect from this scaffold command. The most basic form of an Odoo module is one only containing a __manifest__.py file, which only needs a name value like so ~ {"name": "New Module"}. The manifest file has many fields that can be added which include but are not limited to; name, summary, description, author, license, website, category, version, depends, data, and demo. I will not go over what each of these fields do as they should be pretty straight-forward via their naming conventions, the only ones that I could see being confusing slightly is depends. Depends refers to the modules that this module will inherit from (meaning the new module will have everything that the depends modules have). Odoo modules follow the MVC design pattern, which means they seperate the code base into 3 main components; model, view, and controller. Along with those directories, there is also data, demo, security, and static. The data directory contains initial data for the module, demo is for demonstration data, security is for access control lists data, and static is for web assets.

Now that we’ve discussed the makeup of an Odoo module, lets create one with that scaffold command! Its as simple as ./odoo-bin scaffold new_module ~/path/to/addons/directory. With the magic of scaffold we now have a directory called new_module (contained in the addons directory) which will have the following generated.

new_module
├── controllers
│   ├── controllers.py
│   └── __init__.py
├── demo
│   └── demo.xml
├── __init__.py
├── __manifest__.py
├── models
│   ├── __init__.py
│   └── models.py
├── security
│   └── ir.model.access.csv
└── views
    ├── templates.xml
    └── views.xml

The first thing that needs to be changed is the __manifest__.py file, which contains configuration values for the module. These include options like ~

* Name
* Summary
* Description
* Author
* Website
* Category
* Version
* Depends
* Data

These are only a few…

Code generated in files like models.py or views.xml are commented out; this code can be used, but from experience I would suggest not to as some of the values generated cause errors (or at least when I tried).

Web701 22

June 15, 2019
Web701 Serverless OpenFaas Docker CLI Python Digital Ocean

Web701 21

May 21, 2019
Web701 VirtualBox Serverless OpenFaas Docker CLI Python

Web701 20

May 20, 2019
Web701 Python Django Heroku Web Hosting
comments powered by Disqus