Fix broken barcode commands.

UPC wasn't working, and EAN wasn't even being attempted...
This commit is contained in:
Lance Edgar 2014-05-11 13:57:42 -07:00
parent a37c0565ee
commit 8e74be71f9

View file

@ -78,9 +78,25 @@ class BlasterTwoUpFormatter(labels.TwoUpCommandFormatter, BlasterFormatter):
half_offset = 120 half_offset = 120
def label_body_commands(self, product, x=0): def label_body_commands(self, product, x=0):
description = '%s %s' % (product.description, product.size)
# Always remove check digit from UPC.
upc = unicode(product.upc)[:-1]
if len(upc) != 13:
raise ValueError(u"UPC format is unexpected: {0}".format(repr(product.upc)))
# Create barcode command based on type of UPC.
if upc.startswith(u'00'): # UPC-A
barcode_type = u'UPCA+'
barcode = upc[2:]
elif upc.startswith(u'0'): # EAN-13
barcode_type = u'EAN13+'
barcode = upc[1:]
else:
raise ValueError(u"UPC format is invalid: {0}".format(repr(product.upc)))
description = u'{0} {1}'.format(product.description, product.size)
return [ return [
'STRING 5X7(1,1,1,1) %u 5 %s' % (x + 5, description[:17]), u'STRING 5X7(1,1,1,1) {0} 5 {1}'.format(x + 5, description[:17]),
'STRING 5X7(1,1,1,1) %u 15 %s' % (x + 5, description[17:]), u'STRING 5X7(1,1,1,1) {0} 15 {1}'.format(x + 5, description[17:]),
'BARCODE UPCA+ %u 75 25 %011u' % (x + 9, product.upc), u'BARCODE {0} {1} 75 25 {2}'.format(barcode_type, x + 9, barcode),
] ]