When I wrote this article, odoo 13 was released more than 1 year ago. There is even a newer version, odoo 14. Compared to odoo 12, there are many changes in their source code, such as the removal of the account.invoice model, the removal of the @api.multi decorator, the removal of the view_type field from the ir.actions.act_window model and many more.
I immediately felt the effects of the changes above. Even when I started working on my first odoo 13 projects. Because things above are common things.
But there are also changes that I have just noticed recently. It is about how to get a company that is currently active if in one database, odoo has many companies. It is usually called by Multi Company.
I have worked on many projects since odoo version 10. But not many projects use multi company. Maybe this is one of the reasons why I realized that there were changes in the odoo’s source code about the multi company too late. 🙂
OK. These are some changes that occurred in odoo 13 compared to odoo 12, regarding multi company.
In odoo 12, let’s assume that we have 3 companies as shown below.
Then in the master user form let’s configure that the user can open all of the companies above.
In odoo 12, we can open the transactions from one company only. If we want to open the transactions from another company, we have to switch the company that is currently active, with another company that we want to open its transactions. Look at the image below.
To get the active company name that the user choose, we can use a code like this.
print('=======Get Active Company=======') print('Company id => ',self.env.user.company_id.id) print('Company name => ', self.env.user.company_id.name) print('=======Get Active Company=======')
The result will like this.
If we choose another company as an active company, the code above will still give the correct result.
So what has changed in odoo 13 ?
In odoo 13, now we can choose more than one company. This means that we can open the transactions from several companies at once.
Besides, the code below also does not work like in odoo 12.
self.env.user.company_id
Look at the image below.
Then, what is the correct code to get the active company in odoo 13 ?
Use this code.
print('=======Get Active Company=======') print('Company id => ',self.env.company.id) print('Company name => ', self.env.company.name) print('=======Get Active Company=======')
Please take a look at some pictures below.
You need to remember that how multi company in odoo 14 works are the same as odoo 13.