Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
16724 Vizualizări

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?

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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"/>
Imagine profil
Abandonează
Cel mai bun răspuns

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,


Imagine profil
Abandonează
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.

Related Posts Răspunsuri Vizualizări Activitate
4
mar. 20
17324
3
mai 18
7190
1
apr. 22
9288
1
mai 24
8224
3
nov. 22
8264