diff --git a/InvenTree/plugin/builtin/labels/label_sheet.py b/InvenTree/plugin/builtin/labels/label_sheet.py index 2d19ab4514..4a48edbe25 100644 --- a/InvenTree/plugin/builtin/labels/label_sheet.py +++ b/InvenTree/plugin/builtin/labels/label_sheet.py @@ -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 = """""" @@ -176,17 +173,19 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug html += "" for col in range(n_cols): - html += f"
" # 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 += """
""" - continue + if idx >= len(items): + break - if idx < len(items): + html += f"
" + + # If the label is empty (skipped), render an empty cell + if items[idx] is None: + html += """
""" + else: try: # Render the individual label template # Note that we disable @page styling for this