mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 13:28:49 +00:00
Add facility to skip first "n" cells when printing labels (#6028)
This commit is contained in:
parent
c3acb1753e
commit
3c9e3d1252
@ -29,6 +29,13 @@ class LabelPrintingOptionsSerializer(serializers.Serializer):
|
|||||||
help_text=_('Page size for the label sheet')
|
help_text=_('Page size for the label sheet')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
skip = serializers.IntegerField(
|
||||||
|
default=0,
|
||||||
|
label=_('Skip Labels'),
|
||||||
|
help_text=_('Skip this number of labels when printing label sheets'),
|
||||||
|
min_value=0
|
||||||
|
)
|
||||||
|
|
||||||
border = serializers.BooleanField(
|
border = serializers.BooleanField(
|
||||||
default=False,
|
default=False,
|
||||||
label=_('Border'),
|
label=_('Border'),
|
||||||
@ -70,6 +77,7 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
|||||||
page_size_code = printing_options.get('page_size', 'A4')
|
page_size_code = printing_options.get('page_size', 'A4')
|
||||||
landscape = printing_options.get('landscape', False)
|
landscape = printing_options.get('landscape', False)
|
||||||
border = printing_options.get('border', False)
|
border = printing_options.get('border', False)
|
||||||
|
skip = int(printing_options.get('skip', 0))
|
||||||
|
|
||||||
# Extract size of page
|
# Extract size of page
|
||||||
page_size = report.helpers.page_size(page_size_code)
|
page_size = report.helpers.page_size(page_size_code)
|
||||||
@ -90,6 +98,7 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
|||||||
|
|
||||||
# Data to pass through to each page
|
# Data to pass through to each page
|
||||||
document_data = {
|
document_data = {
|
||||||
|
"skip": skip,
|
||||||
"border": border,
|
"border": border,
|
||||||
"landscape": landscape,
|
"landscape": landscape,
|
||||||
"page_width": page_width,
|
"page_width": page_width,
|
||||||
@ -107,6 +116,9 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
|||||||
idx = 0
|
idx = 0
|
||||||
|
|
||||||
while idx < n_labels:
|
while idx < n_labels:
|
||||||
|
|
||||||
|
document_data['label_idx'] = idx
|
||||||
|
|
||||||
if page := self.print_page(label, items[idx:idx + n_cells], request, **document_data):
|
if page := self.print_page(label, items[idx:idx + n_cells], request, **document_data):
|
||||||
pages.append(page)
|
pages.append(page)
|
||||||
|
|
||||||
@ -153,6 +165,9 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
|||||||
|
|
||||||
n_cols = kwargs['n_cols']
|
n_cols = kwargs['n_cols']
|
||||||
n_rows = kwargs['n_rows']
|
n_rows = kwargs['n_rows']
|
||||||
|
n_skip = kwargs['skip']
|
||||||
|
|
||||||
|
label_idx = kwargs['label_idx']
|
||||||
|
|
||||||
# Generate a table of labels
|
# Generate a table of labels
|
||||||
html = """<table class='label-sheet-table'>"""
|
html = """<table class='label-sheet-table'>"""
|
||||||
@ -166,6 +181,11 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
|||||||
# Cell index
|
# Cell index
|
||||||
idx = row * n_cols + col
|
idx = row * n_cols + col
|
||||||
|
|
||||||
|
# If we are within the skip range, do not render a label
|
||||||
|
if (idx + label_idx) < n_skip:
|
||||||
|
html += """<div class='label-sheet-cell-skip'></div>"""
|
||||||
|
continue
|
||||||
|
|
||||||
if idx < len(items):
|
if idx < len(items):
|
||||||
try:
|
try:
|
||||||
# Render the individual label template
|
# Render the individual label template
|
||||||
|
Loading…
x
Reference in New Issue
Block a user