From 43c5c8a5ba4f12b26df46c024ab63fd871fa5fea Mon Sep 17 00:00:00 2001 From: Andreas Mieke Date: Sat, 20 Apr 2024 21:51:01 -0400 Subject: [PATCH] feat(label): Switch to custom barcode with numbers only --- inventree_phomemo/phomemo_label.py | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/inventree_phomemo/phomemo_label.py b/inventree_phomemo/phomemo_label.py index 456948e..fc661cc 100644 --- a/inventree_phomemo/phomemo_label.py +++ b/inventree_phomemo/phomemo_label.py @@ -42,18 +42,24 @@ class PhomemoLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin): port = int(self.get_setting('PORT')) object_to_print = kwargs['label_instance'].object_to_print - key = object_to_print.pk - kind = '' - if kwargs['label_instance'].SUBDIR == 'part': - tpart = object_to_print - kind = 'part' - elif kwargs['label_instance'].SUBDIR == 'stockitem': - tpart = object_to_print.part - kind = 'stockitem' - else: - print(f"!! Unsupported item type: {object_to_print.SUBDIR}") - return + match kwargs['label_instance'].SUBDIR: + case 'part': + tpart = object_to_print + barcode = '1' + str(object_to_print.pk) + case 'stockitem': + tpart = object_to_print.part + barcode = '2' + str(object_to_print.pk) + 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}") fields = { 'name': tpart.name, @@ -62,8 +68,7 @@ class PhomemoLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin): 'params': tpart.parameters_map(), 'category': tpart.category.name, 'category_path': tpart.category.pathstring, - 'kind': kind, - 'ppk': key + 'barcode': barcode } data = json.dumps(fields)