Odoo Help


How to get company ID in this method?

Pascal Tremblay
on 2/23/15, 6:18 AM 4,949 views

Hello guys,

I have this class (almost the same of ./addons/report/controllers/main.py) in my custom module :

class PTReportController(ReportController):
    @route(['/report/download'], type='http', auth="user")
    def report_download(self, data, token):


I use this method mainly to change the name of PDF reports.

For the actual user, how could I get the company name or the company ID in this method?

I would like to put is in the filename of the reports.

Thanks for your ideas

On 2/23/15, 7:42 AM

Try like this:

self.cr, self.uid, self.pool = request.cr, request.uid, request.registry

user = self.pool["res.users"].browse(self.cr, self.uid, self.uid)
company_id = user.company_id.id
company_name = user.company_id.name

Great, I try it now and I come back.

Pascal Tremblay
on 2/23/15, 7:43 AM

Your code is perfect! Thanks a lot!

Pascal Tremblay
on 2/23/15, 8:15 AM
On 2/23/15, 8:15 AM

use request.registry.get('res.users') instead of self.pool["res.users"]


import openerp
    @route(['/report/download'], type='http', auth="user")
    def report_download(self, data, token):
        cr, uid, context = request.cr, openerp.SUPERUSER_ID, request.context
        user = request.registry.get('res.users').read(cr, uid, uid, ["company_id"])
        company_id = user['company_id'][0]
        company_name = user['company_id'][1]


Pascal Tremblay
on 2/23/15, 8:16 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/23/15, 6:18 AM
Seen: 4949 times
Last updated: 6/5/15, 7:14 PM