The following is a Print Format to print labels use zpl that have individual serial numbers for each label.
I use it from Purchase receipts so that the labels can be printed upon receipt.
It will print directly to the printer (do not put raw printing on) but the output is fussy about which browser you use. SeaMonkey worked the best for me.
In the Print Format choose Custom Format - the following was used in the Purchase receipt doctype:
<h1>Print Labels</h1>
<p>This works dirrerently on different browsers - SeaMonkey works well.
The Zebra printer driver needs to be set to take text only.</p>
<ul>
<!-- Loop through items received -->
{% for row in doc.items %}
<p> </p>
<!-- The following script is thanks to https://jsfiddle.net/lakerfield/8jtL87n7/4/ -->
<script type="text/javascript">
function printZpl(zpl) {
var printWindow = window.open();
printWindow.document.open('text/plain')
printWindow.document.write(zpl);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
</script>
<!-- Serial numbers are concatenated in the serial_no field and need to be extracted individually -->
<input type="button" value="Print zpl " onclick="printZpl(document.getElementById('zplcode').value)" /><br/>
<textarea id="zplcode" cols="50" rows="12">
{# Loop through each serial number, extract the serial no. and create a label for it #}
{% for pack in range(row.received_qty) %}
^XA
^FO50,30
^A0N,66,55^FD{{ row.description }}^FS
^FO50,90
^A0N,44,33^FDOrigin:^FS
^FO150,90
^A0N,44,33^FD{{ doc.supplier_name }}^FS
^FO650,100
^A0N,28,22^FD{{ doc.posting_date }}^FS
^FO50,170
^A0B,28,21^FDBatch No^FS
^FO80,150^BY3
^BCN,80,Y,N,N
^FD{{ row.batch_no }}^FS
^FO50,300
^A0B,28,21^FDSerial No^FS
^FO700,350
^A0N,28,22^FD {{ pack + 1 }} of {{ row.received_qty|string }}^FS
^FO80,280^BY3
^BCN,80,Y,N,N
^FD{{ row.serial_no[(pack*(row.serial_no|length+1)/row.received_qty)|int:((pack+1)*(row.serial_no|length+1)/row.received_qty-1)|int] }}^FS
^XZ
{% endfor %}
</textarea>
{% endfor %}
</ul>
When you print the next screen will be as follows:
The resultant label will be: