Odoo Help


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.


Generate Report in PDF and HTML

on 10/13/16, 9:19 AM 118 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
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

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)


Asked: 10/13/16, 9:19 AM
Seen: 118 times
Last updated: 10/13/16, 10:41 AM