ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

[Solution] 2D Barcodes and Programmatically show serial numbers

print_format
barcode

#1

I am sharing a simple solution (most of the developers knows, but helpful for newbies like me) to show 2D barcode (or any type) on the delivery note.

Also through Jinja Format we can hide some serial number based on products. For example if you don’t want to show a product’s serial number create a custom field (check-box), and tag them. Find below code to print/not to print the tagged product’s serial number(s).

here is my delivery note output.

Header

<div class="print-heading">
<h2>Delivery Note</h2>
<br>

<div style="display:block">

<p>{{ doc.name }}</p>
<br>
<p>Date: {{ frappe.utils.get_datetime(doc.posting_date).strftime('%d-%m-%Y') }}</p>
<br /><img src="http://bwipjs-api.metafloor.com/?bcid=code128&text={{ doc.name }}&scaleX=1&scaleY=1" alt="barcode" height="10" width="200">
</div></div>

Serial Numbers (without any conditions)

<h6>Serial Number in 2D barcode format</h6>
{% for row in  doc.items %}
<div style="content: "";display: table;clear: both;">
  <div  style="float: left;width: 50%;padding: 10px;">
<figure>

   <img  src="http://bwipjs-api.metafloor.com/?bcid=pdf417&text={{ row.serial_no }} " alt="barcode" align="middle" hspace="20">
<figcaption align="middle">{{ row.item_code }}</figcaption>

<figure>
  </div>
  
</div>

{% endfor %}

Show serial number(s) Based on some conditions - Here I used tra (I created a check box called tra on product master)

<h6>Serial Number in 2D barcode format</h6>
{% set c = frappe.get_doc("Item", doc.item) %}
       {{ c.tra or '0' }}
       


{% for row in  doc.items if c.tra %}

{{ row.tra }}

<div style="content: "";display: table;clear: both;">
  <div  style="float: left;width: 50%;padding: 10px;">
<figure>

   <img  src="http://bwipjs-api.metafloor.com/?bcid=pdf417&text={{ row.serial_no }} " alt="barcode" align="middle" hspace="20">
<figcaption align="middle">{{ row.item_code }}</figcaption>

<figure>
  </div>
  
</div>

{% endfor %}

on the line {% for row in doc.items if c.tra %} you can include IF NOT to toggle the checkbox.

thanks


#2

Hi @Riyas_Rawther,

thanks for sharing! So you are using an external barcode generator which uses the HTML request parameters to make a barcode and return an image. We have found this to work reliably and also apply it to QR codes and even charts (when they need to be printed).


#3

HI @Riyas_Rawther , Any chance this can be in the core frappe ?


#4

more about the API can be found on https://github.com/metafloor/bwip-js/wiki/Online-Barcode-API