Odoo Help


Generate Report in PDF and HTML

on 10/13/16, 9:19 AM 1,919 views


is it possible to generate a report in html or pdf and the User can decide if he wants a html preview or the generated pdf instead?


Have you tried to register the same report with two <report> records with 'report-type=qweb-pdf' in the first one and 'report-type=qweb-html' in the other?

on 10/13/16, 10:29 AM

Bejaoui Souheil

--Bejaoui Souheil--
--Bejaoui Souheil--

Odoo developer,  functional and technical consultant


Bejaoui Souheil
On 10/13/16, 10:41 AM


Add a selection field to your model where the user can chose between HTML and PDF.

Add a method that call your report based on user choice

type = fields.Selection([('qweb-pdf', "PDF"),('qweb-html', "HTML"),], default='qweb-pdf')
def print_report(self):
        vals = {}       
        return {
                'type': 'ir.actions.report.xml',           
                'datas': {                   
                            'id': report_ids and report_ids[0] or False,                   
                            'ids': report_ids and report_ids or [],                   
                            'report_type': self.type},
                            'nodestroy': True

Call this method by a print button.

<button name="print_report" string="Print" type="object" />

Best regards.

Even better is to replace @api.one with @api.multi and self.ensure_one() :)

on 10/14/16, 2:30 AM

Yes, Thanks :).

Bejaoui Souheil
on 10/14/16, 12:12 PM

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: 10/13/16, 9:19 AM
Seen: 1919 times
Last updated: 10/13/16, 10:41 AM