In this tutorial I will learn you how to install Odoo 12 community or enterprise on Ubuntu 18.04. The script that you will use is based on the code from André Schenkels but has been updated, upgraded and improved. Do notice that if you want to install the enterprise version that you will need to be an official partner or that you need to have bought the enterprise subscription from Odoo. Otherwise you will have no access to the Github repository for the enterprise code!

1. Downloading the script

The first step is to download my script from Github and to add the code in a new .sh file on your Ubuntu machine, wherever you’d like this.
For example right under /home. Open up an Ubuntu terminal and cd to the directory where you’d like to keep the script and then create the file:

If you’re curious about how the whole code looks and works you can find it on my Github account.
Now open up the file and edit the parameters to your liking:

Open install script

Python

1

sudo nano odoo_install.sh

There are some things you can configure/change to your likings at the top of the script. You can choose if you wish to install Wkhtmltopdf or not, which version you’d like, where the location is and most importantly what the master admin password is.Tip: always modify this for every Odoo you install!
If you want the enterprise version of V12 you should change the line IS_ENTERPRISE to true:

Enterprise activation

Python

1

IS_ENTERPRISE="True"

If you want the community version you can just continue and keep the IS_ENTERPRISE key on “False” (which is the case by default):

Enterprise activation

Python

1

IS_ENTERPRISE="False"

2. Making the Odoo installation file executable

The next step is to make this file executable. After you’ve made it executable you can execute it and everything will be installed automatically.
do this with the following command:

Installation script executable

Python

1

sudo chmod+xodoo_install.sh

3.Running the script

Now that the code is in your file and the file is executable you simply have to execute it with the following command:

install odoo 12

Python

1

./odoo_install.sh

You will see that the script automatically starts updates, downloads required packages, creates the user, downloads the code from Github, … Eventually, if you’ve chosen to install the enterprise version, you will need to give in your Github credentials to download the enterprise code (since this is a private repository). Fill in your details and let the script continue:
Give the script a few minutes to configure and install everything and eventually you will see something like this:

You now have a fully functional Odoo V12 community or enterprise on your system! Congratulations.

4. Extra information about Odoo 12 Enterprise

Since Odoo Enterprise uses code from both http://github.com/odoo/odoo and http://github.com/odoo/enterprise we will separate the code with this script. This will make future upgrades easier and the code is nicely separated. This means that the default V12 code will be under /odoo/odoo-server/ and all the enterprise code will be under /odoo/enterprise/.

In the script you saw there was an option to change the Odoo port (OE_PORT). When you’d change this port number to 8070 in the install script it would be applied to /etc/your-config-file.conf and this would give you the ability to change the default port.
To apply these changes you should do the following:
The -c will change the configuration and memorize what you’ve changed under /etc/your-config-file.conf. Because my port was set to 8070 this is telling the Odoo that it should run on port 8070. When you would now open up your browser and navigate to http://localhost:8070/ you will see it is running there:

Has this tutorial helped you, do you have any feedback or questions? Post away!

Share this:

Like this:

In this tutorial I will learn you how to create new building blocks and how to add the blocks to the menu so that you can quickly drag and drop the blocks in the webpage.
In this tutorial I will create a new building block named “References with title” which will show four icons and a title above it:

1. Adding the dependency

Before you can start creating a new building block you will need to create a new module and configure the manifest.py correctly. Open up your manifest.py and add the website as a dependency:

Add website dependency

Python

1

2

# The website module has to be installed and is needed to add a building block

depends': ['website'],

Without this dependency you cannot create and add new building blocks to the Odoo website.

2. Creating a new XML file

Now create a new XML file named “snippets.xml” under the “views” folder:
In this file we will add all the code to create the building block (snippet) and to make it visible in the editor.

2.1 Creating the building blocks

First we will need to create the building block itself. Let us create a building block that has a title (h3) saying “Our references” with four logo’s under the title. Have a look at this code:

So, what does this tell us? We first create a new XML record. After doing this we add all our code within a section block and inside this we create a container div. Within this section and container you can basically code anything you like, this is the framework for any building block. Generally when you create a building block you try to use as much bootstrap classes as possible. In the above example I simply made two rows. One row for the title and one row for the images. Those images are all the same width thanks to the default bootstrap classes col-md, col-sm and col-xs-6.
You’re already well over halfway to your own building block! If you would install this module right now all the code would be there that is needed for a building block, but we still have to show it in the editor so that we can use it.

2.2 Adding the building block to the editor

Let us continue and add a building block preview to the editor so you can quickly find it from the editor.
You can do this by inheriting the default “website.snippets” record and doing an xpath in the “snippet_structure” id, which holds the main structure of the editor. Have a look at this code:

Add building block to editor

Python

1

2

3

4

5

6

7

8

9

<!--This record will createapreview of the building block inthe left menu fromwhere you choose the blocks-->

<template id="add_title_references_to_bar"inherit_id="website.snippets"name="Place into building blocks bar">

<xpath expr="//div[@id='snippet_structure']"position="inside">

<div class="o_panel_body">

<tt-snippet="website_snippet_demo.s_title_references"

t-thumbnail="/website/static/src/img/blocks/block_references.png"/>

</div>

</xpath>

</template>

Let me explain the code a bit further. We first inherit the default ‘website.snippets’ record, which holds the link to all available snippets. By doing an xpath on ‘snippet_structure’ we’re telling Odoo to add our building block preview within the editor. In this xpath element we add a div and we use the t-snippet element made by Odoo. By doing so Odoo knows we want to add a snippet preview to the editor.
Finally save this file and add it in the manifest.py file so that it is loaded:

load snippet page

Python

1

2

3

4

5

# always loaded

'data':[

# Load the snippets (building block code) when installing

'views/snippets.xml',

]

When you now install the module you will see your new building block is available for use from the editor:
That is all. You’ve just made your own building block, congratulations!

3. Conclusion

Thanks to the Odoo framework it is very easy to create and use new building blocks. The functionality is so flexible and easy to use that you can create a building block for about anything. Creating and reusing building blocks in Odoo is one of the biggest strengths of the Odoo website editor.

Do you want to try the demo code and see the source code of this tutorial? You can view it on my Github account.
Has this tutorial helped you, do you have any feedback or questions? Post away!

Share this:

Like this:

In this tutorial I will learn you how to create and use submodules in Odoo.sh. In this example I will create a public submodule and a private submodule and I will link them to the Odoo.sh project.

1. Introduction to submodules

Tip: If you haven’t made an Odoo.sh project yet you can follow my tutorial here.
So, what exactly is a submodule? A submodule is a link from one Github repository to another repository. You can see it as a virtual pointer to a specific commit in time of the remote repository.

For Odoo.sh there are two major differences. You have public submodules and private submodules. Public repositories are those that are publicly available (for example https://github.com/odoo/odoo). Private repositories are the repositories that are not publicly available. Usually you have private repositories when you work for a company and when you manage customer code.
There is a big difference in using public or private submodules on Odoo.sh though. When you have a public repository you can easily add the submodule and it will work. For a private repository you will need to generate a deploy key on Odoo.sh and then add it on the remote Github repository.

1.1 Why use submodules?

Now we know what a submodule is but the question is why would you use a submodule? Submodules are very handy to use if you want to include third party apps in your Odoo.sh tests. The only other way to get this code available in your Odoo.sh builds is to add all this third party code in your own repository. But what if the third party developer has made a lot of changes, fixes or improvements? If you don’t use submodules you will constantly need to download the remote apps, add them to your own repository and keep track of all those changes. This is the true power of submodules. Now let us first link a public repository to the Odoo.sh project in chapter 2. In chapter 3 I will learn you how to add a private repository as a submodule.

2. Public repositories

Setting up public repositories is really very easy to do.
You will need to create a submodule and commit it to Github. Go to your Github repository, switch to the correct branch and add the submodule from the command line:

add submodule command

Python

1

2

3

4

git submodule-b11.0add git@github.com:oca/hr.git

git add-A&&git commit-m"[ADD] submodule: add OCA/hr as submodule"

git push

This new commit will trigger a new Odoo.sh build. After this build is ready you will see that the modules from the OCA/hr repository are available on this instance:
Great job! This is all you need for a public repository. If you also have a private repository and want to add it then continue to the next chapter.

3. Private repositories

Alright now let us configure the use of a private submodule! Go back to your Odoo.sh project to the settings tab and add the link to your private repository (git@github.com:youruser/repository.git). In your repository you could now make a commit to add the repository as a submodule. For a private repository however you have some extra work. You have to copy the generated key from the Odoo.sh project and add it on Github. First copy the key:
Now go to the repository where you’ve linked to (so the submodule), go to the settings tab, open “Deploy keys” and add your own key here by clicking on “Deploy key”:
Now add the key in the next screen and click on “Add key”:
After doing this Odoo.sh can find the private repository and can access all the data it needs. The final thing you need to do is to add the submodule from the command line, commit it and push it to Github:

This new commit will trigger a new Odoo.sh build. After this build is ready you will see that the modules from your other private repository are available on this instance.

4. Conclusion

Using submodules in combination with Odoo.sh is very powerfull and handy to use. Setting it up in the beginning might take some time and you can make some mistakes but in the long run it will save you a load of time and redundant code. As a result it’ll improve your testing a lot as all your custom code will be automatically tested.
If you can use submodules and want to test your deployments on Odoo.sh then submodules are the way to go.
Has this tutorial helped you, do you have any feedback or questions? Post away!

Share this:

Like this:

In this tutorial I will teach you how to separate your Odoo frontend and backend. I will install the Odoo codebase/frontend on one server and the backend (your PostgreSQL server and database) on another server. You will learn how to configure both Odoo and PostgreSQL to achieve this.

1. Introduction

In order to achieve and demonstrate this setup to you I will be working with two virtual machines.
I will refer to the Odoo codebase/frontend server as the ‘frontend server’. The PostgreSQL server and database will be named ‘backend server’ throughout this tutorial.
My frontend server has the IP 192.168.118.167 and my backend server has the IP 192.168.118.168.Tip: Make sure that both your servers have a fixed IP, otherwise your setup will break due to IP changes!

2. Configuring the backend server

Let us start with the configuration of the backend server. This server will contain the PostgreSQL server and the database(s).

2.1 Installing postgreSQL

Open up a terminal on your backend server and install PostgreSQL if you haven’t yet:

install PostgreSQL command

Python

1

sudo apt-get install postgresql-y

2.2 Creating the PostgreSQL user

Now create a new PostgreSQL user. Make sure that the PostgreSQL username matches with the username of the user running Odoo on your frontend server. In my example I will create a new PostgreSQL user with the name “odoo11”:

Create postgreSQL user

Python

1

sudo su-postgres-c"createuser -s odoo11 -P"

After you execute this command the system will ask you for a password for this user. Fill in a password and confirm this password again.Tip: Don’t forget to remember this password, you’ll need it later on.

2.3 Configuring pg_hba.conf

After installing the PostgreSQL server and creating the user we now need to configure the remote connections. As our backend server will be used for the database connections our frontend server needs to be able to access it. Open up your frontend server and get the IP of the server. In my example my frontend server has the IP 192.168.118.167. Now open up your pg_hba.conf file on your backend server:

edit ph_hba.conf

Python

1

sudo nano/etc/postgresql/9.5/main/pg_hba.conf

Scroll in this file and search for the following line of code:

Default pg_hba.conf

Python

1

2

# IPv4 local connections:

host allall127.0.0.1/32md5

Add a new line after the existing one which contains your frontend server its IP address. As you don’t want to use the exact IP address you should use the /24 subdomain. In my example this results to 192.168.118.0/24 instead of 192.168.118.167. Your configuration file should now look like this:

pg_hba file configuration

Python

1

2

3

4

# IPv4 local connections:

host allall127.0.0.1/32md5

host allall192.168.118.0/24md5

Finally, save your file and close it. Your PostgreSQL now knows that you want to allow connections from the backend server (IP 192.168.118.167).

2.4 Configuring postgresql.conf

Your PostgreSQL still needs to know the listen address of your frontend server too though. To achieve this we have to edit the postgresql.conf file:

Tip: Don’t forget to remove the # in this line because otherwise this line will be skipped!
Save this file and close it.
You’ve now applied all the changes that you need to do on the backend server. Next reload the PostgreSQL service in order to apply all the changes:

Reload PostgreSQL

Python

1

sudo service postgresql reload

3. Configuring the frontend server

Your backend server is done now. Switch to the frontend server and open up your Odoo configuration file.Tip: If you haven’t installed an Odoo yet you can follow my tutorial here
Typically your Odoo configuration file is under /etc/ and is named your-odoo.conf:

Edit Odoo configuration file

Python

1

sudo nano/etc/odoo11-server.conf

Add or change the following parameters in the configuration file:

odoo configuration parameters

Python

1

2

3

4

5

6

[options]

admin_passwd=mysupersecretpassword

db_host=192.168.118.168# This is the IP of the backend server

db_port=5432

db_user=odoo11# The PostgreSQL user you've configured in chapter 2.2.

db_password=yourpassword# The PostgreSQL user his password you've set in chapter 2.2

Finally, restart your Odoo service to reload your Odoo configuration:

Restart Odoo service

Python

1

sudo service odoo11-server restart

When you now browse to your Odoo instance (on your frontend server) you’ll see that your new Odoo is ready to use.
That is all! You’ve now setup your own Odoo instance where the frontend and backend are split between two servers.

4. Tips

While this is everything that you need in order to split up the backend and frontend of Odoo there are still some things to consider.
Because of security reasons you’ll most likely want to encrypt all the data and place everything on SSL. This also includes the calls from the frontend server to the backend server.
After you’ve created a new database you should check if the database is in fact created on the backend server instead of on the frontend server. You can do this executing the following commands (one by one) on your backend server:

See databases commands

Python

1

2

3

sudo su postgres

psql

\l

After running these commands you can see an overview of your databases and to what user the database belongs. In my example you can see a new database named ‘ABC’ which is owned by my Odoo/PostgreSQL user ‘odoo11’:

5. Conclusion

Setting up an Odoo instance where the frontend and the backend are split is actually quite easy. Due to the built-in parameters from Odoo it is very easy to configure the frontend side. When you split the frontend and backend up and apply extra security – such as HTTPS connections and VLAN’s – you’ll have a safer and more controlable Odoo instance.
If you’d like to learn more about the deployment of servers and the default Odoo parameters you can have a look at the official documentation.

Has this tutorial helped you, do you have any feedback or questions? Post away!

Share this:

Like this:

In this tutorial I will learn you how to setup an Odoo.sh account, how to configure Odoo.sh and how to tests your code automatically with Odoo.sh.
In this example I will create a new account, create a new repository and add code to the Github repository in order to explain how Odoo.sh works.

1. Creating an Odoo.sh account

Go to odoo.sh and click on the “Sign in” button at the top:
When you click on the “Sign in button” you’ll get an authorize screen from Github. If you’re not yet logged in on Github it will ask you to login, if you’re already logged in on Github you’ll get the authorize screen. Click on “Authorize odoo”:
After you click on “Authorize odoo” Github will ask for additional permissions. Click on “Authorize Odoo” again to give the additional permissions. Because of these additional permissions Odoo.sh can follow all changes and handle it automatically for you.
Now Odoo will ask you to deploy your platform. Choose an existing repository if you want to use it or create a new one. In this tutorial I will create a new repository to show everything in detail. Choose a repository name. Next choose the Odoo version you want to test against and finally provide your enterprise (or partner) license. The hosting location is up to you. Finally click on “Deploy”:
Thats it! You’ve just registered your own Odoosh account and connected Github to Odoosh!

2. The Odoo.sh main screen

After you’ve clicked on “Deploy” you’ll now see the main screen of Odoo.sh.
In the left menu you will see the title “DEVELOPMENT”. Under this section you will see every branch you’ve made on this Github repository. If I would create a second branch named “11.0” I would see “11.0” and “master” in the left menu. At the top you’ll see a main menubar with the options “Branches”, “Builds”, “Status” and “Settings.

The Branches tab opens the main page, from where you can see everything related to your branches. This includes the mails, shell access to the test instance and access to the logs.

The Builds tab opens a page where you can see all your test instances. This is almost identical to the Odoo runbot (at runbot.odoo.com).

The Status tab opens a page where you can see all the statistics of the Odoo.sh platform. It shows you the uptime and the status of all the servers.

The Settings tab opens a page where you can configure advanced settings. You can add collaborators, set a project name (and URL), add submodules and much more.

3. Github

Now open up your Github and go to your (just created) repository. Add a commit to the repository so that it contains some (new) code. In my example I will push a module to Github that contains an automated test so I can show you how tests work and what happens. If you’d like to do the same you can take my example module from Github. The moment that you make a commit to the Github repository Odoo.sh will detect this and it will start up a test environment because of the new commit. My Github after making a commit:
My Odoo.sh a few seconds after making this commit:

4. Checking the commit

Now switch back to Odoo.sh. After a few minutes your new commit will procude a new test instance that is ready and built. In my example I’ve deliberately added an error in my last commit so as a result you can see the test fail. When the test instance is done, typically after a few minutes, you’ll see the result in the main screen:

So now my test has failed it means I must have done something wrong. I’ve figured out what was wrong and I correct my test. After correcting this test I make a new commit to Github. After a few seconds you’ll see that Odoo.sh automatically detects and tests this new commit again:

5. Odoo.sh builds and test instances

Finally go to the builds page by clicking on “Builds” in the top menu bar. After you click on “Builds” you will see an overview of all your test instances and if they succeeded or not:
From this page you can directly connect to a test instance in order to test functionalities or ‘play’ with Odoo.
When a test has failed (such as “INIT: Add demo module wit…” in my screenshot) you can click on the exclamation icon, next to the connect button, to see why your instance has failed:Tip: If you want to see the full log of the instance you can do this by clicking on the “…” icon at the top of a build and selecting “Logs”. From here you can download and view all logs. Alternatively you can also do this from the “Branches” page by clicking on the “Logs” menu.

6. Conclusion

As Odoo.sh is very big and has a lot of options I’ve decided to split the content in two tutorials. Because of this the first blog post, this one, is only about basic operations. You can find a second tutorial about how to configure public and private submodules here.

Odoo.sh is a very powerfull platform to use. Odoo has invested a lot of time into Odoo.sh and due to this it is an advanced system that allows you to quickly (and easily!) use test instances with Odoo. Thanks to Odoo.sh you no longer need your own runbot instance and complex hardware setup as you can get it all out of the box.

Has this tutorial helped you, do you have any feedback or questions? Post away!

Share this:

Like this:

In this tutorial I will learn you how to write tests, how to use the tests in Odoo and how to test them. I will create an example test that creates a new project, a new task and attaches the project to the new task.Tip: This tutorial is based on Odoo V11 but will also work in V10.

1. Creating a new module

Let us create a new module to start. You can either manually create a module or create one with the scaffold command from Odoo. Now that you’ve created your module you should add the dependency to the module where you want to create a test for. In this tutorial I will create a test for the project module so I’ll add a dependency for ‘project’. Add your depends in the manifest.py (or __openerp__.py in V10):

Add dependency

Python

1

'depends':['project'],

2. Creating the Python files

After you’ve created your new module you should create a new folder named ‘tests’. Create a new Python file for the test, in this example I’ll create a new file named ‘test_project.py’.Tip: The filename of a Python test should always start with ‘test_’ or it will not be executed! Your folder structure should now look like this:

Next create a new Python file named __init__.py and import the Python file ‘test_project’ in it:

Import project test

Python

1

2

3

# -*- coding: utf-8 -*-

from.importtest_project

Your folder structure should now look like this:Tip:You should not import the tests folder in the main __init__.py file. Odoo tests are an exception and have a built-in check by Odoo. They do not need an explicit import like models or controllers.

3. Creating the class and adding imports

Now open up your ‘test_project.py’ file again and let us start by adding the import and creating the class structure!
In order to write a test you should import ‘odoo.tests’ and you should create a new class with a TransactionCase. Have a look at this code:

Basic test structure

Python

1

2

3

4

5

6

7

# -*- coding: utf-8 -*-

# Part of Odoo. See LICENSE file for full copyright and licensing details.

fromodoo.tests importcommon

classTestProject(common.TransactionCase):

So, does this make sense to you? We simply import the default Odoo framework options for tests with ‘from odoo.tests import common’. We then create a new class in which we add ‘common.TransactionCase’. The ‘common.TransactionCase’ tells Odoo that we want to test a transaction and that we want to do a rollback of this record after the test is done.

4. Writing the tests

Now that we have the basic structure setup there is just one more thing to do: write a function in which you want to do your tests. Go ahead and create a new function in your file.Tip: Function names for tests should always start with ‘test_’ or they will not be run by Odoo!

Finally, write the test cases you’d like in this function. In my example I will create a test that creates a new project, then creates a new task and then adds the project to the task. Have a look at this piece of code:

Test function

Python

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

deftest_create_data(self):

# Create a new project with the test

test_project=self.env['project.project'].create({

'name':'TestProject'

})

# Add a test task to the project

test_project_task=self.env['project.task'].create({

'name':'ExampleTask',

'project_id':test_project.id

})

# Check if the project name and the task name match

self.assertEqual(test_project.name,'TestProject')

self.assertEqual(test_project_task.name,'ExampleTask')

# Check if the project assigned to the task is in fact the correct id

self.assertEqual(test_project_task.project_id.id,test_project.id)

# Do a little print to show it visually for this demo - in production you don't really need this.

print('Your test was succesfull!')

So, does this make sense to you? A lot of the code looks the same as if you’re writing custom code. With self.env[‘project.project’].create({}) we’ll create a new project named ‘TestProject’. With self.env[‘project.task’].create({}) we’ll create a new task named ‘ExampleTask’ and we will assign the project to this task, thanks to the ‘test_project’ variable.
If you would run this code it would create a new project and task and the moment the test is finished the transaction is rolled back (so there is no record in the database).

4.1 Understanding assertEqual

The final part of my code shows some assertEqual calls, so what do these calls do? assertEqual is made available by default in Odoo to test and compare values. For example:

Example assertEqual

Python

1

self.assertEqual(test_project.name,'TestProject')

This will test if the just created project record it’s name is indeed named ‘TestProject’. In the second assertEqual I check if the task name is in fact ‘ExampleTask’. And, finally, in the third assertEqual I check if the project attached to the task is indeed the right project:

Python

1

self.assertEqual(test_project_task.project_id.id,test_project.id)

The first variable of assertEqual is always the value you’ve gotten back from the test and the second part is the result that you’re expecting. If there is a difference in those two the test will fail.

5. Running / testing the test

So now we’ve coded the whole test but how do we run and test it? In order to run a test you should use the ‘–test-enable’ parameter and the ‘-i’ parameter to say which module(s) you want to test. If you want to test this in your local Odoo instance you will need to run your Odoo from the terminal like this:

Run Odoo from terminal

Python

1

2

./odoo-bin-iautomated_test_demo--test-enable-c/etc/odoo11-server.conf

If you have a runbot instance (or use Odoo.sh) the tests will be executed automatically and you will see if the test succeeded or failed right away. An example of Odoo.sh:
An example of a runbot instance:

When you just run the tests locally you can see if the test succeeded or failed in the logfile. Open up your logfile after you’ve ran the test and have a look at the output:

If you add a print statement in the test, like in my example, you will also see it printed in the terminal:

5.1 Making a test fail

We’ve now seen how to create a test and how to run it, but how exactly does a failed test look?
Open up your test again and change the assertEqual from this:

Good assertEqual

Python

1

self.assertEqual(test_project.name,'TestProject')

to this:

Bad assertEqual

Python

1

self.assertEqual(test_project.name,'TestProject11')

Run the test from your terminal again with -i your_module –test-enable in the command. You’ll see that the print statement is no longer printed in your terminal. Now open up your logfile again after your Odoo is loaded. You’ll now find a failure in the logfile:

This shows you that the input ‘TestProject’ does not match what we expect (‘TestProject11’) and because of this our test failed.
If you would commit these changes to Github and if you’re using a runbot or Odoo.sh you’ll also see a failed instance after this.

6. Conclusion

Writing and using tests in Odoo is quite easy to do. It is a great feature to use if you’re writing a lot of custom code and want to keep overview. Thanks to Odoo.sh and runbots it is also very easy to follow up on your tests and to see if something has broken or not. Sadly at this point running tests locally isn’t very easy to follow up though so you might want to consider setting up a runbot or Odoo.sh account.
Do you want to try the demo code and see the source code of this tutorial? You can view it on my Github account.
Has this tutorial helped you, do you have any feedback or questions? Post away!