2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 12:05:53 +00:00

Allow offloading of label printing to the configured plugin

This commit is contained in:
Oliver
2022-03-24 14:57:01 +11:00
parent f1f07a1977
commit 6c25a5805d
4 changed files with 111 additions and 28 deletions

View File

@ -415,15 +415,6 @@ class LabelPrintingMixin:
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

View File

@ -95,7 +95,11 @@ def process_event(plugin_slug, event, *args, **kwargs):
logger.info(f"Plugin '{plugin_slug}' is processing triggered event '{event}'")
plugin = registry.plugins[plugin_slug]
plugin = registry.plugins.get(plugin_slug, None)
if plugin is None:
logger.error(f"Could not find matching plugin for '{plugin_slug}'")
return
plugin.process_event(event, *args, **kwargs)
@ -186,3 +190,25 @@ def after_delete(sender, instance, **kwargs):
model=sender.__name__,
table=table,
)
def print_label(plugin_slug, label_image, **kwargs):
"""
Print label with the provided plugin.
This task is nominally handled by the background worker.
Arguments:
plugin_slug: The unique slug (key) of the plugin
label_image: A PIL.Image image object to be printed
"""
logger.info(f"Plugin '{plugin_slug}' is printing a label")
plugin = registry.plugins.get(plugin_slug, None)
if plugin is None:
logger.error(f"Could not find matching plugin for '{plugin_slug}'")
return
plugin.print_label(label_image)