Flask_tryton download a report

Hello,
I’ve wondering if it’s possible to download a report using flask_tryton, In case not, I’m guessing I should start reading about how to use the JSON-RPC or XML-RPC.

A good start point should be see sao source code? or where should I start? Thanks in advance.

1 Like

Yes, it is possible you should use something like:


from flask import Flask, send_file
from flask_tryton import Tryton 

app = Flask(__name__)              
tryton = Tryton(app)   

@app.route('your_route_here')        
@tryton.transaction()                                                          
def render_report(records):                                              
    Report = tryton.pool.get('your.report.name', type='report')                    
    ext, content, _, name = Report.execute([r.id for r in records], {})                                
    return send_file(                                                          
        BytesIO(content),                                                      
        attachment_filename='%s.%s' % (name, ext))                             
                                                       

Hope it helps!

3 Likes

Worked like a charm!,
Thanks as always @pokoli.

Just to complement:
your.report.name: I found it on client under Administration - User interface - Actions - Informs - (desired report) and it’s the internal name.

the records parameter it’s coming from pool , so if I want to download a party report I had to:

Party = tryton.pool.get(‘party.party’)
records = Party.search([(‘id’,’=’,‘45’)]) in case I need only 45 party id report.

Regards

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.