Odoo is a beautiful multi-tenant system. You can serve as many clients as you want with a single code base. In Odoo, every client has his own database in Postgres, and data are not shared amount clients. Our preferred version of odoo is the V14 community edition because we have many clients and customs modules written for them. In a single VPS server, we have one source code of odoo14 and roughly 8 clients on every server.
What is the problem?
As a multi-tenant system, when you open your Odoo instance from the main domain, you have the listing of all the databases as shown in the following picture.
Each client should then select their corresponding database and log in to perform their daily business operation.
In our situation, our client shouldn’t be aware of the existence of the database of other persons on that server. Also, should be able to only access their database with their domain name. Imagine you can know that we also host the database of your main competitors on the same server .
What I was asking to do?
In my early days in the team as a newbie odoo developer, my supervisor asked me to find a way to get rid of this problem. Our boss didn’t want that anymore. So I search the internet and found an interesting blog post explaining database filtering in Odoo. It is worth it to read that short blog post.
My task was to filter the database listing base on the domain name. I learned there that odoo offer two types of a regular expression to filter databases:
- %d filter databases based on subdomain
- %h (my favorite) filter databases based on full domain name port excluded if any
If you want to know a more advanced way to filter databases in odoo, read trobz blog post where I learned dB filtering in Odoo. I only cover what I used (%h) and how I used it to solve my problem.
My usage of %h to filter databases in Odoo?
The first thing to do is to configure every client domain name to point to the same Odoo instance. For example, if you have erp.client1.net and my.client2.org, both should be pointed to the same Odoo instance.
The second step is to create the database of the client with the same name as their domain name. The following picture show to you what I am saying.
The third and last step is to add the following entry in your odoo.conf file and restart your server.
dbfilter = %h
Voilà. You have successfully applied database filtering in your odoo instance based on the domain name in the URL.
- %h means everything starting with the hostname. If I create another database with the name erp.client1.net_demo, this database will be displayed when you will access erp.client1.net domain name
- %h$ is used for exact matching. This will only allow the listing of the database with the same name as the domain name.
In this short blog post, I shared with you how I managed to apply dB filtering in our Odoo instances based on the domain name. I hope this will help you. If you like the type of content I share, consider subscribing to my newsletter to don’t miss any content I pop out.
If you have an incomprehension with my explanation, leave a comment and I would clarify that part. Thanks for reading.
I am a Master’s student in computer science passionate about DevOps, Cloud Computing, AI, and BI. I am also a web developer, especially with Django and Laravel Frameworks. I love to share things that work for me with others to save them time searching through the internet to solve the same problem.