support Click to see our new support page.
support For sales enquiry!

How to Create and Print Barcodes in Odoo 18

How to Create and Print Barcodes in Odoo 18 - Banner Image

AjazAug. 18, 2025

Introduction

Barcodes are essential tools that improve operational efficiency across inventory, sales, procurement, and logistics. By automating data entry and reducing errors, they enhance accuracy and speed in daily business processes.

Odoo 18 offers a powerful barcode engine that allows users to generate and print barcodes for any business model. In this guide, we’ll show you how to implement barcode functionality using the Sale Order model as an example — a method easily adaptable to other models.

 


Step 1: Extend the Sale Order Model with a Barcode Field

 

  from odoo import models, fields, api

  class SaleOrder(models.Model):
    _inherit = 'sale.order'

    barcode = fields.Char(string="Barcode")

 

Note: Use @api.model and override the create method if you want to generate the barcode dynamically.

 


Step 2: Add the Barcode Field to the Sale Order Form View

 

  <odoo>
    <record id="sale_order_form_inherit" model="ir.ui.view">
      <field name="name">sale.order.form.barcode</field>
      <field name="model">sale.order</field>
      <field name="inherit_id" ref="sale.view_order_form"/>
      <field name="arch" type="xml">
        <xpath expr="//field[@name='payment_term_id']" position="after">
          <field name="barcode"/>
        </xpath>
      </field>
    </record>
  </odoo>

 


 

Step 3: Create a Report Action to Print Barcodes

 

  <record id="action_report_sale_barcode" model="ir.actions.report">
    <field name="name">Sale Order Barcode</field>
    <field name="model">sale.order</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">sales_custom.barcode_template</field>
    <field name="report_file">sales_custom.barcode_template</field>
    <field name="print_report_name">'Sale Order Barcode (PDF)'</field>
    <field name="binding_model_id" ref="sale_management.model_sale_order"/>
    <field name="binding_type">report</field>
  </record>

 


 

Step 4: Define the QWeb Template to Display the Barcode

 

<template id="barcode_template">
  <t t-call="web.html_container">
    <t t-foreach="docs" t-as="doc">
      <t t-call="web.external_layout">
        <div class="page">
          <h2><span t-field="doc.name"/></h2>
          <img t-if="doc.barcode"
              style="width:400px;height:70px;"
              t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', doc.barcode, 265, 80)"/>
          <div><t t-esc="doc.barcode"/></div>
        </div>
      </t>
    </t>
  </t>
</template>

 


Final Output

After completing these steps:

  • A barcode field is added to your Sale Orders.
     
  • Users can generate barcodes automatically.
     
  • Printable barcode PDFs are available via Actions → Print → Sale Order Barcode.
     

 


Conclusion

Adding barcodes to your Odoo system improves traceability, accuracy, and efficiency across departments. While we demonstrated this with Sale Orders, the same concept can be extended to other models like Products, Deliveries, or Invoices.

This guide serves as a base to create a customized barcode system tailored to your business needs.

0

Leave a Comment

Subscribe to our Newsletter

Sign up to receive more information about our latest offers & new product announcement and more.