mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Bug fix for label-skip implementation (#6030)
- Previous implementation skipped the first n labels - We want to skip cells, but print all labels - New implementation is also cleaner
This commit is contained in:
parent
3c9e3d1252
commit
f034d86c3f
@ -94,11 +94,13 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
||||
if n_cells == 0:
|
||||
raise ValidationError(_("Label is too large for page size"))
|
||||
|
||||
# Prepend the required number of skipped null labels
|
||||
items = [None] * skip + list(items)
|
||||
|
||||
n_labels = len(items)
|
||||
|
||||
# Data to pass through to each page
|
||||
document_data = {
|
||||
"skip": skip,
|
||||
"border": border,
|
||||
"landscape": landscape,
|
||||
"page_width": page_width,
|
||||
@ -117,8 +119,6 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
||||
|
||||
while idx < n_labels:
|
||||
|
||||
document_data['label_idx'] = idx
|
||||
|
||||
if page := self.print_page(label, items[idx:idx + n_cells], request, **document_data):
|
||||
pages.append(page)
|
||||
|
||||
@ -165,9 +165,6 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
||||
|
||||
n_cols = kwargs['n_cols']
|
||||
n_rows = kwargs['n_rows']
|
||||
n_skip = kwargs['skip']
|
||||
|
||||
label_idx = kwargs['label_idx']
|
||||
|
||||
# Generate a table of labels
|
||||
html = """<table class='label-sheet-table'>"""
|
||||
@ -176,17 +173,19 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
||||
html += "<tr class='label-sheet-row'>"
|
||||
|
||||
for col in range(n_cols):
|
||||
html += f"<td class='label-sheet-cell label-sheet-row-{row} label-sheet-col-{col}'>"
|
||||
|
||||
# Cell index
|
||||
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):
|
||||
break
|
||||
|
||||
if idx < len(items):
|
||||
html += f"<td class='label-sheet-cell label-sheet-row-{row} label-sheet-col-{col}'>"
|
||||
|
||||
# If the label is empty (skipped), render an empty cell
|
||||
if items[idx] is None:
|
||||
html += """<div class='label-sheet-cell-skip'></div>"""
|
||||
else:
|
||||
try:
|
||||
# Render the individual label template
|
||||
# Note that we disable @page styling for this
|
||||
|
Loading…
Reference in New Issue
Block a user