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

I'm wondering if it's possible and if so, how is it possible to generate a qweb report and save it in a binary field?

I need this so if I have to add something new to the report, or change some data (new company name) the old reports will all have the correct data (old data), because they won't be generated again.

So how do you generate a report from a model and save it into the models binary field?

Avatar
Abbandona
Autore Risposta migliore

After finding out that I need to use the method "get_pdf()" I found the answer.

https://www.odoo.com/forum/help-1/question/how-to-programmatically-create-pdf-attachment-in-odoo-10-0-118073

def generate_report_file(self):
        report_name = "hr_izracun_place.report_placilna_brez_prisp"
        pdf = self.env['report'].sudo().get_pdf([self.id], report_name)
        self.report_file = base64.encodestring(pdf)

After I just created a method that creates a string that ends with .pdf for the file name and stores in a field and added to my view.

<field name="file_name" invisible="1"/>
<field name="report_file" filename="file_name"/>
Avatar
Abbandona
Risposta migliore

Hello Samo,

You can add report as attachment in your record, when generating report.

To add attchment of report in record, you can add "attachment" in report XML as did in invoice report: 

<report 
            id="account_invoices"
            model="account.invoice"
            string="Invoices"
            report_type="qweb-pdf"
            name="account.report_invoice_with_payments"
            file="account.report_invoice_with_payments"
            attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
            print_report_name="(object._get_printed_report_name())"
     />

Thanks,


Avatar
Abbandona
Autore

I don't think this does what I asked. I need to save it into a binary field of an X model and I need this to be done in the python code. To have a model where all documents are stored. In the example you posted I can't find to what field it's stored.

Post correlati Risposte Visualizzazioni Attività
4
mar 20
17345
3
mag 18
7216
1
apr 22
9323
1
mag 24
8234
3
nov 22
8283