Skip to content

Commit 6397c4b

Browse files
Merge pull request #31 from inventree/print-copies
Add printing options framework
2 parents 6ffcc6d + 1018f44 commit 6397c4b

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

inventree_brother/brother_plugin.py

+30-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# translation
1414
from django.utils.translation import ugettext_lazy as _
1515

16+
# printing options
17+
from rest_framework import serializers
18+
1619
from inventree_brother.version import BROTHER_PLUGIN_VERSION
1720

1821
# InvenTree plugin libs
@@ -47,6 +50,19 @@ def get_rotation_choices():
4750
return [(f"{degree}", f"{degree}°") for degree in [0, 90, 180, 270]]
4851

4952

53+
class BrotherLabelSerializer(serializers.Serializer):
54+
"""Custom serializer class for BrotherLabelPlugin.
55+
56+
Used to specify printing parameters at runtime
57+
"""
58+
59+
copies = serializers.IntegerField(
60+
default=1,
61+
label=_('Copies'),
62+
help_text=_('Number of copies to print'),
63+
)
64+
65+
5066
class BrotherLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
5167

5268
AUTHOR = "Oliver Walters"
@@ -57,6 +73,8 @@ class BrotherLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
5773
SLUG = "brother"
5874
TITLE = "Brother Label Printer"
5975

76+
PrintingOptionsSerializer = BrotherLabelSerializer
77+
6078
# Use background printing
6179
BLOCKING_PRINT = False
6280

@@ -120,6 +138,11 @@ def print_label(self, **kwargs):
120138
# ^ currently this width and height are those of the label template (before conversion to PDF
121139
# and PNG) and are of little use
122140

141+
# Printing options requires a modern-ish InvenTree backend,
142+
# which supports the 'printing_options' keyword argument
143+
options = kwargs.get('printing_options', {})
144+
n_copies = int(options.get('copies', 1))
145+
123146
# Look for png data in kwargs (if provided)
124147
label_image = kwargs.get('png_file', None)
125148

@@ -184,9 +207,10 @@ def print_label(self, **kwargs):
184207

185208
instructions = convert(**params)
186209

187-
send(
188-
instructions=instructions,
189-
printer_identifier=f'tcp://{ip_address}',
190-
backend_identifier='network',
191-
blocking=True
192-
)
210+
for _i in range(n_copies):
211+
send(
212+
instructions=instructions,
213+
printer_identifier=f'tcp://{ip_address}',
214+
backend_identifier='network',
215+
blocking=True
216+
)

inventree_brother/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version information for the plugin"""
22

3-
BROTHER_PLUGIN_VERSION = "0.7.2"
3+
BROTHER_PLUGIN_VERSION = "0.8.0"

0 commit comments

Comments
 (0)