How to show Item barcode inside Sales order print format (standard or jinja custom is fine)

We need to show the barcode for the item inside the sales order which is vital for our production team and customers as we use different barcodes.

Is there any way to print the barcodes from Item Master in the custom print format?

@ramielian go through the link of the post below showing on how to print only barcodes in separate print format.

Hi @ramielian

You have to create a new print format and making the “Print Format Type” is Jinja.

And write this HTML Code:

    <div style="text-align: center; backgound: #000000; margin-top: 0 px; margin-bottom: 0 px; height:12px;">&nbsp;</div>
    <div style="text-align: center; backgound: #000000; margin-top: 0 px; margin-bottom: 0 px;height:15px;">Your Company Name if there any Need</div>
    <div style="margin-right:5px; border: #000 solid 0px; height:14px; overflow:hidden; text-align: center; backgound: #000000; margin-top: 0 px; margin-bottom: 0 px;">{{doc.item_name}}</div>
    <div style="text-align:center; backgound:#000000" >
    <svg class="barcode"
     jsbarcode-margin="0"
     jsbarcode-margintop="5"
     jsbarcode-marginright="15"
     jsbarcode-marginleft="1"
     jsbarcode-height="25"
     jsbarcode-width="1"
     jsbarcode-fontsize="12"
     jsbarcode-textalign="Center"
     jsbarcode-value="{{doc.name}}"/>
  </div>

<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.9.0/dist/JsBarcode.all.min.js"></script>

<script>
JsBarcode(".barcode").init();
</script>

Please let me know if there are any queries.

6 Likes

Printing the Barcode it self is not a big deal, the issue is how to get the value of the barcode into sales order item

@ramielian,

I’m sure that you have enabled the barcode option in the “Stock Settings”.

When you enable the “Show Barcode Field”, you will find the “Scan Barcode” in “Sales Order”.

Just when you scan the barcode it will add the item directly into the “Sales Order Item” table.

Yes, but the Barcode value is not stored in Sales order item table.

one way of doing it would be to:

  1. Create a custom field in sales order item table,
  2. Using custom scripts, add a handler to item_code field in the sales order item table, get the barcode list using frappe.db.get_doc and set_value to the custom field.

Another way would be to use frappe.get_doc in the Jinja Template to get the barcode while printing, but that would be very resource heavy while printing.

ok, maybe i did not explain good enough:

We need to add the BARCODE from the item master to sales order item so we can print it, ERPNext / frappe does not support grandchild tables (a table inside another table) and the barcode is saved in a table inside the item master.

how could we get this value in this case?

Try this code … this code is to generate a barcode by naming series and will put the barcode in the barcode table.

frappe.ui.form.on('Item',
{
validate: function(frm) {
if (!frm.is_new()){
 if (frm.doc.barcodes.length==0){
 frm.add_child("barcodes");
 frm.fields_dict.barcodes.get_value()[0].barcode = frm.doc.name;
cur_frm.save();
}
}
},
});

I am lost in the code, why on Item?

i think you are lost in the translation, I need the barcode in sales order and sales invoice printing, I don’t mind to have it as a field, but this does not seem to get the value from anywhere like I mentioned.