Odoo homepage screen

Installing Odoo frontend and backend on different servers

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:

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”:

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:

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

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:

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:

Find the ‘listen_addresses’ line, which looks like this by default:

Now add in the IP of your frontend Odoo server (in my example 192.168.118.192):

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:

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:

Add or change the following parameters in the configuration file:

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

When you now browse to your Odoo instance (on your frontend server) you’ll see that your new Odoo is ready to use.
Odoo homepage screen
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:

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’:
Database overview result backend

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!


PayPal

Odoo Experts

Installing and configuring Odoo on DigitalOcean

In this tutorial I will teach you how to install Odoo on a new DigitalOcean VPS. You will learn how to create a new account, create a new server (droplet) and how to install any Odoo version on it.
In this tutorial I will show you step by step how to create the server and how to install the Odoo thanks to my installation scripts.

1. Creating a DigitalOcean account

If you do not have a DigitalOcean account yet you should create one. If you do you can continue to chapter 2. You can create a new DigitalOcean account through this link, which will give you $10 for free to start with. After clicking on this link you will see the following screen:
DigitalOcean website
Simply click on the link, fill in an e-mailadress and a password and click on “Sign Up”. After doing so you’ll get an e-mail in your inbox. Open up the link in your e-mail and your account will be activated.

2. Creating a new server (droplet)

Now that you have an account it is time to create a VPS. DigitalOcean calls a VPS (or a server) a droplet. When you’re on the home screen after logging in you’ll see a button “Create”. After you click on this button you will see a dropdown that has an option called “Droplets“, click on it:
Create droplet button
After clicking on the button a new page will show up asking which OS you want to use and what specifications (with their prices) you’d like:
Droplet configuration

For this tutorial I will create an Ubuntu 16.04.3 droplet (VPS) with 2GB RAM, 2 CPU’s and 40GB storage. This will cost $20 per month at the time of writing. Choosing what server you need is up to you and depends on your requirements. Do know that a server with less than 1GB of RAM will not work out. Finally you will see some additional options, the ability to add an SSH key and to name your droplet (VPS) as you’d like:
Droplet configuration
I’d advice you to check on “Monitoring” as it has no extra costs but it allows you to configure warnings. For more information about monitoring you should read this article from DigitalOcean.
Now give your droplet (VPS) a name and click on the “Create” button. A few seconds later you will see that the droplet (VPS) is being created:
Droplet creation page
That’s it! You’ve just created a new droplet and are ready to connect with it.

3. Connecting with the DigitalOcean droplet (VPS)

Because you’ve just created a new droplet (VPS) you’ve gotten an e-mail in your inbox. Open up your mailbox and you will find an e-mail with all the information you need to connect to the remote server:
Droplet connection details

You can now SSH to the server with these details in order to configure the server and install Odoo. You can connect by using the Linux command ‘ssh’, which looks like this:

SSH tells Linux that you want to open up a secure connection, root is the username of the user you’re connecting with and 138.68.95.197 is the IP of the server.
After entering this command you will get the question if you’re sure to continue connecting, just type yes. Now you’ll need to enter the password that is inside the e-mail you’ve recieved from DigitalOcean. Finally the server will ask you your current password and a new one, in order to change your automatically generated password to a safer one. Go ahead and change your password, after doing so you’re good to go:
SSH connection

4. Installing Odoo

That wasn’t too bad right? Now there is just one more thing to do: install Odoo on the server!
In order to install Odoo on the server you can use my installation script, which does a lot of the installation automatically. You can find an installation script for every Odoo version on Github. In this example I will install Odoo 10, but you’re free to install any other version.

4.1 Downloading the installation script

  • If you want to install Odoo 10 you can run the following command:
  • If you want to install Odoo 9 you can run the following command:
  • If you want to install Odoo 8 you can run the following command:

As a result you will get a new file (named ‘odoo_install.sh’) on your system which contains all the code to install Odoo:
Download installation script

4.2 Configuring the installation script

Now open up the file and edit the parameters to your liking:

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 V10 you should change the line IS_ENTERPRISE to 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):

4.3 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.
You can do this with the following command:

4.4 Running the installation script

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

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:
Enterprise authentication
Finally, give the script a few minutes to configure and install everything and eventually you will see something like this:
Result installation script

You now have a fully functional Odoo on your system! Congratulations.

