コンテンツへスキップ
メニュー
この質問にフラグが付けられました
9 返信
20543 ビュー

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? 





アバター
破棄
著作者 最善の回答

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)

 

アバター
破棄
最善の回答

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]

アバター
破棄
最善の回答

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

アバター
破棄
著作者

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.

著作者

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

著作者

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.

関連投稿 返信 ビュー 活動
0
9月 21
2488
1
5月 18
3685
2
1月 17
6775
3
3月 15
7534
2
10月 24
2271