Online editor

The Online Editor view allows editing the source code of your builds from a web browser. It also gives you the possibility to open terminals, Python consoles, Odoo shell consoles, and Jupyter Notebooks.

Overview of the online editor

You can access the editor of a build through the branches tab, the builds dropdown menu, or by adding /odoo-sh/editor to the build’s URL (e.g., https://odoo-addons-master-1.dev.odoo.com/odoo-sh/editor).

Editing the source code

The working directory is composed of the following:

.
├── home
│    └── odoo
│         ├── 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
│         ├── 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

You can edit the source code (files under /src) of development and staging builds. For production builds, the source code is read-only, because applying local changes on a production server is not a good practice.

備註

To open a file in the editor, double-click it in the file browser panel. You can then edit the file. To save your changes, go to File ‣ Save or use the Ctrl+S keyboard shortcut.

If you save a Python file in your Odoo server’s addons path, Odoo will detect it and reload automatically, meaning your changes are immediately visible.

Change to a Python file being immediately visible

However, if your changes are stored in the database, such as a field’s label or a view, it is necessary to update the related module to apply the changes. To update the module of the currently1 open file, go to Odoo ‣ Update current module.

Using the editor to update the current module

小訣竅

You can also execute the following command in a terminal to update a module:

odoo-bin -u <comma-separated module names> --stop-after-init

Committing and pushing changes

To commit and push changes to your GitHub repository:

  • Open a terminal by going to File ‣ New ‣ Terminal.

  • Change the directory to ~/src/user.

    cd ~/src/user
    
  • State your identity.

    git config --global user.email "you@example.com" && git config --global user.name "Your Name"
    
  • Stage your changes.

    git add
    
  • Commit your changes.

    git commit
    
  • Push your changes.

    git push https HEAD:<branch>
    

    In this command:

    • https is the name of your HTTPS GitHub remote repository (e.g., https://github.com/username/repository.git).

    • HEAD is the reference to the latest revision you committed.

    • <branch> must be replaced by the name of the branch to which you want to push the changes, most likely the current branch if you work on a development build.

You will be prompted to input your GitHub username and password. After inputting your credentials, press enter.

The commands to commit and push changes

小訣竅

If you activate two-factor authentication for your GitHub account, you can create a personal access token and use it as a password. Granting the repo permission suffices.

備註

  • It is not possible to authenticate yourself using SSH, as your private SSH key is not hosted in your build containers for security reasons, nor forwarded through an SSH agent, as you access the editor through a web browser.

  • The source folder ~/src/user is not checked out on a branch but rather on a detached revision. This is because builds work on specific revisions rather than branches, meaning you can have multiple builds on the same branch, but on different revisions.

Once your changes are pushed, according to your branch push behavior, a new build may be created. You can continue to work in the editor you pushed from, as it will have the same revision as the new build that was created. However, always make sure to be in the editor of a build using the latest revision of your branch.

You can open Python consoles, which are IPython interactive shells. Using these Python consoles (rather than IPython shells within a terminal) allows you to utilize their rich display capabilities to display objects in HTML.

Example

The Pretty class displays lists in a legible way.

Pretty class example

小訣竅

Using pandas you can display:

  • Cells of a CSV file

    pandas CSV example
  • Graphs

    pandas graph example

You can open Odoo shell consoles to experiment with the Odoo registry and model methods of your database. You can also read or write directly on your records.

警告

In an Odoo shell console, transactions are automatically committed. This means that changes made to records are applied to the database. For example, if you change a user’s name, it will be updated in your database as well. Therefore, use Odoo shell consoles carefully on production databases.

You can use env to invoke models of your database registry, e.g., env['res.users'].

env['res.users'].search_read([], ['name', 'email', 'login'])
[{'id': 2,
'login': 'admin',
'name': 'Administrator',
'email': 'admin@example.com'}]