4.5 Accessing your Odoo

Good job! You’ve created a DigitalOcean account, created a droplet (VPS), configured it and installed Odoo on it. Now it is time to enjoy the results of your hard work. If you now open up your browser and surf to your IP and the port you’ve installed Odoo on (by default 8069) you can see your Odoo is up and running. Because the droplet (VPS) is automatically connected to the internet (a public IP address) your Odoo will also be publicly available. Go to http://yourip:yourport and you will see your just installed Odoo:
Public Odoo page

4.6 Security advisory

As security is a very big topic I did not add anything about security in this tutorial. Please do configure your Odoo with a firewall, Nginx, SSL and best security practices. The security part is out of scope in this tutorial because of the size of the subject but please do add in security rules.
For more information please do look at Nginx, the official DigitalOcean security measures and LetsEncrypt.

5. Conclusion

Creating a new server, configuring it and installing an Odoo on it is very easy with DigitalOcean. You’ll have a VPS in a matter of minutes for an affordable price. Due to the accessibility and flexibility of DigitalOcean and Odoo it has never been so easy to have an ERP publicly available.

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




PayPal

Odoo Experts

Override create functions in Odoo

In this tutorial I will teach you how to override the default create function from Odoo. You will learn how to override the create function and how to change values on a record before storing it in the database.
In this tutorial I will use the ‘res.partner’ model, which is the model from where you can create and edit contacts. I will override this create function, print a message in the terminal and will change the value of a field before storing the record in the database.

1. Inheriting the model

The first thing that you need to do is create a new python file in the ‘models’ folder. Open the ‘models’ folder of your custom module and create a new Python file named ‘res_partner.py’. After creating this file don’t forget to import it in ‘__init__.py’.
Now, open up the ‘res_partner.py’ file, import Odoo, add a class name and inherit the ‘res.partner’ model. Your code should now look like this:

2. Override the create function

Now that we have access to all Odoo methods (thanks to the imports) and now that Odoo knows which model we want to inherit we can start inheriting the create function.
The create function is a default function from Odoo so we can use the API that is provided by Odoo, this is where we use @api.model. After calling @api.model we need to define a function name and pass self and values to the function:

At this point Odoo knows we are doing these operations on the model ‘res.partner’ and that we created a new function with the decorator @api.model.
Tip: Want more information about the Odoo API and the model decorator? See the official documentation
At this point Odoo doesn’t know that we want to inherit an already existing function though. This is where the super call comes in action. With super we can call the original function and override it to change the default behaviour. If you’d like more information about using super see the official Python documentation.
Now, call the super method, pass your class along and tell Python which function you want to override:

So, what exactly does this code do? It tells Python to call the original create function for the model ‘res.partner’ and to apply all the current values to the variable ‘record’.  the variable ‘values’ contains all the values and is passed in the .create() function so that all variables are in ‘record’. In the variable ‘record’ will be all values that you’ve filled in on the form up untill the point you clicked save.

2.1 Changing values in the super

Now, let us go a step further, and add a new field to the model ‘res.partner’ to change a variable the moment we override this function.
Add the following field to your model:

Usually when you override a default function you want to change the value of a field or apply a value. In this example I will set the just created field ‘passed_override_write_function’ to true so that this value is also stored in the database. You can get, or change, any value on this record by calling record[‘field_name’] to change it. Set the variable ‘passed_override_write_function’ to true every time we pass this function:

2.2 Returning the super call

The final step is to return the record and stop the function. Without this your function will not work and the new values will not be returned. Returning the record is very simple:

Let us have a look at the full code. Your ‘res_partner.py’ file should now look like this:

Congratulations, that is all! You’ve now overriden the create method, changed a value in it and stored it in the database. Now create a new contact and click on ‘Save’. The result in the terminal:New contact creation

The result in the database:Database result after override

3. Conclusion

Overriding existing functions in Odoo is quite easy to do. Odoo is built on Python and Python allows you to use super calls, which makes it quite easy to override existing functions.

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!




PayPal

Odoo Experts

Creating security groups in Odoo

Hi guys,

In this tutorial I will teach you how to create security groups, how to add specific users to these groups and how to show/hide menu’s depending on in which group the user is in. An example of the result after this tutorial:
Example settings under user

1. Creating a model

The first thing to do is to create a model. If you already have an existing model you can skip this chapter and continue with part 2.
Still reading? Alright, let us create a new model. In this tutorial I will create a new model named ‘demo.access.rights’, with just one simple field. Create a new Python file under the ‘models’ directory and create a new model with a field:

2. Creating the security groups

Alright, now that we have a model, the next thing to do is to create the security groups with the specific rights that you would like to give to this group.
First of all open up the ir.model.access.csv file (under security/) and look at the top of the file:
Security CSV file
When you look at this file you’ll see that there are a few columns. Let me explain them a bit into detail:

  • Id: An unique identifier for the record (they should always be unique!)
  • Name: This is the description that is shown in the front-end and is the name for the security group.
  • model_id:id: The name of the model where you want to create a security rule for. Replace the ‘.’ by an ‘_’. If you have a model named ‘this.model’ it should become ‘this_model’ and it should always be prefixed with model_. So this would become ‘model_this_model’ in my example.
  • group_id:id: An unique name of the group.
  • perm_read: If this is set to 1 it means that all users that are in this group have read acces on this model. If it is set to 0 it means that the users don’t have read rights.
  • perm_write: If this is set to 1 it means that all users that are in this group have write acces on this model. If it is set to 0 it means that the users don’t have write rights.
  • perm_create: If this is set to 1 it means that all users that are in this group have create acces on this model. If it is set to 0 it means that the users don’t have create rights.
  • perm_unlink: If this is set to 1 it means that all users that are in this group have delete acces on this model. If it is set to 0 it means that the users don’t have delete rights.

Let us start writing security groups. In my example I will create two groups: one with full rights for reading, writing, creating and deleting (admin behaviour) and one group that can only read records. Let me show you the result and I will then explain it further!

Look at those two rules for a minute and try to figure out what they do.
I’ve created two lines, which means two groups, that are both for the model ‘demo.access.rights’, where the first group has all rights on the model and the second group can only read data (look at the 1,1,1,1 and the 1,0,0,0).
Do you notice something else? There is a group_id in the field named ‘user_access_rights_demo.group_manager’ on the first line and ‘user_access_rights_demo.group_user’ on the second line. What do these two mean? Well, the first part (‘user_access_rights_demo’) is the name of the module where you are creating groups for. The second part, ‘group_manager’ will link to an XML record in which we specify the rest of the details. Add those lines to your CSV file, save it and then close it.

3. Creating the groups and selection in XML

Now that you’ve written the groups in the CSV we have the rules but in the CSV file they link to ‘group_manager’ and ‘group_user’, which we still haven’t made anywhere. So let us make them!
Create a new XML file under the ‘security’ folder so that we can write the XML side. In my example I’ve named the file ‘user_groups.xml’ as you can see here:
XML security file
We now need three things:

  • A group named ‘group_user’
  • A group named ‘group_manager’
  • A record that will link these both groups in a dropdown, in order to show it in the user his form.

Let’s start by writing a record that will show our both groups in a dropdown:

This will create an option in the user his form that has the label ‘Demo module access’ and a description ‘User access level for this module’. The sequence can be used to specify where it should come in the view. When you’re done with this part it will show this selection:
Example security settings

One down, two to go. We now need to create two group records (‘group_user’ and ‘group_manager’) so that the CSV can find and use these groups. The code should look like this:

Let me explain the code a bit more. The ‘name’ field will be the text that is shown to the user in the front-end.
By setting the ‘users’ field (which links to another group user) you can say that by default users that belong to the other group should be added to this specific group. For example: with users set to ‘base.user_root’ I will by default enable this value for the user. By setting the field ‘implied_ids’ on the ‘group_manager’ I’m saying that if the user has the manager rights that he should also have rights as a user (ref(‘user_access_rights_demo.group_user’) does this).

That is all! You’ve just created your own security groups and made them available on the user his form so that you can configure this for every user on his own.

4. Applying groups to views

After you’ve created your own groups and rules you’ve got a broad set of options to configure Odoo depending on the user his rights.
Let me give you an example with two menuitems that are available for one of two groups. If you do not need to know this you can skip to the conclusion (part 5), otherwise read on!
Alright, I will create two menuitems, one of them will be available to the user group and both menu’s will be available to the manager group. How would this look in XML? Like this:

