Skip to content

Commit

Permalink
fix driver to new interface working in workers
Browse files Browse the repository at this point in the history
  • Loading branch information
wolflu05 committed Jul 10, 2024
1 parent 9522c74 commit 35eac3b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 10 additions & 6 deletions inventree_dymo/InvenTreeDymoPlugin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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', {})

Expand All @@ -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')
Expand All @@ -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}")
2 changes: 1 addition & 1 deletion inventree_dymo/dymo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
*,
Expand Down

0 comments on commit 35eac3b

Please sign in to comment.