This question has been flagged

Hi community,

I am looking at ways to determine the current company for a user in order to show only records for the current company for multi-company environments. I am wondering what is the purpose of this method:

self.env['res.company']._company_default_get()

Why do we need to go trough a method in res.company which calls a method in res.user.

Can't we directly call the method in res.user

self.env['res.users']._get_company()

Or even better can't we directly use:

self.env.user.company_id


What is the difference between the 3, which one is better to be used?

Avatar
Discard
Best Answer

Hi, 

If you need to get the company of the currently logged in user - then the best way is to get directly self.env.user.company_id

Other two options will do the same, but via several static methods of corresponding classes.



Avatar
Discard