Odoo Help

Welcome!

This community 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.

1

How to get company ID in this method?

By
Pascal Tremblay
on 2/23/15, 6:18 AM 3,413 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

3

zbik

--zbik--
5976
| 6 4 7
Lodz, Poland
--zbik--


zbik
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
1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 2/23/15, 8:15 AM

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

Example,

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]

thanks

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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