[ADD] odoo_sh: documentation for the new features of Odoo.sh

This commit is contained in:
Denis Ledoux 2018-12-27 12:22:08 +01:00
parent cdc99e7a66
commit d444c8652f
21 changed files with 324 additions and 41 deletions

View File

@ -12,4 +12,5 @@ Get started
getting_started/builds
getting_started/status
getting_started/settings
getting_started/online-editor
getting_started/first_module

View File

@ -181,11 +181,25 @@ and open a shell on your database by typing :code:`psql`.
.. image:: ./media/interface-branches-shell.png
:align: center
You can open multiple tabs and drag-and-drop them to arrange the layout as you wish,
for instance side by side.
.. Note::
Long running shell instances are not guaranteed. Idle shells can be
disconnected at anytime in order to free up resources.
Editor
------
An online integrated development environment (IDE) to edit the source code.
You can also open terminals, Python consoles and even Odoo Shell consoles.
.. image:: ./media/interface-branches-editor.png
:align: center
You can open multiple tabs and drag-and-drop them to arrange the layout as you wish,
for instance side by side.
Logs
----
A viewer to have a look to your server logs.

View File

@ -117,6 +117,8 @@ in the dropdown menu of the *Connect* button.
.. image:: ./media/interface-builds-build-dropdown.png
:align: center
.. _odoosh-gettingstarted-builds-dropdown-menu:
In the dropdown menu of the build, you can access the same features than in :ref:`the branches view <odoosh-gettingstarted-branches-tabs>`:
*Logs*, *Web Shell*, *Outgoing e-mails*.
*Logs*, *Web Shell*, *Editor*, *Outgoing e-mails*.
You also have the possibility to *Download a dump* of the build's database.

View File

