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

It seems Odoo guys have yet once more changed methods and classes so, my v10 working examples are messed up in v11...

I need to run a report by code, get the result and save it to an attachment. All by code!

Does anyone know how to do this?


SOLUTION

 #run the report and get the pdf (use the reports xml_id and pass record ids into render)

data, data_format = self.env.ref('hr_timesheet.timesheet_report').render([1,2,3])


#save the attachment

att_id = self.env['ir.attachment'].create({

            'name': 'My name',

            'type': 'binary',

            'datas': base64.encodestring(data),

            'datas_fname': 'Myname.pdf',

            'res_model': 'account.invoice',

            'res_id': invoice.id,

            'mimetype': 'application/x-pdf'

            })

아바타
취소

it is all over in the code, why don't you read it ?

작성자

F.P. If you don't understand the basic rules of a forum meant for developers to help other developers, I suggest you try Facebook instead.

Thanks a lot for posting the solution, Rui!

베스트 답변

If you are defining your report using the <report/>, see the following example:

<report id="l10n_ch_isr_report"
    model="account.invoice"
    report_type="qweb-pdf"
    string="ISR"
    name="l10n_ch.isr_report_main"
    file="l10n_ch.isr_report_main"
attachment="'ISR-' + object.number + '.pdf'"/>

 The attachment attribute will give the file a name and store it as an attachment.

You can also configure this in the UI by going to Settings -> Technical -> Reports, selecting the correct report and clicking the Advanced Properties tab. The attachment field is editable here. Note: you must be in developer mode to see these menus.

아바타
취소
작성자 베스트 답변

Thanks Jake Robinson but, by "code" I mean "python". I need to be able to do this using python.


Call a report and get the attachment (or create it).

아바타
취소
베스트 답변

Thanks Jake Robinson a lot.


아바타
취소
관련 게시물 답글 화면 활동
3
8월 16
9453
2
3월 15
9449
2
9월 21
3213
1
6월 16
4204
0
4월 15
3751