2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Adds a LabelPrintingMixin plugin class

- Enables the implementation of custom label printing plugins
- Will be available directly from the "print labels" dialog box
This commit is contained in:
Oliver
2022-03-24 12:51:27 +11:00
parent 170c4dfd4c
commit 69e9d1625a
2 changed files with 56 additions and 1 deletions

View File

@ -393,6 +393,59 @@ class AppMixin:
return True
class LabelPrintingMixin:
"""
Mixin which enables direct printing of stock labels.
Each plugin should provide a PRINTER_NAME attribute,
and also implement the print_label() function
"""
class MixinMeta:
"""
Meta options for this mixin
"""
MIXIN_NAME = 'Label printing'
def __init__(self):
super().__init__()
self.add_mixin('labels', 'has_label_printing', __class__)
@property
def has_label_printing(self):
if not bool(self.PRINTER_NAME):
raise ValueError("PRINTER_NAME must be defined")
return True
PRINTER_NAME = "LabelPrinter"
def get_printer_name(self):
return self.PRINTER_NAME
def print_labels(self, labels, **kwargs):
"""
Print multiple labels.
Default implementation is to call print_label() for each label,
but it can be overridden if desired.
"""
for label in labels:
self.print_label(label, **kwargs)
def print_label(self, label, **kwargs):
"""
Callback to print a single label
Arguments:
label: A black-and-white pillow Image object
"""
# Unimplemented (to be implemented by the particular plugin class)
...
class APICallMixin:
"""
Mixin that enables easier API calls for a plugin