Barcode Generation in Odoo 17

January 8, 2026 by
Barcode Generation in Odoo 17
Liu
| No comments yet

Mastering Barcode & QR Code Generation in Odoo 17

Odoo 17 provides a robust framework for generating and rendering various barcodes and QR codes directly within reports, forms, and website pages. This guide explores the technical implementation using the report module and Python logic.


1. The Core Mechanism: report.barcode

Odoo handles code generation through a dedicated controller. Instead of manually generating images, you call a specific URL pattern that Odoo's rendering engine converts into a graphical representation.

The URL Pattern

The standard format for generating a code via URL is:

/report/barcode/?barcode_type=TYPE&value=VALUE&width=WIDTH&height=HEIGHT&humanreadable=1



2. Implementation in QWeb Reports

To display a barcode in an Odoo report (like a Picking List or Invoice), use an <img> tag with a dynamic src attribute.

Standard Barcode (Code128)

HTML

<img t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', o.name, 600, 100)" 
     style="width:300px;height:50px;"/>

QR Code Generation

QR codes are essential for mobile triggers or digital payments.

HTML

<img t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', o.get_base_url(), 200, 200)" 
     style="width:100px;height:100px;"/>



3. Supported Symbologies

Odoo 17 supports a wide range of industrial and retail standards. Choosing the right barcode_type is critical for scanner compatibility:

TypeBest Use Case
Code128General purpose, alphanumeric (Shipping labels)
EAN13Retail products (International)
UPCARetail products (North America)
QRURLs, vCards, complex data strings
GS1-128Logistics and supply chain data



4. Python Implementation (Backend)

Sometimes you need to generate a barcode in the backend to save it as a field or send it via API. You can use the barcode request helper.

Python

from odoo import models

class ProductTemplate(models.Model):
    _inherit = 'product.template'

    def get_qr_code_base64(self):
        # Generate the barcode via the report module's barcode function
        barcode_type = 'QR'
        value = self.barcode or 'No Data'
        # Returns the raw image data
        return self.env['ir.actions.report'].barcode(barcode_type, value, width=200, height=200, humanreadable=True)


5. Tips for Reliability

  1. URL Encoding: Ensure the value parameter is URL-safe if it contains special characters.
  2. Quiet Zones: Always leave white space around your QR codes in your CSS to ensure scanners can "lock on" to the alignment patterns.
  3. Human Readable: Set humanreadable=1 for retail barcodes so staff can manually type the code if the scanner fails.

Note: In Odoo 17, the barcode scanning interface (the "Barcode" App) is highly optimized for mobile devices using the barcode_mobile widget.


Barcode Generation in Odoo 17
Liu January 8, 2026
Share this post
Archive
Sign in to leave a comment