diff --git a/slips/models.py b/slips/models.py index 41f5cf3..68e85c5 100644 --- a/slips/models.py +++ b/slips/models.py @@ -64,6 +64,8 @@ class Order(models.Model): def save(self, *args, **kwargs): if not self.canister_count and self.total_weight and self.canister_weight: self.apply_weight() - self.canister_pages = math.ceil(self.canister_count / 4) if self.canister_count else 0 - self.box_pages = math.ceil(self.box_count / 4) if self.box_count else 0 + # Mixed sheets: canister + box labels share pages; total in canister_pages + n = self.canister_count + self.box_count + self.canister_pages = math.ceil(n / 4) if n else 0 + self.box_pages = 0 super().save(*args, **kwargs) diff --git a/slips/print_layout.py b/slips/print_layout.py index fdc3fdb..d5d7532 100644 --- a/slips/print_layout.py +++ b/slips/print_layout.py @@ -18,16 +18,9 @@ def _pad_to_four(weights): def build_print_pages(order): - pages = [] + """Mix box then canister labels on shared sheets (pad only last page).""" cw = _display_weight(order.canister_weight) - - # Canister labels (uniform weight) canister_weights = [cw] * order.canister_count - for i in range(0, len(canister_weights), 4): - pages.append({ - 'type': 'Canister', - 'slips': _pad_to_four(canister_weights[i:i + 4]), - }) # Box labels — last box may be a partial fill cans_left = order.canister_count @@ -37,12 +30,12 @@ def build_print_pages(order): box_weights.append(_display_weight(order.canister_weight * cans_in_box)) cans_left -= cans_in_box - for i in range(0, len(box_weights), 4): + weights = box_weights + canister_weights + pages = [] + for i in range(0, len(weights), 4): pages.append({ - 'type': 'Box', - 'slips': _pad_to_four(box_weights[i:i + 4]), + 'slips': _pad_to_four(weights[i:i + 4]), }) - return pages @@ -55,11 +48,21 @@ if __name__ == '__main__': box_count = 3 pages = build_print_pages(O()) - assert len(pages) == 4 # 3 canister pages + 1 box page + assert len(pages) == 4 # 13 labels → 4 mixed pages assert all(len(p['slips']) == 4 for p in pages) - assert pages[0]['slips'] == [5, 5, 5, 5] + assert pages[0]['slips'] == [20, 20, 10, 5] # boxes first, then cans assert all(isinstance(w, int) for w in pages[0]['slips']) - assert pages[2]['slips'] == [5, 5, 5, 5] # last canister page padded - assert pages[3]['type'] == 'Box' - assert pages[3]['slips'] == [20, 20, 10, 20] # partial last box; pad from first + assert pages[1]['slips'] == [5, 5, 5, 5] + assert pages[2]['slips'] == [5, 5, 5, 5] + assert pages[3]['slips'] == [5, 5, 5, 5] # last page full + # 3 cans + 1 box → one mixed page + class Small: + canister_count = 3 + canister_weight = 5.0 + canisters_per_box = 4 + box_count = 1 + + one = build_print_pages(Small()) + assert len(one) == 1 + assert one[0]['slips'] == [15, 5, 5, 5] print('ok') diff --git a/slips/static/slips/js/entry.js b/slips/static/slips/js/entry.js index 85293c7..2a15b3c 100644 --- a/slips/static/slips/js/entry.js +++ b/slips/static/slips/js/entry.js @@ -46,14 +46,12 @@ document.addEventListener('DOMContentLoaded', () => { const cpb = parseInt(canistersPerBoxInput.value) || 1; const cc = Math.ceil(tw / cw); - const cp = Math.ceil(cc / 4); - const bc = Math.ceil(cc / cpb); - const bp = Math.ceil(bc / 4); + const pages = Math.ceil((cc + bc) / 4) || 0; const t = translations[currentLang] || translations.en; previewDisplay.textContent = - `${t.canisters_unit}: ${cc} (${cp} ${t.preview_pages}) | ${t.boxes_unit}: ${bc} (${bp} ${t.preview_pages})`; + `${t.canisters_unit}: ${cc} | ${t.boxes_unit}: ${bc} | ${pages} ${t.preview_pages}`; } window.updateLabelsPreview = updatePreview; diff --git a/slips/templates/slips/entry.html b/slips/templates/slips/entry.html index 6432214..0db9ce6 100644 --- a/slips/templates/slips/entry.html +++ b/slips/templates/slips/entry.html @@ -59,7 +59,7 @@
Order #{{ order.id }} — {{ order.product.code }}
- {{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) |
- {{ order.box_count }} Boxes ({{ order.box_pages }} Pages)
+ {{ order.canister_count }} Canisters |
+ {{ order.box_count }} Boxes |
+ {{ order.canister_pages|add:order.box_pages }} Pages