Files
product-slip/slips/print_layout.py
Diaco Soltanpour d7f1929674 Label print calibration and Lithium Label UI polish (#3)
## Summary
- Calibrate label print/calibrate CSS to the reference PDF (positions, ~7pt/6pt sizes, bottom-row pitch)
- Print layout: partial last-box weight, pad short pages to 4 slips, whole-number weights
- Rename to Lithium Label Manager; Vazirmatn for FA / Inter for EN; inverted lithium icon; seed weights=5; number step=1; hide empty toast

## Test plan
- [ ] Print calibration sheet and overlay on a physical label — top and bottom rows align
- [ ] Order 50/5/4 — box labels show 20, 20, 10 (padded page); weights without `.0`
- [ ] Language toggle switches Inter ↔ Vazirmatn
- [ ] Seed products use canister weight 5; form spinners step by 1

Reviewed-on: #3
Co-authored-by: Diaco Soltanpour <dyaco8464@yahoo.com>
Co-committed-by: Diaco Soltanpour <dyaco8464@yahoo.com>
2026-10-01 18:10:44 +00:00

66 lines
2.0 KiB
Python

"""Build print pages: per-slip weights, always 4 slips per page."""
def _display_weight(w):
"""Whole numbers as int (5 not 5.0) for print labels."""
f = float(w)
return int(f) if f.is_integer() else f
def _pad_to_four(weights):
"""Pad short page by repeating the first slip on that page."""
if not weights:
return weights
first = weights[0]
while len(weights) < 4:
weights.append(first)
return weights
def build_print_pages(order):
pages = []
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
box_weights = []
for _ in range(order.box_count):
cans_in_box = min(order.canisters_per_box, cans_left)
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):
pages.append({
'type': 'Box',
'slips': _pad_to_four(box_weights[i:i + 4]),
})
return pages
# ponytail: assert-based check; upgrade to pytest if suite grows
if __name__ == '__main__':
class O:
canister_count = 10
canister_weight = 5.0
canisters_per_box = 4
box_count = 3
pages = build_print_pages(O())
assert len(pages) == 4 # 3 canister pages + 1 box page
assert all(len(p['slips']) == 4 for p in pages)
assert pages[0]['slips'] == [5, 5, 5, 5]
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
print('ok')