Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
16692 Vistas

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
Descartar
Autor Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Autor

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.

Publicaciones relacionadas Respuestas Vistas Actividad
4
mar 20
17274
3
may 18
7180
1
abr 22
9255
1
may 24
8198
3
nov 22
8232