Advanced topics¶
This section covers advanced features of Odoo.sh related to containers, Git submodules, and scheduled actions.
Contenitori¶
Each build is isolated in its own container (Linux namespace container). The base is an Ubuntu-based system on which all of Odoo’s required dependencies, as well as common, useful packages, are installed.
If your project requires additional Python dependencies or more
recent releases, you can define a requirements.txt file at the root of your branches that
lists them. The platform will ensure these dependencies are installed in your containers.
Vedi anche
For a concrete example, check out the Odoo Community requirements.txt file.
Nota
The requirements.txt files of submodules are also
taken into account. The platform looks for such files in the parent folder of each folder
containing an Odoo module.
Struttura della cartella¶
As the containers are Ubuntu-based, their directory structure follows the Filesystem Hierarchy Standard.
Vedi anche
The directories relevant to Odoo.sh are the following:
.
├── home
│ └── odoo
│ ├── backup.daily
│ ├── data
│ │ ├── filestore Database attachments, as well as the files of binary fields
│ │ └── sessions Visitors and users sessions
│ ├── logs
│ │ ├── install.log Database installation logs
│ │ ├── odoo.log Running server logs
│ │ ├── update.log Database updates logs
│ │ └── pip.log Python packages installation logs
│ └── src
│ ├── odoo Odoo Community source code
│ │ └── odoo-bin Odoo server executable
│ ├── enterprise Odoo Enterprise source code
│ ├── themes Odoo Themes source code
│ └── user Your repository branch source code
└── usr
├── lib
│ └── pythonX.XX
│ └── dist-packages Python X.XX standard libraries
├── local
│ └── lib
│ └── pythonX.XX
│ └── dist-packages Python X.XX third-party libraries
└── usr
└── bin
└── pythonX.X Python X.XX executable
Shell del database¶
While accessing a container with the shell, you can access the database using the psql command.
odoo@odoo-master-1.odoo.sh:~$ psql
psql (16.9)
Type "help" for help.
odoo-master-1=>
Avvertimento
Always use transactions (e.g.,
BEGIN (…) COMMIT / ROLLBACK) when an SQL statement leads to changes (e.g., UPDATE,
DELETE, ALTER, etc.) , especially for your production database. The transaction mechanism is
your safety net in case of a mistake. You simply have to rollback your changes to revert your
database to its previous state.
Do not forget to commit or roll back transactions. Open transactions may lock records in your tables, and a running database may wait for them to be released, causing a server to hang indefinitely.
In addition, use your staging databases to test your statements first. It gives you an extra safety net.
Example
You forgot to set your WHERE condition. In such a case, you can rollback to revert the
unwanted change:
odoo-master-1=> BEGIN;
BEGIN
odoo-master-1=> UPDATE res_users SET password = '***';
UPDATE 457
odoo-master-1=> ROLLBACK;
ROLLBACK
Then, rewrite the statement and commit the change:
odoo-master-1=> BEGIN;
BEGIN
odoo-master-1=> UPDATE res_users SET password = '***' WHERE id = 1;
UPDATE 1
odoo-master-1=> COMMIT;
COMMIT
Far funzionare un server Odoo¶
You can start an Odoo server instance from a container shell. You won’t be able to access it from the outside world with a web browser, but you can, for example:
Use the Odoo shell:
odoo-bin shell >>> partner = env['res.partner'].search([('email', '=', 'asusteK@yourcompany.example.com')], limit=1) >>> partner.name 'ASUSTeK' >>> partner.name = 'Odoo' >>> env['res.partner'].search([('email', '=', 'asusteK@yourcompany.example.com')], limit=1).name 'Odoo'
Install a module:
odoo-bin -i sale --without-demo=all --stop-after-initSuggerimento
The argument
--without-demo=allprevents demo data from being loaded for all modules.The argument
--stop-after-initimmediately shutdowns the server instance after the operation is completed.
Update a module:
odoo-bin -u sale --stop-after-init
Run the tests for a module:
odoo-bin -i sale --test-enable --log-level=test --stop-after-init
Vedi anche
To find the addons path used by Odoo.sh to run your server, look for «odoo: addons paths» in the
logs (~/logs/odoo.log).
2025-02-19 10:51:39,267 4 INFO ? odoo: Odoo version 18.0
2025-02-19 10:51:39,268 4 INFO ? odoo: Using configuration file at /home/odoo/.config/odoo/odoo.conf
2025-02-19 10:51:39,268 4 INFO ? odoo: addons paths: ['/home/odoo/data/addons/18.0', '/home/odoo/src/user', '/home/odoo/src/enterprise', '/home/odoo/src/themes', '/home/odoo/src/odoo/addons', '/home/odoo/src/odoo/odoo/addons']
Avvertimento
Operations you perform on an Odoo server instance are not isolated; changes will be reflected in the database. Remember to always carry out tests in your staging databases.
Eseguire il debug in Odoo.sh¶
Nota
Debugging an Odoo.sh build is not really different from debugging another Python app. As such, the goal of this section is to cover the specificities and limitations of the Odoo.sh platform, and assumes that you already know how to use a debugger.
You can use pdb, pudb, or ipdb to debug code on Odoo.sh. Since the server runs outside a
shell, you cannot launch the debugger directly from your Odoo backend, as it requires a shell to
operate.
pdb viene installato per impostazione predefinita in ogni contenitore.
Suggerimento
To use pudb or ipdb, it is necessary to install them either:
permanently by adding
pudboripdbto your project’srequirements.txtfile, ortemporarily (only in the current build) by running the relevant command:
pip install pudb --user
pip install ipdb --user
To trigger the debugger, add this to the code you want to debug:
import sys if sys.__stdin__.isatty(): import pdb; pdb.set_trace()
Nota
The condition
sys.__stdin__.isatty()is a workaround for detecting whether you are running Odoo from a shell.Next, save the file and run the Odoo shell:
odoo-bin shell
Use the Odoo shell to trigger the code you want to debug.
Moduli secondarii¶
Git submodules let you link external repositories directly into your project without copy-pasting code, streamlining deployment by cloning dependencies alongside your main codebase. You maintain precise version control by choosing exact branches and pinning specific commit revisions to update whenever you choose.
On Odoo.sh, the platform automatically detects submodules and adds them to your addons path for database installation, provided you configure a deploy key in your project and repository settings when integrating private repositories.
Aggiungere un modulo secondario¶
Nota
Currently, it is not possible to add private repositories with Odoo.sh. You can nevertheless do so with Git.
From the Branches view of your Odoo.sh project, choose the branch in which you want to add a submodule.
In the upper right corner, click Submodule, then Run on Odoo.sh.
In the dialog box, fill in the following:
Repository URL: the SSH URL of the repository
Suggerimento
On GitHub, click Clone, select SSH, and copy the URL.
Branch: the specific branch that should be used
Path: the folder in which the submodule should be added to in your branch
In un terminale, nella cartella dove viene clonato il registro Git, verifica il ramo al quale vuoi aggiungere il modulo secondario:
git checkout <branch>
Add the submodule:
git submodule add -b <branch> <git@yourprovider.com>:<username/repository.git> <path>
<git@yourprovider.com>:<username/repository.git>: the SSH URL of the repository you want to add as a submodule
<branch>: the branch you want to use in the above repository
<path>: the folder in which you want to add this submodule
Commit and push the changes:
git commit -a && git push -u <remote> <branch><remote>: the repository on which you want to push your changes. On a standard Git setup, this is origin.
<branch>: the branch on which you want to push your changes. Most likely, the branch you checked out in the first step.
Suggerimento
When adding a repository that contains many modules, you may want to ignore some of them if any
are installed automatically. To do so, prefix your submodule folder with a . (e.g.
.folder). The platform will ignore this folder, and you can hand-pick the modules by creating
symbolic links to them from another folder.
Azioni programmate¶
On the Odoo.sh platform, scheduled actions are implemented slightly differently from a regular Odoo server and are run on a best-effort basis. This is because there might be multiple customers on the same server, and each customer is guaranteed a fair share of the server’s resources. Therefore, an exact running time for scheduled actions cannot be guaranteed.
Importante
Do not expect any scheduled action to be run more often than every five minutes.
As the execution time of scheduled actions is limited, it is advised to ensure your scheduled actions:
Work on small batches of records.
Commit their work after processing each batch so that if they are interrupted by the time limit, they do not need to start over.
Are idempotent, i.e, they must not cause side effects if they are started more often than expected.