Add custom labels printed before box and canister slips
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -36,11 +36,20 @@ def _box_weight_template(order):
|
||||
return template
|
||||
|
||||
|
||||
def build_print_pages(order):
|
||||
"""Mix box then canister labels on shared sheets (pad only last page).
|
||||
def _custom_weights(order):
|
||||
"""User-defined slips. Counts repeat the stored weight; they are not derived."""
|
||||
weights = []
|
||||
for line in getattr(order, 'custom_labels', None) or []:
|
||||
weights.extend([_display_weight(line['weight'])] * int(line['count']))
|
||||
return weights
|
||||
|
||||
canister_count / box_count are print quantities only; slip weights come from
|
||||
total_weight packaging so reprint steppers do not change label content.
|
||||
|
||||
def build_print_pages(order):
|
||||
"""Custom labels, then boxes, then canisters, on shared sheets (pad only last page).
|
||||
|
||||
Counts are print quantities. Box and canister weights come from total_weight
|
||||
packaging, so those steppers do not change label content. Custom weights are
|
||||
the ones stored on the order.
|
||||
"""
|
||||
cw = _display_weight(order.canister_weight)
|
||||
canister_weights = [cw] * order.canister_count
|
||||
@@ -51,7 +60,7 @@ def build_print_pages(order):
|
||||
else:
|
||||
box_weights = [template[i % len(template)] for i in range(order.box_count)]
|
||||
|
||||
weights = box_weights + canister_weights
|
||||
weights = _custom_weights(order) + box_weights + canister_weights
|
||||
pages = []
|
||||
for i in range(0, len(weights), 4):
|
||||
pages.append({
|
||||
@@ -68,6 +77,7 @@ if __name__ == '__main__':
|
||||
canister_weight = 5.0
|
||||
canisters_per_box = 4
|
||||
box_count = 3
|
||||
custom_labels = []
|
||||
|
||||
pages = build_print_pages(O())
|
||||
assert len(pages) == 4 # 13 labels → 4 mixed pages
|
||||
@@ -97,4 +107,14 @@ if __name__ == '__main__':
|
||||
one = build_print_pages(Small())
|
||||
assert len(one) == 1
|
||||
assert one[0]['slips'] == [15, 5, 5, 5]
|
||||
|
||||
# Custom slips print first; box and canister weights stay on the packaging recipe
|
||||
class WithCustom(O):
|
||||
custom_labels = [{'weight': 8.0, 'count': 1}, {'weight': 1.5, 'count': 1}]
|
||||
|
||||
mixed = build_print_pages(WithCustom())
|
||||
assert mixed[0]['slips'] == [8, 1.5, 20, 20]
|
||||
assert isinstance(mixed[0]['slips'][0], int)
|
||||
assert mixed[1]['slips'] == [10, 5, 5, 5]
|
||||
assert len(mixed) == 4 # 2 custom + 3 boxes + 10 cans = 15 → 4 pages
|
||||
print('ok')
|
||||
|
||||
Reference in New Issue
Block a user