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

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
9090
2
3月 15
9121
2
9月 21
2939
1
6月 16
3954
0
4月 15
3452