Setting up multi-website with multiple (sub)domains in Odoo

In this tutorial I will learn you how to setup multiple website in Odoo and linking them to multiple (sub)domains. This allows you to setup multiple websites – and webshops – from one shared Odoo database and having those websites run on multiple (sub)domains.
In this tutorial I will setup two websites that link to two subdomains. Let’s assume that you want to have two separate websites where one is an informaton center and one is a shop.
We’ll host the information center on and the shop on

1. Creating multiple websites

The first step in adding an extra website (after the initial one) is by going to Website > Configuration > Settings and clicking on the button “Create a new website”. After clicking on this button you will get a pop-up:

Website configuration pop-up when opened

The website name is just informative and will be shown throughout Odoo so give it a good name, such as “Information portal” in our case. The second field, “Website Domain” will tell Odoo to which (sub)domain all pages related to this website should link. Enter the website URL here without www or https:// in front of it and no slashes, so like this:

Website configuration pop-up after configuration

When this is done click on “Pick a theme”, choose one, save and your second website is set up.
The next step is that you most likely want to configure extra options for your website such as the languages, social media accounts and so on. You can do this from Website > Configuration > Settings again. Keep a close eye out though! The options configured here are website specific! Be sure to first select the website you want to configure at the top before configuring your website further:

Website switcher in website configuration

Repeat this step for as many websites as you like. Once you’re done it is time for the next step, setting up the DBS records.

2. Setting up the DNS