This will create a new top menu named ‘Access rights demo’, with a menu named ‘Rights demo’, with two menuitems named ‘User records’ and ‘Admin records’, which looks like this:
Example menuitems
By simply adding the ‘groups=’ tag on the menuitems I can specify which group can access which menuitem! It is as simple as that. When I would now create a new user with the ‘User’ rights he would only see the menuitem for the user and not the admin menu:
User menuitem

5. Conclusion

The security groups and security rules are not very hard to set-up but allow you a very broad range of configuration. You can specify what a user can see just by in which groups or security rules the user is in. This allows you to show or hide menuitems, fields and options with very little effort. The possibilities are endless!

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!




PayPal

Odoo Experts

Installing Odoo 9 on Ubuntu 16.04

Hi guys,

1. Introduction

In this tutorial I will teach you how to install Odoo 9 on Ubuntu 16.04. The script that you will use is based on the code from André Schenkels but has been updated and improved.

2. 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:

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!

3. 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:

4.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:

You will see that the script automatically starts updates, downloads required packages, creates the user, downloads the code from Github, …
Give the script a few minutes to configure and install everything and eventually you will see something like this:
Result install script

You now have a fully functional Odoo V9 on your Ubuntu 16.04! Congratulations.
Odoo V9

5. Extra information

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:
Changing Odoo settings
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:
Odoo V9 alternative port

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


Odoo Experts

Updating your Odoo from Github

Hi guys,

In this tutorial I will teach you how to update your Odoo code from Github. In this tutorial you will learn how to use terminal commands to update your local Odoo installation.

In this example I will learn you how to update your Odoo environment from Github and how you can update your database in order to use the newest code.

1. Navigating in to the correct folder

The first thing that you will need to do is to navigate in to the correct folder from your terminal. Usually your Odoo is installed right under the root folder and has a structure along the lines of /odoo/odoo-server. In my local example I’ve installed an Odoo 9 under /odoo9/odoo9-server:
Odoo folder location
So, how do you know in which folder you need to be? if you see the same structure as in my above screenshot you’re in the right place. You should see the odoo.py and addons folder.

2. Fetch content from Github

Now that you’re in the correct folder you should fetch the content from Github in order to apply it locally later on. Fetch the content from Github:

So, what does this line do? Sudo will execute this command with administrator priveleges, git fetch will tell the system that we want to fetch content from github, origin refers to the origin where Odoo comes from (http://github.com/odoo/odoo) and 9.0 is the Odoo version.
Tip: If you have Odoo version 8 you should replace 9.0 with 8.0.
After running this command you will see the following result:
Github fetch origin

3. Apply all changes

You now have everything fetched and you should now tell the system to apply this. At this point the system knows which files and changes need to be made, but you didn’t make them yet. You can do this with git reset. The code:

Tip: git reset –hard will apply all changes, no matter what. If you did add custom code in already existing modules (so in the source code and not in a self made module) you should not use this. Your custom code will be overwritten with this! This is however against all the rules, so if you do code in the source code please start with creating your own modules in place of adding in the source code.
Tip #2: Do you have another version? Simply change 9.0 with the Odoo version you have running. For example if you have Odoo 8:

After you’ve used this command you will see a result similar to this:
Github reset hard example
So, what does this refer to? If I open up Github and look at the latest change that has been made to Odoo you will see that these match up:
Github reset result on Github
As you can see your Odoo code is now up-to-date and is at the latest change that has been made by Odoo.

4. Updating the database

Congratulations, you’ve already updated your whole Odoo code! That was simple, right? There is just one more thing to do. You should now update your database so that the database knows about all changes and applies them in the database.
There are multiple ways to do this but the most simple one is to restart the Odoo service with the correct parameters to update the odoo. Every Odoo has a service running and usually has a name along the lines of odoo-server. Type the following command in your terminal:

Let us break down the whole command to know which part does what.
sudo service odoo9-server restart tells the system to restart a service (so, an Odoo environment). -u all will tell the Odoo to update all modules and -d YourDatabaseName will tell the Odoo to do these changes on the database named ‘YourDatabaseName’.
Tip: Want to know more about the possibilities of the command-line interface? Have a look at the official documentation!

That is all, you’re done! After you’ve run this command you’ve updated the whole database with the latest code.

5. Conclusion

Updating an Odoo environment from Github is actually really easy. Your users will not notice anything (besides of a minor delay when reloading the database) and your system will not need to go down when updating an environment.

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




PayPal

Odoo Experts