Immagini prodotto in offerta odoo

Includere immagini dei prodotti nel report di vendita di Odoo può rendere i documenti più accattivanti e informativi. Questa guida ti guiderà attraverso i passaggi per attivare la modalità debug, individuare e modificare il template QWeb, e implementare una soluzione per visualizzare le immagini dei prodotti nel report dell’ordine di vendita.


Passo 1: Attiva la Modalità Debug

La modalità debug ti consente di accedere agli strumenti per sviluppatori in Odoo, inclusi i template QWeb.

    1. Accedi alla tua istanza di Odoo.
    2. Nella barra degli indirizzi del browser, aggiungi ?debug=1 all’URL corrente e ricarica la pagina. Ad esempio:
https://tua-istanza-odoo.com/web?#action=...&debug=1
  1. In alternativa, vai su Impostazioni > Attiva Modalità Sviluppatore (richiede diritti di amministratore).

Passo 2: Accedi alla Vista QWeb per il Report di Vendita

  1. Vai su Impostazioni > Tecnico > Interfaccia Utente > Viste.
  2. Cerca la vista denominata report_saleorder_document (questo è il template QWeb usato per il report dell’ordine di vendita).
  3. Fai clic sul record per aprire l’editor.

Passo 3: Modifica il Template QWeb

    1. Individua la sezione all’interno del ciclo <t t-foreach="doc.order_line" t-as="line">.
    2. Aggiungi il seguente codice per includere le immagini dei prodotti:
<img t-if="line.product_id.image_1920"
     t-att-src="/web/image/product.product/" + str(line.product_id.id) + "/image_1920"
     style="max-width: 100px; max-height: 100px;" />

Spiegazione:

    • t-if="line.product_id.image_1920": Garantisce che l’immagine venga inclusa solo se il prodotto ha un’immagine.
    • t-att-src: Genera dinamicamente l’URL dell’immagine utilizzando il percorso /web/image.
    • style: Imposta una dimensione massima per l’immagine per assicurarsi che si adatti correttamente al report.
  1. Salva le modifiche al template QWeb.

Passo 4: Testa il Report

  1. Vai su Vendite > Ordini > Preventivi o Ordini di Vendita.
  2. Apri un record e fai clic su Stampa > Preventivo / Ordine di Vendita.
  3. Verifica che le immagini dei prodotti vengano visualizzate correttamente nel report.

Note e Risoluzione dei Problemi

  • Immagini Non Visualizzate:
    • Verifica che i prodotti nell’ordine di vendita abbiano immagini caricate nel campo image_1920.
    • Assicurati che l’ID del prodotto sia valido.
  • Dimensioni delle Immagini Troppo Grandi:
    • Se le immagini dei prodotti sono troppo grandi, considera di ridimensionarle o utilizzare miniature più piccole come image_128.
  • Problemi di Rendering nei PDF:
    • Se le immagini appaiono correttamente nel browser ma non nei PDF, verifica che wkhtmltopdf sia installato e aggiornato correttamente sul server.

Perché Usare /web/image?

Il percorso /web/image serve dinamicamente le immagini archiviate nel database di Odoo. Questo metodo:

  • Evita di incorporare immagini codificate in base64 di grandi dimensioni.
  • Garantisce la compatibilità con le esportazioni PDF.
  • Ottimizza le prestazioni per report con più immagini.

Seguendo questi passaggi, puoi includere con successo le immagini dei prodotti nel report di vendita di Odoo, migliorando l’attrattiva visiva e l’informatività dei tuoi documenti. Per ulteriori consigli su personalizzazioni o domande, non esitare a contattarci!


Adding Product Images to Odoo Sale Quotation Report (QWeb)

Including product images in your Odoo sale report can make your documents more visually appealing and informative. This guide will walk you through the steps to activate debug mode, locate and edit the QWeb template, and implement a solution to display product images in the sale order report.


Step 1: Activate Debug Mode

Debug mode allows you to access developer tools in Odoo, including QWeb templates.

    1. Log in to your Odoo instance.
    2. In the URL bar of your browser, append ?debug=1 to the current URL and reload the page. For example:
https://your-odoo-instance.com/web?#action=...&debug=1
  1. Alternatively, navigate to Settings > Activate Developer Mode (requires admin rights).

Step 2: Access the QWeb View for the Sale Report

  1. Go to Settings > Technical > User Interface > Views.
  2. Search for the view named report_saleorder_document (this is the QWeb template used for the sale order report).
  3. Click on the record to open the editor.

Step 3: Modify the QWeb Template

    1. Locate the section within the <t t-foreach="doc.order_line" t-as="line"> loop.
    2. Add the following code to include product images:
<img t-if="line.product_id.image_1920"
     t-att-src="/web/image/product.product/" + str(line.product_id.id) + "/image_1920"
     style="max-width: 100px; max-height: 100px;" />

Explanation:

    • t-if="line.product_id.image_1920": Ensures the image is included only if the product has an image.
    • t-att-src: Dynamically generates the image URL using the /web/image route.
    • style: Sets a maximum size for the image to ensure it fits neatly in the report.
  1. Save the changes to the QWeb template.

Step 4: Test the Report

  1. Navigate to Sales > Orders > Quotations or Sale Orders.
  2. Open a record and click Print > Quotation / Sale Order.
  3. Check that the product images are displayed correctly in the report.

Notes and Troubleshooting

  • No Images Displayed:
    • Verify that the products in the sale order have images uploaded in the image_1920 field.
    • Ensure the product ID is valid.
  • Large Image Sizes:
    • If your product images are too large, consider resizing them or using smaller thumbnails like image_128.
  • PDF Rendering Issues:
    • If the images appear correctly in the browser but not in PDFs, ensure wkhtmltopdf is properly installed and updated on your server.

Why Use /web/image?

The /web/image route dynamically serves images stored in Odoo’s database. This method:

  • Avoids embedding large base64-encoded images.
  • Ensures compatibility with PDF exports.
  • Optimizes performance for reports with multiple images.

By following these steps, you can successfully include product images in your Odoo sale report, enhancing the visual appeal and informativeness of your documents. For further customization tips or questions, feel free to reach out!