How to generate PDF report from Python code. Odoo 16

I have a custom wizard with fields : "file_name"(Char), "model_id"(active model), "content_report"(html) . I added a print button in this wizard . When I click on this button I want to generate reporte with name = "file_name" and content of report = "content_report" , without using a report template. Only with python code?

How can I do it? Any help please?

Thanks.

1 Answer

You can use _run_wkhtmltopdf function used to print the qweb reports.

Example:

def render_html(self): self.ensure_one() action_report = self.env['ir.actions.report'] pdf_content = action_report._run_wkhtmltopdf( [self.content_report], report_ref=None, header=header, footer=footer, landscape=False, specific_paperformat_args=specific_paperformat_args, set_viewport_size=False, ) self.update({'file_content': base64.b64encode(pdf_content)})

Your HTML should be enclosed in main tag

6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like