Advanced topics

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

Behållare

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.

Se även

Observera

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.

Struktur för katalog

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

Databasskal

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

Varning

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

Kör en Odoo-server

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

    Tips

    • The argument --without-demo=all prevents demo data from being loaded for all modules.

    • The argument --stop-after-init immediately 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
    

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']

Varning

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.

Felsökning i Odoo.sh

Observera

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 installeras som standard i alla behållare.

Tips

To use pudb or ipdb, it is necessary to install them either:

  • permanently by adding pudb or ipdb to your project’s requirements.txt file, or

  • temporarily (only in the current build) by running the relevant command:

    pip install pudb --user
    
    pip install ipdb --user
    
  1. To trigger the debugger, add this to the code you want to debug:

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

    Observera

    The condition sys.__stdin__.isatty() is a workaround for detecting whether you are running Odoo from a shell.

  2. Next, save the file and run the Odoo shell:

    odoo-bin shell
    
  3. Use the Odoo shell to trigger the code you want to debug.

    pdb running in an Odoo.sh shell

Undermoduler

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.

Lägga till en undermodul

Observera

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

      Tips

      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

Tips

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.

Schemalagda åtgärder

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.

Viktigt

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.