Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
6 Risposte
17140 Visualizzazioni

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'

            })

Avatar
Abbandona

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

Autore

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!

Risposta migliore

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.

Avatar
Abbandona
Autore Risposta migliore

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).

Avatar
Abbandona
Risposta migliore

Thanks Jake Robinson a lot.


Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
3
ago 16
9415
2
mar 15
9415
2
set 21
3188
1
giu 16
4193
0
apr 15
3717