Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

Custom module: Can I generate and store a PDF report in a binary field - Odoo 18

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
reportsBinaryv18
2 Risposte
191 Visualizzazioni
Avatar
Boris Giordanengo
Hello,

I have an xml file to generate a report a my.model:

<odoo>
<template id="my_template">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
My report
</t>
</t>
</template>

<report id="my_report" model="ir.actions.report">
<field name="name">Report</field> <field name="model">my.model</field> <field name="report_type">qweb-pdf</field> <field name="report_name">my_app.my_template</field> <field name="report_file">my_app.my_template</field> <field name="binding_model_id" ref="model_my_model"/> <field name="binding_type">report</field>
</report>
</odoo>


This code is working file.
I also know how to generate the pdf report via a button, but I don't know how to generate this pdf report as a binary field of my.model (report_id = fields.Binary('pdf report')).

Thanks,

Boris

0
Avatar
Abbandona
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Risposta migliore
Hi,

You can generate a QWeb PDF report programmatically and store it in a Binary field on your model.The correct approach is to call the report action from Python, render the PDF in memory, and then write the resulting bytes to a binary field. You do not need to trigger a download or rely on a button action that returns a report.

First, define the binary field on your model:

from odoo import models, fields

class MyModel(models.Model):
    _name = 'my.model'

    report_pdf = fields.Binary(string="PDF Report", attachment=True)
    report_pdf_name = fields.Char(string="PDF Filename")

Then, generate and store the PDF using ir.actions.report. In Odoo 18, the supported API is _render_qweb_pdf:

from odoo import models, api
import base64

class MyModel(models.Model):
    _name = 'my.model'

    def action_generate_pdf(self):
        report = self.env.ref('my_app.my_report')

        pdf_content, _ = report._render_qweb_pdf(self.id)

        self.write({
            'report_pdf': base64.b64encode(pdf_content),
            'report_pdf_name': f'Report_{self.id}.pdf',
        })
This method renders the same PDF as your XML report definition, but instead of returning it to the browser, it stores it directly in the database.
Setting attachment=True on the binary field ensures the file is stored efficiently in ir.attachment and can be downloaded later. You can then expose this field in a form view to allow users to download the stored PDF.


Hope it helps

0
Avatar
Abbandona
Avatar
Jainesh Shah(Aktiv Software)
Risposta migliore

Hello Boris Giordanengo ,

 

Yes, you can generate a PDF report and store it in a Binary field in Odoo 18 using a custom module. You can achieve this by following the steps below

 

1) Add New Fields to Your Model

class MyModel(models.Model):

    _name = 'my.model'

   

    report_id = fields.Binary(

        string='PDF Report',

        attachment=True

    )

    report_filename = fields.Char(string='Report Filename')

 

 2) Add Button and Fields to Your Form View

           

<button name="action_generate_pdf_report"

                    type="object"

                    string="Generate PDF"

                    class="btn-primary"/>

 

3) Create the Button Action:

       Define a Python method that generates the PDF report and stores it in the Binary field

 

4) Generate and Store the PDF:

       When you click the Generate PDF button, the report will be generated and automatically stored in the Binary field as an attachment

 

This solution allows you to generate a PDF report and store it directly in a Binary field using standard Odoo functionality.


If you have any questions, feel free to reach out.

Hope this helps!


Thanks and Regards,

Email: odoo@aktivsoftware.com

0
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Where is the PDF Partner Ledger QWeb Report and View in Odoo Online?
v18
Avatar
Avatar
1
dic 25
3352
Change Sign & Pay Button on Quotation E-mails
v18
Avatar
Avatar
Avatar
Avatar
3
nov 25
595
Problem including JS asset in v18
v18
Avatar
Avatar
Avatar
3
nov 25
8986
Code for page number in Body of Pdf report
reports
Avatar
Avatar
Avatar
2
ott 25
3407
How to increase the width of a column on odoo quotation PDF?
reports
Avatar
Avatar
1
ott 25
1253
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now