Odoo Help

1

How to get company ID in this method?

By
Pascal Tremblay
on 2/23/15, 6:18 AM 3,797 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--
6223
| 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--
Prakash
3203
| 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 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.

Register

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)

Stats

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