feat(label): Switch to custom barcode with numbers only

This commit is contained in:
Andreas Mieke 2024-04-20 21:51:01 -04:00
parent a732fb3d4a
commit 43c5c8a5ba
Signed by: zenermerps
SSH key fingerprint: SHA256:Ne+hwc5QIgYlqCuLZ0LV3301Wo/p8UoGOrGC+T6S0t8

View file

@ -42,18 +42,24 @@ class PhomemoLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
port = int(self.get_setting('PORT')) port = int(self.get_setting('PORT'))
object_to_print = kwargs['label_instance'].object_to_print object_to_print = kwargs['label_instance'].object_to_print
key = object_to_print.pk
kind = ''
if kwargs['label_instance'].SUBDIR == 'part': match kwargs['label_instance'].SUBDIR:
case 'part':
tpart = object_to_print tpart = object_to_print
kind = 'part' barcode = '1' + str(object_to_print.pk)
elif kwargs['label_instance'].SUBDIR == 'stockitem': case 'stockitem':
tpart = object_to_print.part tpart = object_to_print.part
kind = 'stockitem' barcode = '2' + str(object_to_print.pk)
else: case 'location':
tpart = object_to_print
barcode = '3' + str(object_to_print.pk)
case 'build':
tpart = object_to_print
barcode = '4' + str(object_to_print.pk)
case _:
tpart = object_to_print
barcode = '0' + str(object_to_print.pk)
print(f"!! Unsupported item type: {object_to_print.SUBDIR}") print(f"!! Unsupported item type: {object_to_print.SUBDIR}")
return
fields = { fields = {
'name': tpart.name, 'name': tpart.name,
@ -62,8 +68,7 @@ class PhomemoLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
'params': tpart.parameters_map(), 'params': tpart.parameters_map(),
'category': tpart.category.name, 'category': tpart.category.name,
'category_path': tpart.category.pathstring, 'category_path': tpart.category.pathstring,
'kind': kind, 'barcode': barcode
'ppk': key
} }
data = json.dumps(fields) data = json.dumps(fields)