Enable Dark Mode!
how-to-add-barcode-in-qweb-pdf-report.jpg
By: Nafih VK

How to Add Barcode in Qweb PDF Report?

Technical

Barcode is the inevitable factor in the business environment. Furthermore, it is a machine-readable code with a mix of numbers and patterns of parallel lines of varying widths. Barcode is used in many modules inside Odoo, such as Inventory, POS,  for describing product template, etc.
This blog will provide an insight into how you can add barcodes in Qweb PDF reports on the Odoo platform.
To view the print a barcode option in Odoo,
Open product form view, and navigate as per the following:
Sales module > Products Menu > Open any product > Print > product Barcode
Before you print the barcode, ensure that the data in the “Barcode” description under the general information of the product form view is correct.
how-to-add-barcode-in-qweb-pdf-report-cybrosys
As Odoo supports any string as a barcode, you'll always define your own barcode format for internal use. Therefore, you can provide the barcodes as a mix of  Integers and characters. In addition, barcode nomenclatures are the principles that are used to create a barcode. You can configure your barcode nomenclature menu accessible from the Inventory > Configuration > Barcode Nomenclature.
To know more about barcode nomenclature view the following video:
A Barcode scanner is a gadget that catches and interprets the data contained by a standardized tag. Moreover, customary standardized tag scanners comprise of the accompanying four parts:
Light source: This aids the scanner tag peruse and precisely unravel the data contained in a standardized identification.
Focal point: This sweeps the scanner tag.
Photoconductor: This makes an interpretation of optical driving forces into electrical ones.
Decoder: This examines the standardized tag's information, decodes it, and sends it to the scanner's yield port.
Subsequent to catching the data, standardized tag scanners are connected to a host PC or tablet and are sent continuously, without extra human mediation. This assists retailers with mechanizing information assortment measures and lessen human effort on stock following and handling retail location exchanges.
In addition, inside Odoo we have a module called barcode, which is used by the end-user to scan the barcodes and get the details. 
Let us see how to print a barcode in a Qweb report.
If you are making a Qweb report for the first time, please refer to our blog: How to Create a Pdf Report in Odoo 13
I have created a new report into partner view and added an XML template in which I have added an Image tag to contain the barcode which is depicted in the following code. Additionally, if we are looking to print a barcode inside a Qweb report, we may have to specify a barcode inside the “<img/>” tag.
how-to-add-barcode-in-qweb-pdf-report-cybrosys
Now we need to define the following parameter inside it.
<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', doc.barcode, 600, 100)"
    style="width:350px;height:60px;"/>
type=%s: It depends on the Nomenclature you use in the ERP system, here I give “Code128”, 
It  supports all barcode standards like EAN13, UPC 
value=%s: On which field are you generating barcode ie, doc.barcode
The rest of them are height and width. For better understanding, I have mentioned the following code.
<odoo>
   <template id="report_barcode">
       <t t-call="web.html_container">
           <t t-foreach="docs" t-as="doc">
               <t t-call="web.external_layout">
                   <div class="page">
                       <div class="oe_structure"/>
                       <div>
                           <div class="col-5">
                               <h2>
                                   <span t-field="doc.name"/>
                               </h2>
                               <br/>
                               <span style="margin-left:-60px;">
                                   <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', doc.barcode, 600, 100)"
                                        style="width:350px;height:60px;"/>
                               </span>
                               <span t-field="doc.barcode"/>
                           </div>
                       </div>
                   </div>
               </t>
           </t>
       </t>
   </template>
</odoo>
We can generate barcodes inside the customer form view as in the following image:
how-to-add-barcode-in-qweb-pdf-report-cybrosys
In the above template I have mentioned the partner name, barcode, and barcode string which will provide you with the resultant barcode image as shown below:
how-to-add-barcode-in-qweb-pdf-report-cybrosys
Furthermore, we can place barcodes anywhere in the template. However, while placing the barcode, we should consider the following things,
    - A barcode should be defined inside a “<img>” tag
    - Recommended format /report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s'
        1. Type - Barcode Type
        2. Value - Field
    - If you are defining a barcode inside a table column, make sure that proper style is given for the column and barcode.
        <table>
            <tr>
               <td>
                     <img alt="barcode"  
                            t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', doc.barcode, 600, 120)"
style="max-height:50pt;max-width:100%;"/>
                </td>
           </tr>
     </table>
In the image tag, if we don’t consider style, it can cause style issues and we may not get the barcode printed in the desired way. 


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message