From f44590a9f5a2df20017b7a2cea8852491a879053 Mon Sep 17 00:00:00 2001 From: Andreas Mieke Date: Thu, 18 Apr 2024 00:53:43 -0400 Subject: [PATCH] fix(label): Serialize only a few fields --- inventree_phomemo/phomemo_label.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/inventree_phomemo/phomemo_label.py b/inventree_phomemo/phomemo_label.py index d4c093e..0bcd66e 100644 --- a/inventree_phomemo/phomemo_label.py +++ b/inventree_phomemo/phomemo_label.py @@ -40,14 +40,33 @@ class PhomemoLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin): # Read settings ip_address = self.get_setting('IP_ADDRESS') port = int(self.get_setting('PORT')) - label_data = kwargs['label_instance'].object_to_print + + object_to_print = kwargs['label_instance'].object_to_print + + if kwargs['label_instance'].SUBDIR == 'part': + tpart = object_to_print + elif kwargs['label_instance'].SUBDIR == 'stockitem': + tpart = object_to_print.part + else: + print(f"!! Unsupported item type: {object_to_print.SUBDIR}") + return + + fields = { + 'name': tpart.name, + 'description': tpart.description, + 'pk': tpart.pk, + 'params': tpart.parameters_map(), + 'category': tpart.category.name, + 'category_path': tpart.category.pathstring, + 'qr_data': kwargs['qr_data'] + } # Send the label to the printer try: print_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print_socket.settimeout(5) print_socket.connect((ip_address, port)) - json.dump(label_data, print_socket) + json.dump(fields, print_socket) print_socket.close() except Exception as error: raise ConnectionError('Error connecting to printer server: ' + str(error))