fix(label): Serialize only a few fields
This commit is contained in:
parent
b52ee09b90
commit
f44590a9f5
1 changed files with 21 additions and 2 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue