From 1cf5a5880776444ec84646a58a1fe03e2e9c3844 Mon Sep 17 00:00:00 2001 From: Andreas Mieke Date: Sun, 21 Apr 2024 21:40:35 -0400 Subject: [PATCH] fix(label): Change code to more reflect the mixin --- inventree_phomemo/phomemo_label.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/inventree_phomemo/phomemo_label.py b/inventree_phomemo/phomemo_label.py index c5ee53e..8058f51 100644 --- a/inventree_phomemo/phomemo_label.py +++ b/inventree_phomemo/phomemo_label.py @@ -40,10 +40,10 @@ class PhomemoLabelPlugin(LabelPrintingMixin, BarcodeMixin, SettingsMixin, InvenT }, } - def get_fields(self, **kwargs): - object_to_print = kwargs['label_instance'].object_to_print + def get_fields(self, label_instance): + object_to_print = label_instance.object_to_print - match kwargs['label_instance'].SUBDIR: + match label_instance.SUBDIR: case 'part': tpart = object_to_print barcode = '1' + str(object_to_print.pk) @@ -59,7 +59,7 @@ class PhomemoLabelPlugin(LabelPrintingMixin, BarcodeMixin, SettingsMixin, InvenT case _: tpart = object_to_print barcode = '0' + str(object_to_print.pk) - print(f"!! Unsupported item type: {kwargs['label_instance'].SUBDIR}") + print(f"!! Unsupported item type: {label_instance.SUBDIR}") fields = { 'name': tpart.name, @@ -69,9 +69,9 @@ class PhomemoLabelPlugin(LabelPrintingMixin, BarcodeMixin, SettingsMixin, InvenT 'category': tpart.category.name if hasattr(tpart, 'category') else None, 'category_path': tpart.category.pathstring if hasattr(tpart, 'category') else None, 'barcode': barcode, - 'type': kwargs['label_instance'].SUBDIR, - 'width': kwargs['width'], - 'height': kwargs['height'] + 'type': label_instance.SUBDIR, + 'width': label_instance.width, + 'height': label_instance.height } return fields @@ -82,7 +82,7 @@ class PhomemoLabelPlugin(LabelPrintingMixin, BarcodeMixin, SettingsMixin, InvenT # Get label content for every label for item in items: label.object_to_print = item - outputs.append(self.print_label(label, request, **kwargs)) + outputs.append(self.get_fields(label)) # Read settings ip_address = self.get_setting('IP_ADDRESS') @@ -106,10 +106,6 @@ class PhomemoLabelPlugin(LabelPrintingMixin, BarcodeMixin, SettingsMixin, InvenT 'message': f'{len(items)} labels printed', }) - def print_label(self, label: LabelTemplate, request, **kwargs): - self.render_to_html(label, request, **kwargs) - return self.get_fields(**kwargs) - @staticmethod def get_supported_barcode_models():