Skip to Content
Menu
This question has been flagged
3 Replies
15527 Views

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
Discard
Author Best Answer

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
Discard
Best Answer

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
Discard
Author

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 Replies Views Activity
4
Mar 20
16046
3
May 18
6333
1
Apr 22
8015
1
May 24
7068
3
Nov 22
7123