Advanced topics

This section covers advanced features of Odoo.sh related to containers, Git submodules, and scheduled actions.

Conteneurs

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.

Voir également

Note

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.

Structure du répertoire

As the containers are Ubuntu-based, their directory structure follows the Filesystem Hierarchy Standard.

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 de base de données

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=>

Avertissement

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

Faire fonctionner un serveur 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:

  • Utiliser le shell Odoo :

    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'
    
  • Installer un module :

    odoo-bin -i sale --without-demo=all --stop-after-init
    

    Astuce

    • L’argument --without-demo=all empêche le chargement des données de démonstration pour tous les modules.

    • L’argument --stop-after-init arrête immédiatement l’instance du serveur une fois l’opération terminée.

  • Mettre à jour un module :

    odoo-bin -u sale --stop-after-init
    
  • Exécuter les tests d’un module :

    odoo-bin -i sale --test-enable --log-level=test --stop-after-init
    

Voir également

Documentation CLI

Pour trouver le chemin des addons utilisé par Odoo.sh pour exécuter votre serveur, recherchez « odoo: addons paths » dans les journaux (~/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']

Avertissement

Les opérations effectuées sur une instance de serveur Odoo ne sont pas isolées ; les modifications seront répercutées dans la base de données. N’oubliez pas de toujours effectuer les tests dans vos bases de données de transition.

Débogage dans Odoo.sh

Note

Déboguer une build Odoo.sh n’est pas vraiment différent du débogage d’une autre application Python. Ainsi, l’objectif de cette section est de couvrir les spécificités et les limites de la plateforme Odoo.sh, en supposant que vous savez déjà utiliser un débogueur.

Vous pouvez utiliser pdb, pudb ou ipdb pour déboguer le code sur Odoo.sh. Comme le serveur s’exécute en dehors d’un shell, vous ne pouvez pas lancer le débogueur directement depuis votre backend Odoo, car cela nécessite un shell pour fonctionner.

pdb est installé par défaut dans chaque conteneur.

Astuce

Pour utiliser pudb ou ipdb, il est nécessaire de les installer soit :

  • de façon permanente en ajoutant pudb ou ipdb au fichier requirements.txt de votre projet, ou

  • de façon temporaire (uniquement dans la build actuelle) en exécutant la commande appropriée :

    pip install pudb --user
    
    pip install ipdb --user
    
  1. Pour déclencher le débogueur, ajoutez ceci au code que vous souhaitez déboguer :

    import sys
    if sys.__stdin__.isatty():
        import pdb; pdb.set_trace()
    

    Note

    La condition sys.__stdin__.isatty() est une solution de contournement permettant de détecter si vous exécutez Odoo à partir d’un shell.

  2. Ensuite, enregistrez le fichier et exécutez le shell Odoo :

    odoo-bin shell
    
  3. Utilisez le shell Odoo pour déclencher le code que vous souhaitez déboguer.

    pdb en cours d'exécution dans un shell Odoo.sh

Sous-modules

Les sous-modules Git vous permettent de lier des dépôts externes directement à votre projet sans copier-coller de code, ce qui simplifie le déploiement en clonant les dépendances aux côtés de votre code source principal. Vous conservez un contrôle précis des versions en choisissant des branches exactes et en épinglant des révisions de commit spécifiques à mettre à jour quand vous le souhaitez.

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.

Ajouter un sous-module

Note

Currently, it is not possible to add private repositories with Odoo.sh. You can nevertheless do so with Git.

  1. From the Branches view of your Odoo.sh project, choose the branch in which you want to add a submodule.

  2. In the upper right corner, click Submodule, then Run on Odoo.sh.

  3. In the dialog box, fill in the following:

    • Repository URL: the SSH URL of the repository

      Astuce

      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

Astuce

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.

Actions planifiées

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.

Important

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.