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:
|
if n_cells == 0:
|
||||||
raise ValidationError(_("Label is too large for page size"))
|
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)
|
n_labels = len(items)
|
||||||
|
|
||||||
# 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,
|
||||||
@ -117,8 +119,6 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
|||||||
|
|
||||||
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)
|
||||||
|
|
||||||
@ -165,9 +165,6 @@ 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'>"""
|
||||||
@ -176,17 +173,19 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
|||||||
html += "<tr class='label-sheet-row'>"
|
html += "<tr class='label-sheet-row'>"
|
||||||
|
|
||||||
for col in range(n_cols):
|
for col in range(n_cols):
|
||||||
html += f"<td class='label-sheet-cell label-sheet-row-{row} label-sheet-col-{col}'>"
|
|
||||||
|
|
||||||
# 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 >= len(items):
|
||||||
if (idx + label_idx) < n_skip:
|
break
|
||||||
html += """<div class='label-sheet-cell-skip'></div>"""
|
|
||||||
continue
|
|
||||||
|
|
||||||
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:
|
try:
|
||||||
# Render the individual label template
|
# Render the individual label template
|
||||||
# Note that we disable @page styling for this
|
# Note that we disable @page styling for this
|
||||||
|
Loading…
Reference in New Issue
Block a user