Now that you’ve setup your website(s) in Odoo it is time to configure the DNS. By configuring the DNS you will tell Odoo that when the user enters a website URL in the web browser (for example to which server it should connect to get the data from.
Luckily this step is pretty forward. Login to the portal where your DNS is managed – usually your hosting provider – and add an A-record to your DNS list which connects the URL to the IP of the server. Your configuration will look something like this:

Sample DNS A-record

3. Configuring NGINX

Alright, so now we’ve told Odoo that we want a website and where it points too and we told our DNS which URL should go to which server (IP). The final step is to tell Nginx (or whichever alternative you use) which domain should link to where. You should already have an Nginx configuration file with a server block. The easiest is to make a duplicate of this block in the existing configuration file. Make sure that this duplicated code block it’s “server_name” points to the domain you’ve setup in the frontend of Odoo (so “”). Typically it would look something like this:

That’s it! Just don’t forget to reload and restart your Nginx to apply these changes (sudo service nginx reload and service nginx restart). If you do this configuration you can setup multiple websites with a separate design (theme) running on separate (sub)domains!

4. Conclusion

Thanks to the default built-in features from Odoo setting up multiple websites, webshops or portals is pretty easy! By just creating a second website, adding a DNS records and an Nginx server block you can have a new website running in a matter of minutes!
Has this tutorial helped you, do you have any feedback or questions? Post away!

New building block result

Creating building blocks in Odoo

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:
New building block result

1. Adding the dependency

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

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:
snippets.xml structure
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:

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 file so that it is loaded:

When you now install the module you will see your new building block is available for use from the editor:
Building block editor example
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!
Tutorial sponsored by Oocademy


Creating webpages and controllers in Odoo 10

In this tutorial I will teach you how to create new webpages and controllers through code in Odoo 10. You will learn how to create new webpages (in XML), how to create controllers and how to use controllers to open specific webpages. After following this tutorial you will be able to create your own webpages and controllers in Odoo.
In this example I will create a webpage with a button. The button click will call a controller function and this controller will redirect you to another webpage. On this page we will show the details of all the companies in your Odoo:
Example result

1. Creating the controller structure

Before you can create (and call) a webpage you need to make a controller. This controller will tell Odoo which URL links to which webpage. Open up your module and create a folder ‘controllers’ if you don’t have one yet. After creating this folder make an __init__ file and add the followig line of code in it:

Now that you have an import that is directly loaded by Odoo (thanks to the __init.py__) you should create a new Python file. Name this new file ‘’, which will be the controller. As a result your folder structure should be looking like this:
Folder structure

1.1 Creating the controller

Let us create our first controller now! Just have a look at this code:

So, what does this tell you? In order to let an user navigate to a specific page you will need an @http.route. This @http.route will tell Odoo that we want to link the url ‘/example’ to a specific webpage. Inside the @http.route you will see four variables. Let me explain them one by one:

  • ‘/example’: Because Odoo needs to know which URL links to what (XML) template you’ll need to provide the URL first. In this example it means that http://localhost/example would call this @http.route
  • type=’http’: This will let Odoo know that your page is running in HTTP.
  • auth=’public’: Tells Odoo who can view the page.
    You can choose between ‘public’, ‘user’ and ‘none’. If you choose ‘public’ anybody can view the page. When you choose ‘user’ only logged in people can view this page and if  you choose ‘none’ there will be no facilities to access the database or any configuration. For more information see the official documentation
  • website=True: Tells Odoo that is has to link to a webpage and that it is not just a Python function.

After calling @http.route you will need to give the Python function a name, in this example render_example_page(self). Notice that self is also passed along in functions in the front-end of Odoo, just like in the backend.

1.2 Returning the controller function

Finally, you need to return the function. Because the function needs to know which XML record needs to be called we pass it along like this:

http.request.render will call the view renderer from the Odoo framework. within the brackets “()” you have to specify the module_name.page_name. In this case my module is named ‘create_webpage_demo’ and I will create a webpage with the technical name ‘page_name’. In this http.request.render you’ll also see {}. Why is this there? You can pass variables and data along in this dictionary to the website. Further in this tutorial I will show an example about how to do this, so don’t worry about it yet.

2. Creating the webpage

Close the Python file, go into the ‘views’ folder and create a new XML file named ‘example_webpage.xml’. Add this XML file in your first:

Now go back to your example_webpage.xml file and create a new XML record. You’ll notice that creating a new webpage is just as easy as creating an Odoo view. Have a look at this code first and then add it in your module:

Does this make sense to you? Let me explain it step by step. The record starts with a template id, which is identical to creating views in Odoo. Why did I name this example_page though? Because in the controller we did this: return http.request.render(‘create_webpage_demo.example_page‘, {}). As a result Odoo will now know that the controller needs to render the XML view that we’re now coding. Did you notice the page=”True” key too? Since Odoo needs to know if it is a webpage or not there is a key ‘page’ added in Odoo. By settings this key to true Odoo knows it’ll become a webpage. Next, we have the following line:

Because of this Odoo knows that it has to take the default webpage lay-out and needs to apply it to this XML record. The next line has some noteworthy features. The div class oe_structure will add the feature to use building blocks within Odoo, which is otherwise not possible. As a result other people, that use your Odoo that do not have technical knowledge, will be able to use building blocks to style the webpages. As for the rest of the code? You could basically add what you want here. Because Odoo implements bootstrap, less and font awesome you can use a lot of features out of the box!

2.1 Saving and showing the webpage

Finally, save this page, update your module and open your Odoo. In the website go to /example and you’ll see the following result:
Example page
Do you see that button? In the XML record that we just created I added the following line of code:

I’ve added a t-attf-href in this line with a reason, but why? Because the Odoo framework will be triggered the moment that you click on this button. Odoo can interpret this code and knows that you want to open the page /example/detail.
So, let us continue and let us create another function in the controller to handle this.

2.2 Second function in controller

Open up the Python file ‘’ again and let us create a second function, just like we did with the first. There will be just one addition to the code, we’ll also pass data to the next webpage! Go ahead and create a second function that links to /example/result. Your code should look like this:

This code will work fine and you’ll be able to open the page /example/detail (if you’d have an XML record by now too), but, we still need to pass data along.

2.3 Passing data to the webpage

Since there is no code to pass data along yet we should add it. You can call data from the database in controllers too, it just works slightly different. Usually in Odoo you would do this:

It’s not possible to do it like this in the controller though. In the controller we will need to use ‘http.request.env’ to fetch data from a model. As a result your code will look like this:

I’ve also added the function “.sudo()” on this search. Why? Since the website looks at user rights and access rights too you’d need to make sure the users have enough rights. As this is not in the scope of this tutorial I simply add “.sudo()” so that the database query is executed as if it was done by the super administrator user without any security problems.
The final thing to do is to pass this data, that is in the variable companies, to the webpage. How do you do that? Like this:

Now you’re all set on the controller side to open up the page /example/detail and to pass all data to the webpage. The final code of your function will look like this:

Because of doing {‘companies’: companies} in the dictionary all data from all companies will be passed along to the webpage.
Save this code and let us create the second XML record for the webpage in ‘example_webpage.xml’.

2.5 Creating the detail view

Finally, let us create the second webpage and then we’re all done! Open up the ‘example_webpage.xml’ file and create a second XML record, where you also set the page=”True” key on. On this page we will show all company details in a table, which is passed along in the variable “companies”. Have a look at this code and then add it in your XML file:

The controller will know that it has to call this record thanks to the name “detail_page” so when you would save this and update your module everything will work. Since we’ve passed along the dictionary companies we can access all company data. To print all records (in multi company you can have multiple companies) we loop over the records thanks to the t t-foreach code:

Because you’re doing a foreach you can access every company it’s data with the variable “company” later on. As a result we can access any data from the company with “company.field_name”. You can show the data in the webpage with span t-esc=”company.field_name” to print it out:

Finally, save this file, update your module and go to /example/detail. You will now see the following result:
Detail page result

3. Conclusion

Creating webpages and using controllers in Odoo is quite easy. As the Odoo framework has a lot of built in libraries (such as requests, less, bootstrap, font awesome, …) it has never been as easy to create webpages as in Odoo 10. As a result you can create beautiful webpages with any data you want in record times.
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!
Tutorial sponsored by Oocademy