Mix box and canister labels on shared sheets

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-11 12:53:57 +03:30
parent 7b9255d31c
commit 08b234c254
5 changed files with 30 additions and 26 deletions

View File

@@ -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')