콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
9 답글
20476 화면

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
2445
1
5월 18
3604
2
1월 17
6750
3
3월 15
7476
2
10월 24
2223