mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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:
parent
170c4dfd4c
commit
69e9d1625a
@ -393,6 +393,59 @@ class AppMixin:
|
|||||||
return True
|
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:
|
class APICallMixin:
|
||||||
"""
|
"""
|
||||||
Mixin that enables easier API calls for a plugin
|
Mixin that enables easier API calls for a plugin
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
Utility class to enable simpler imports
|
Utility class to enable simpler imports
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..builtin.integration.mixins import APICallMixin, AppMixin, SettingsMixin, EventMixin, ScheduleMixin, UrlsMixin, NavigationMixin
|
from ..builtin.integration.mixins import APICallMixin, AppMixin, LabelPrintingMixin, SettingsMixin, EventMixin, ScheduleMixin, UrlsMixin, NavigationMixin
|
||||||
|
|
||||||
from ..builtin.action.mixins import ActionMixin
|
from ..builtin.action.mixins import ActionMixin
|
||||||
from ..builtin.barcode.mixins import BarcodeMixin
|
from ..builtin.barcode.mixins import BarcodeMixin
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ __all__ = [
|
|||||||
'APICallMixin',
|
'APICallMixin',
|
||||||
'AppMixin',
|
'AppMixin',
|
||||||
'EventMixin',
|
'EventMixin',
|
||||||
|
'LabelPrintingMixin',
|
||||||
'NavigationMixin',
|
'NavigationMixin',
|
||||||
'ScheduleMixin',
|
'ScheduleMixin',
|
||||||
'SettingsMixin',
|
'SettingsMixin',
|
||||||
|
Loading…
Reference in New Issue
Block a user