Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
14293 Weergaven

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

Avatar
Annuleer
Beste antwoord

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

Avatar
Annuleer
Auteur

Great, I try it now and I come back.

Auteur

Your code is perfect! Thanks a lot!

Beste antwoord

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]

Avatar
Annuleer
Auteur

thanks

Gerelateerde posts Antwoorden Weergaven Activiteit
0
apr. 24
1961
3
mrt. 21
12183
0
jun. 20
2652
1
mei 20
9697
27
aug. 24
40243