From 35eac3b81f085923d8ee370374baf7dc3785a69f Mon Sep 17 00:00:00 2001 From: wolflu05 <76838159+wolflu05@users.noreply.github.com> Date: Wed, 10 Jul 2024 11:51:09 +0200 Subject: [PATCH 1/3] fix driver to new interface working in workers --- README.md | 2 +- inventree_dymo/InvenTreeDymoPlugin.py | 16 ++++++++++------ inventree_dymo/dymo.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6d2beab..1dcff97 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ The easiest way to set this up, is using cups and configure a RAW printer device ## Installation > [!IMPORTANT] -> This plugin is only compatible with InvenTree>=0.14 because this uses the new label printer driver interface introduced with [inventree/InvenTree#4824](https://github.com/inventree/InvenTree/pull/4824). +> This plugin is only compatible with InvenTree>=0.16 because this uses the new label printer driver interface introduced with [inventree/InvenTree#4824](https://github.com/inventree/InvenTree/pull/4824). Goto "Admin Center > Plugins > Install Plugin" and enter `inventree-dymo-plugin` as package name. diff --git a/inventree_dymo/InvenTreeDymoPlugin.py b/inventree_dymo/InvenTreeDymoPlugin.py index 5fcf07c..cbd9462 100644 --- a/inventree_dymo/InvenTreeDymoPlugin.py +++ b/inventree_dymo/InvenTreeDymoPlugin.py @@ -1,13 +1,12 @@ import socket +from django.db import models from django.db.models.query import QuerySet -from rest_framework.request import Request from django.utils.translation import gettext_lazy as _ from django.core.validators import MinValueValidator, MaxValueValidator from plugin import InvenTreePlugin -from plugin.base.label.mixins import LabelItemType from plugin.machine.machine_types import LabelPrinterBaseDriver, LabelPrinterMachine -from label.models import LabelTemplate +from report.models import LabelTemplate from .version import DYMO_PLUGIN_VERSION from .dymo import DymoLabel, RoleSelect, PrintDensity @@ -94,7 +93,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - def print_labels(self, machine: LabelPrinterMachine, label: LabelTemplate, items: QuerySet[LabelItemType], request: Request, **kwargs): + def print_labels(self, machine: LabelPrinterMachine, label: LabelTemplate, items: QuerySet[models.Model], **kwargs): """Print labels using a Dymo label printer.""" printing_options = kwargs.get('printing_options', {}) @@ -109,12 +108,16 @@ def print_labels(self, machine: LabelPrinterMachine, label: LabelTemplate, items for item in items: dpi = {"TEXT": 300, "GRAPHIC": 600}[dymo_label.mode] - png = self.render_to_png(label, item, request, dpi=dpi) + png = self.render_to_png(label, item, dpi=dpi) for _copies in range(printing_options.get('copies', 1)): dymo_label.add_label(png) data = dymo_label.get_data() + self.send_data(machine, data) + + def send_data(self, machine: LabelPrinterMachine, data: bytearray): + machine.set_status(LabelPrinterMachine.MACHINE_STATUS.UNKNOWN) ip_addr = machine.get_setting('SERVER', 'D') port = machine.get_setting('PORT', 'D') @@ -125,4 +128,5 @@ def print_labels(self, machine: LabelPrinterMachine, label: LabelTemplate, items print_socket.send(data) print_socket.close() except Exception as e: - raise ConnectionError(f"Error connection to network printer: {e}") + machine.set_status(LabelPrinterMachine.MACHINE_STATUS.DISCONNECTED) + machine.handle_error(f"Error connecting to network printer: {e}") diff --git a/inventree_dymo/dymo.py b/inventree_dymo/dymo.py index 430c142..8e6fe80 100644 --- a/inventree_dymo/dymo.py +++ b/inventree_dymo/dymo.py @@ -286,7 +286,7 @@ def dump_label(self, png: Image.Image): self.pb.short_form_feed() -class DymoTape(DymoLabel): +class DymoTape(DymoLabelBase): def __init__( self, *, From c6d88b0635d00991dc394f45b9bedef8bbcafc86 Mon Sep 17 00:00:00 2001 From: wolflu05 <76838159+wolflu05@users.noreply.github.com> Date: Wed, 10 Jul 2024 11:58:02 +0200 Subject: [PATCH 2/3] bump version to v1.0.0 --- inventree_dymo/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inventree_dymo/version.py b/inventree_dymo/version.py index 2b2f305..9815b4a 100644 --- a/inventree_dymo/version.py +++ b/inventree_dymo/version.py @@ -1 +1 @@ -DYMO_PLUGIN_VERSION = "0.1.0" +DYMO_PLUGIN_VERSION = "1.0.0" From 074f3265b9fbbe1f56976bccd58862e70805aadc Mon Sep 17 00:00:00 2001 From: wolflu05 <76838159+wolflu05@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:00:17 +0200 Subject: [PATCH 3/3] fix: min version --- README.md | 2 +- inventree_dymo/InvenTreeDymoPlugin.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1dcff97..8821ec6 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ The easiest way to set this up, is using cups and configure a RAW printer device ## Installation > [!IMPORTANT] -> This plugin is only compatible with InvenTree>=0.16 because this uses the new label printer driver interface introduced with [inventree/InvenTree#4824](https://github.com/inventree/InvenTree/pull/4824). +> This plugin is only compatible with InvenTree>=0.16 because this uses the new label printer driver interface introduced with [inventree/InvenTree#4824](https://github.com/inventree/InvenTree/pull/4824) and was fixed with 0.16 to work inside of workers. Goto "Admin Center > Plugins > Install Plugin" and enter `inventree-dymo-plugin` as package name. diff --git a/inventree_dymo/InvenTreeDymoPlugin.py b/inventree_dymo/InvenTreeDymoPlugin.py index cbd9462..75e26ef 100644 --- a/inventree_dymo/InvenTreeDymoPlugin.py +++ b/inventree_dymo/InvenTreeDymoPlugin.py @@ -18,7 +18,8 @@ class InvenTreeDymoPlugin(InvenTreePlugin): VERSION = DYMO_PLUGIN_VERSION # Machine driver registry is only available in InvenTree 0.14.0 and later - MIN_VERSION = "0.14.0" + # Machine driver interface was fixed with 0.16.0 to work inside of inventree workers + MIN_VERSION = "0.16.0" TITLE = "InvenTree Dymo Plugin" SLUG = "inventree-dymo-plugin"