تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
6214 أدوات العرض

Hi, 

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?


I'm trying with this code:

def print_report(self):
self.ensure_one() action_report = self.env['ir.actions.report'] bodies, html_ids, header, footer, specific_paperformat_args = action_report._prepare_html(self.content_report) pdf_content = action_report._run_wkhtmltopdf( bodies, 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)})


But I got this error : 

 File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions_report.py", line 337, in _prepare_html body_parent = root.xpath('//main')[0] IndexError: list index out of range


How can I do it? Any help please?


Thanks.

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

Refer to this blog to generate a PDF report  via a print button in the wizard in Odoo 16
https://www.cybrosys.com/blog/how-to-create-pdf-report-in-odoo-16


Hope it helps

الصورة الرمزية
إهمال
الكاتب

Thanks for response , but my question is about without using template XML . Only using python functions to generate the report.

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
سبتمبر 23
29
1
مايو 20
3272
0
سبتمبر 22
2377
1
مايو 17
4870
0
سبتمبر 24
997