This question has been flagged
9 Replies
17120 Views

I would like to know how can I download/print a single pdf that has multiple reports of the same template.

At the moment I can download only a single report per child, but I want to have them all in a single pdf when I print them from the parent. In my views I use buttons in the header to get the report.

<header>
	<button name="%(action_report_salary_all_details)d" string="Salary (details)" type="action" style="margin-right: 5px;"/>
	<button name="%(action_report_salary_few_details)d" string="Salary" type="action"/>
</header>

My report code for the child model (parent is 'hr.history.salary' and it is in One2Many relation with child):

class ReportSalaryFewDetails(models.AbstractModel):
    _name = 'report.hr.report_salary_few_details'

    @api.model
    def render_html(self, docids, data=None):
        payslips = self.env['hr.history.salary.salary_slips'].browse(docids)
        docargs = {
            'doc_ids': docids,
            'doc_model': 'hr.history.salary.salary_slips',
'docs': payslips, 'data': data, } return self.env['report'].render('my_addon.report_salary_few_details', docargs)

Do I have to create a whole new report so I can call it from the parent or can I modify this code and how to print them all in one pdf? 





Avatar
Discard
Author Best Answer

I finally figured it out with the get_pdf() method. 

def save_reports_file(self):
        report_ids = self.env['hr.myreport.datas'].search([('report_id', '=', self.id)]).ids
        report_name = "module.report_name"
        pdf = self.env['report'].sudo().get_pdf(report_ids, report_name)
        self.reports_file = base64.encodestring(pdf)

 

Avatar
Discard
Best Answer

I know get_pdf() method works for ODOOV10. i.e.

self.env['report'].sudo().get_pdf(obj.id, 'module_name.report_template_xml_id)

In V12 issue can solve this way:

report_sudo = self.env['ir.actions.report']._get_report_from_name('module_name.report_template_xml_id')  # report action
pdf_content = getattr(report_sudo, 'render_qweb_pdf')([obj.id], data={'report_type': 'pdf'})[0]

Avatar
Discard
Best Answer

invoice tree view has print invoices function. check how it is done, it might give you the idea.

see NIyas's answer here: https://www.odoo.com/forum/help-1/question/mass-downloading-invoices-126451

Avatar
Discard
Author

I need it to work from a custom button in a view. At least tell me the name of the module so I can view the source files. The answer in the link isn't helpful! I need a code example not how a end user can do it.

i thought you would notice it from attached picture. it is in accounting / customer invoices. and there is no other ready code I know of. you can do it and share it.

Author

the picture is a bit small so I didn't really see the menu items good. But now I have to figure out what addon modul has this code.

Hi,

just pass the required id's of the records in docids

Author

tried that before posting question because in the template is <t t-foreach="docs" t-as="o">, but it didn't work. Or I just don't know how to do it right.