Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
16710 Tampilan

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
Buang
Penulis Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Penulis

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 Terkait Replies Tampilan Aktivitas
4
Mar 20
17295
3
Mei 18
7187
1
Apr 22
9286
1
Mei 24
8216
3
Nov 22
8260