fix(label): Serialize only a few fields

This commit is contained in:
Andreas Mieke 2024-04-18 00:53:43 -04:00
parent b52ee09b90
commit f44590a9f5
Signed by: zenermerps
SSH key fingerprint: SHA256:Ne+hwc5QIgYlqCuLZ0LV3301Wo/p8UoGOrGC+T6S0t8

View file

@ -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))