13
13
# translation
14
14
from django .utils .translation import ugettext_lazy as _
15
15
16
+ # printing options
17
+ from rest_framework import serializers
18
+
16
19
from inventree_brother .version import BROTHER_PLUGIN_VERSION
17
20
18
21
# InvenTree plugin libs
@@ -47,6 +50,19 @@ def get_rotation_choices():
47
50
return [(f"{ degree } " , f"{ degree } °" ) for degree in [0 , 90 , 180 , 270 ]]
48
51
49
52
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
+
50
66
class BrotherLabelPlugin (LabelPrintingMixin , SettingsMixin , InvenTreePlugin ):
51
67
52
68
AUTHOR = "Oliver Walters"
@@ -57,6 +73,8 @@ class BrotherLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
57
73
SLUG = "brother"
58
74
TITLE = "Brother Label Printer"
59
75
76
+ PrintingOptionsSerializer = BrotherLabelSerializer
77
+
60
78
# Use background printing
61
79
BLOCKING_PRINT = False
62
80
@@ -120,6 +138,11 @@ def print_label(self, **kwargs):
120
138
# ^ currently this width and height are those of the label template (before conversion to PDF
121
139
# and PNG) and are of little use
122
140
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
+
123
146
# Look for png data in kwargs (if provided)
124
147
label_image = kwargs .get ('png_file' , None )
125
148
@@ -184,9 +207,10 @@ def print_label(self, **kwargs):
184
207
185
208
instructions = convert (** params )
186
209
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
+ )
0 commit comments