@ -27,7 +27,38 @@ Replace these by the values of your choice.
Create the development branch
=============================
Clone your Github repository on your machine:
From Odoo.sh
-------------
In the branches view:
* hit the :code:`+` button next to the development stage,
* choose the branch *master* in the *Fork* selection,
* type *feature-1* in the *To* input.
|pic1| |pic2|
.. |pic1| image:: ./media/firstmodule-development-+.png
:width: 45%
.. |pic2| image:: ./media/firstmodule-development-fork.png
:width: 45%
Once the build created, you can access the editor and browse to the folder *~/src/user* to access
to the code of your development branch.
.. image:: ./media/firstmodule-development-editor.png
:align: center
.. image:: ./media/firstmodule-development-editor-interface.png
:align: center
From your computer
------------------
Clone your Github repository on your computer:
.. code-block:: bash
@ -50,20 +81,25 @@ Scaffolding the module
----------------------
While not necessary, scaffolding avoids the tedium of setting the basic Odoo module structure.
It nevertheless requires *odoo-bin*, and therefore the
`installation of Odoo <https://www.odoo.com/documentation/11.0/setup/install.html#source-install>`_ on your machine.
You can scaffold a new module using the executable *odoo-bin*.
If you do not want to bother installing Odoo on your machine,
you can also :download:`download this module structure template <media/my_module.zip>` in which you replace every occurrences of
*my_module* to the name of your choice.
From the Odoo.sh editor, in a terminal:
Use *odoo-bin scaffold* to generate the module structure in your repository:
.. code-block:: bash
$ odoo-bin scaffold my_module ~/src/user/
Or, from your computer, if you have an `installation of Odoo <https://www.odoo.com/documentation/11.0/setup/install.html#source-install>`_:
.. code-block:: bash
$ ./odoo-bin scaffold my_module ~/src/odoo-addons/
This will generate the below structure:
If you do not want to bother installing Odoo on your computer,
you can also :download:`download this module structure template <media/my_module.zip>` in which you replace every occurrences of
*my_module* to the name of your choice.
The below structure will be generated:
::
@ -134,12 +170,28 @@ Commit your changes
Push your changes to your remote repository
From an Odoo.sh editor terminal:
.. code-block:: bash
$ git push https HEAD:feature-1
The above command is explained in the section
:ref:`Commit & Push your changes
<odoosh-gettingstarted-online-editor>` of the
:ref:`Online Editor <odoosh-gettingstarted-online-editor>`
chapter.
It includes the explanation regarding the fact you will be prompted to type your username and password,
and what to do if you use the two-factor authentication.
Or, from your computer terminal:
.. code-block:: bash
$ git push -u origin feature-1
You need to specify *-u origin feature-1* for the first push only.
From that point, to push your future changes, you can simply use
From that point, to push your future changes from your computer, you can simply use
.. code-block:: bash
@ -262,13 +314,14 @@ Add a change
This section explains how to add a change in your module by adding a new field in a model and deploy it.
In your module, edit the file *models/models.py*
From the Odoo.sh editor,
* browse to your module folder *~/src/user/my_module*,
* then, open the file *models/models.py*.
.. code-block:: bash
$ nano ~/src/odoo-addons/my_module/models/models.py
We encourage you to use the editor of your choice, such as *Atom*, *Sublime Text*, *PyCharm*, instead of *nano*.
Or, from your computer,
* use the file browser of your choice to browse to your module folder *~/src/odoo-addons/my_module*,
* then, open the file *models/models.py* using the editor of your choice,
such as *Atom*, *Sublime Text*, *PyCharm*, *vim*, ...
Then, after the description field
@ -282,11 +335,7 @@ Add a datetime field
start_datetime = fields.Datetime('Start time', default=lambda self: fields.Datetime.now())
Then, edit the file *views/views.xml*
.. code-block:: bash
$ nano ~/src/odoo-addons/my_module/views/views.xml
Then, open the file *views/views.xml*.
After
@ -309,11 +358,7 @@ these changes requires the module to be updated.
If you would like the update to be performed automatically by the Odoo.sh platform when you push your changes,
increase your module version in its manifest.
Edit the module manifest
.. code-block:: bash
$ nano ~/src/odoo-addons/my_module/__manifest__.py
Open the module manifest *__manifest__.py*.
Replace
@ -329,11 +374,24 @@ with
The platform will detect the change of version and trigger the update of the module upon the new revision deployment.
Stage your changes to be committed
Browse to your Git folder.
Then, from an Odoo.sh terminal:
.. code-block:: bash
$ cd ~/src/user/
Or, from your computer terminal:
.. code-block:: bash
$ cd ~/src/odoo-addons/
Then, stage your changes to be committed
.. code-block:: bash
$ git add my_module
Commit your changes
@ -342,7 +400,15 @@ Commit your changes
$ git commit -m "[ADD] my_module: add the start_datetime field to the model my_module.my_module"
Push your changes
Push your changes:
From an Odoo.sh terminal:
.. code-block:: bash
$ git push https HEAD:feature-1
Or, from your computer terminal:
.. code-block:: bash
@ -371,9 +437,9 @@ your module.
Create a file *requirements.txt* in the root folder of your repository
.. code-block:: bash
From the Odoo.sh editor, create and open the file ~/src/user/requirements.txt.
$ nano ~/src/odoo-addons/requirements.txt
Or, from your computer, create and open the file ~/src/odoo-addons/requirements.txt.
Add
@ -384,11 +450,7 @@ Add
Then use the library in your module, for instance to remove any special characters in the name field of your
model.
Edit the file *models/models.py*
.. code-block:: bash
$ nano ~/src/odoo-addons/my_module/models/models.py
Open the file *models/models.py*.
Before
@ -426,11 +488,7 @@ Add
Adding a Python dependency requires a module version increase for the platform to install it.
Edit the module manifest
.. code-block:: bash
$ nano ~/src/odoo-addons/my_module/__manifest__.py
Edit the module manifest *__manifest__.py*
Replace
@ -444,11 +502,24 @@ with
'version': '0.3',
Then stage, commit and push your changes
Stage and commit your changes:
.. code-block:: bash
$ git add requirements.txt
$ git add my_module
$ git commit -m "[IMP] my_module: automatically remove special chars in my_module.my_module name field"
Then, push your changes:
In an Odoo.sh terminal:
.. code-block:: bash
$ git push https HEAD:feature-1
In your computer terminal:
.. code-block:: bash
$ git push

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -0,0 +1,195 @@
:banner: banners/odoo-sh.jpg
.. _odoosh-gettingstarted-online-editor:
==================================
Online Editor
==================================
Overview
========
The online editor allows you to edit 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
`Notebooks <https://jupyterlab.readthedocs.io/en/stable/user/notebook.html>`_.
.. image:: ./media/interface-editor.png
:align: center
You can access the editor of a build through
:ref:`the branches tabs <odoosh-gettingstarted-branches-tabs>`,
:ref:`the builds dropdown menu <odoosh-gettingstarted-builds-dropdown-menu>`
or by adding */odoo-sh/editor* to your build domain name
(e.g. *https://odoo-addons-master-1.dev.odoo.com/odoo-sh/editor*).
Edit the source code
====================
The working directory is composed of the following folders:
::
.
├── 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
│ ├── repositories The Git repositories used by your project
│ ├── 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*) in 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.
* The source code of your Github repository is located under */src/user*,
* The source code of Odoo is located under
* */src/odoo* (`odoo/odoo <https://github.com/odoo/odoo>`_),
* */src/enterprise* (`odoo/enterprise <https://github.com/odoo/enterprise>`_),
* */src/themes* (`odoo/design-themes <https://github.com/odoo/design-themes>`_).
To open a file in the editor, just double-click on it in the file browser panel on the left.
.. image:: ./media/interface-editor-open-file.png
:align: center
You can then begin to make your changes. You can save your changes with the menu
:menuselection:`File --> Save .. File` or by hitting the :kbd:`Ctrl+S` shortcut.
.. image:: ./media/interface-editor-save-file.png
:align: center
If you save a Python file which is under your Odoo server addons path,
Odoo will detect it and reload automatically so your changes are reflected immediately,
without having to restart the server manually.
.. image:: ./media/interface-editor-automaticreload.gif
:align: center
However, if the change is a data stored in database, such as the label of a field, or a view,
you have to update the according module to apply the change.
You can update the module of the currently opened file by using the menu
:menuselection:`Odoo --> Update current module`. Note that the file considered as currently opened
is the file focused in the text editor, not the file highlighted in the file browser.
.. image:: ./media/interface-editor-update-current-module.png
:align: center
You can also open a terminal and execute the command:
.. code-block:: bash
$ odoo-bin -u <comma-separated module names> --stop-after-init
.. _odoosh-gettingstarted-online-editor-push:
Commit & Push your changes
==========================
You have the possibility to commit and push your changes to your Github repository.
* Open a terminal (:menuselection:`File --> New --> Terminal`),
* Change the directory to *~/src/user* using :code:`cd ~/src/user`,
* Stage your changes using :code:`git add`,
* Commit your changes using :code:`git commit`,
* Push your changes using :code:`git push https HEAD:<branch>`.
In this last 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 in a development build.
.. image:: ./media/interface-editor-commit-push.png
:align: center
.. Note::
The SSH Github remote is not used because your SSH private key
is not hosted in your build containers (for obvious security concerns)
nor forwarded through an SSH Agent (as you access this editor through a web browser)
and you therefore cannot authenticate yourself to Github using SSH.
You have to use the HTTPS remote of your Github repository to push your changes,
which is added automatically named as *https* in your Git remotes.
You will be prompted to enter your Github username and password.
If you activated the two-factor authentication on Github,
you can create a
`personal access token <https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/>`_
and use it as password.
.. Note::
The Git 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.
In other words, this means you can have multiple builds on the same branch, but on different revisions.
Once your changes are pushed,
according to your :ref:`branch push behavior <odoosh-gettingstarted-branches-tabs-settings>`,
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, but always make sure to be
in an editor of a build using the latest revision of your branch.
Consoles
========
You can open Python consoles, which are
`IPython interactive shells <https://ipython.readthedocs.io/en/stable/interactive/tutorial.html>`_.
One of the most interesting addition to use a Python console
rather than a IPython shell within a terminal is the
`rich display <https://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display>`_
capabilities.
Thanks to this, you will be able to display objects in HTML.
You can for instance display cells of a CSV file using
`pandas <https://pandas.pydata.org/pandas-docs/stable/tutorials.html>`_.
.. image:: ./media/interface-editor-console-python-read-csv.png
:align: center
You can also open an Odoo Shell console to play around
with the Odoo registry and model methods of your database. You can also directly read or write
on your records.
.. Warning::
In an Odoo Console, transactions are automatically committed.
This means, for instance, that changes in records are applied effectively in the database.
If you change the name of a user, the name of the user is changed in your database
as well.
You therefore should use Odoo consoles carefully on production databases.
You can use *env* to invoke models of your database registry, e.g. :code:`env['res.users']`.
.. code-block:: python
env['res.users'].search_read([], ['name', 'email', 'login'])
[{'id': 2,
'login': 'admin',
'name': 'Administrator',
'email': 'admin@example.com'}]
The class :code:`Pretty` gives you the possibility
to easily display lists and dicts in a pretty way, using the
`rich display <https://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display>`_
mentioned above.
.. image:: ./media/interface-editor-console-odoo-pretty.png
:align: center
You can also use
`pandas <https://pandas.pydata.org/pandas-docs/stable/tutorials.html>`_
to display graphs.
.. image:: ./media/interface-editor-console-odoo-graph.png
:align: center