feat: each product's metres are summed and rounded once, and the 1 m minimum is once per order (Marcus, 2026-12-03)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 8m24s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m14s
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 8m24s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m14s
Marcus: "o pedido mínimo de um metro deve ser somente para o primeiro metro, após isso deve se somar a metragem de cada arquivo", "Soma tudo e arredonda uma vez só", and for different products "Pode ser sim": each product apart at its price, the minimum for the whole order. Order #246 (three ready sheets of 3,74, 0,24 and 0,22 m) was 5,80 m with 1 m per item; it is now 4,20 m. pricing.bill_order replaces the per-item minimum and bill_splits: per product the exact lengths (a ready sheet without its gaps) are rounded once with the 8 mm grace, the minimum's difference goes to the first item's product, and each product's total is shared back to its items in 10 cm steps (each its length rounded down, the missing steps to the largest fractions, the minimum to the product's first item), for Tiny's 10 cm SKUs and the cards. A share of 0 m adds no Tiny line. The print file's guard allows an item one 10 cm step under its length. The Site cart shares the same way (cobrarPedido), split sheets round once, the buy box says the items of a product are summed and rounded once, and the Montador's estimate rounds its sum once. Contract: output/revisao/contrato-minimo-pedido.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -76,18 +76,21 @@ def price_items(items, names, catalog_now, manual_extra):
|
||||
"""Price the items without a database: price() per item with the product's
|
||||
base price and the manual extra, bill_splits, then the band of each mode's
|
||||
total, then apply_bands. Exactly as an order is charged."""
|
||||
priced = []
|
||||
priced, lengths = [], []
|
||||
for item in items:
|
||||
extra = manual_extra if pricing.is_manual(item, names) else 0
|
||||
product = catalog_now[item['mode']]
|
||||
# Billed on the length less a ready sheet's gaps; `metres` stays the
|
||||
# film the layout uses, which the print file and the folders follow.
|
||||
charged = pricing.price(item['mode'], str(pricing.billable_metres(item)), item['grade'], extra,
|
||||
minimum=Decimal('0') if item.get('split') else Decimal('1'),
|
||||
unit_cents=product['unit_cents'])
|
||||
length = pricing.billable_metres(item)
|
||||
charged = pricing.price(item['mode'], str(length), item['grade'], extra,
|
||||
minimum=Decimal('0'), unit_cents=product['unit_cents'])
|
||||
priced.append({**charged, 'metres': str(item['metres']),
|
||||
**({'split': item['split']} if item.get('split') else {})})
|
||||
pricing.bill_splits(priced)
|
||||
lengths.append(length)
|
||||
# One rounding per product and the 1 m minimum once for the order (Marcus,
|
||||
# 2026-12-03); it also covers the split sheets of item 17.
|
||||
pricing.bill_order(priced, lengths)
|
||||
totals = {}
|
||||
for item in priced:
|
||||
totals[item['mode']] = totals.get(item['mode'], Decimal('0')) + Decimal(item['billed_metres'])
|
||||
|
||||
@@ -105,6 +105,36 @@ def price(mode: str, metres: str, grade: int, extra_cents: int = 0, minimum: Dec
|
||||
return priced
|
||||
|
||||
|
||||
def bill_order(priced: list, lengths: list) -> list:
|
||||
"""The order's metres (Marcus, 2026-12-03): each product's exact lengths
|
||||
summed and rounded once (billed_length), the 1 m minimum once for the
|
||||
order, on the first item's product. Each product's total is then shared
|
||||
back to its items in 10 cm steps, for Tiny's SKUs and the cards: every
|
||||
item its length rounded down, the missing steps to the largest fractions
|
||||
(ties to the first item), the minimum's difference to the product's first
|
||||
item (output/revisao/contrato-minimo-pedido.md)."""
|
||||
if not priced:
|
||||
return priced
|
||||
steps = [Decimal(str(length)) * 10 for length in lengths]
|
||||
modes = list(dict.fromkeys(item['mode'] for item in priced))
|
||||
totals = {mode: billed_length(sum(Decimal(str(lengths[k])) for k, item in enumerate(priced)
|
||||
if item['mode'] == mode)) for mode in modes}
|
||||
short = Decimal('1') - sum(totals.values())
|
||||
for mode in modes:
|
||||
indexes = [k for k, item in enumerate(priced) if item['mode'] == mode]
|
||||
shares = {k: int(steps[k].to_integral_value(rounding='ROUND_FLOOR')) for k in indexes}
|
||||
missing = int(totals[mode] * 10) - sum(shares.values())
|
||||
by_fraction = sorted(indexes, key=lambda k: (-(steps[k] - shares[k]), k))
|
||||
for k in by_fraction[:missing]:
|
||||
shares[k] += 1
|
||||
if mode == priced[0]['mode'] and short > 0:
|
||||
shares[indexes[0]] += int(short * 10)
|
||||
for k in indexes:
|
||||
billed = Decimal(shares[k]) / 10
|
||||
priced[k].update(billed_metres=str(billed), total_cents=int(billed * priced[k]['unit_cents']))
|
||||
return priced
|
||||
|
||||
|
||||
def bill_splits(priced: list) -> list:
|
||||
"""The order minimum of 1 m once per split group, on its first sheet: the
|
||||
customer did not choose the split (item 17), so it never costs a metre more."""
|
||||
|
||||
@@ -29,6 +29,9 @@ from PIL import Image, ImageOps
|
||||
from .core.models import PRODUCTION_VERSIONS
|
||||
from .core.pricing import STEP_GRACE_M, unbilled_gaps_cm
|
||||
|
||||
# One 10 cm step: the most an item's share of its product's total falls short.
|
||||
SHARE_STEP_CM = Decimal('10')
|
||||
|
||||
PT_PER_CM = 72 / 2.54
|
||||
# Acrobat's page limit, 200 inches (5,08 m). A longer sheet is written at its
|
||||
# real size, on one page: CorelDRAW, where Dropstar checks the files, ignores
|
||||
@@ -388,9 +391,12 @@ def check_layout(item, sizes, vector=(), proof=False):
|
||||
production = item['production']
|
||||
height = Decimal(str(production['height_cm']))
|
||||
billed = Decimal(str(item['billed_metres'])) * 100
|
||||
# Up to 8 mm past the billed length is the customer's grace, and a ready
|
||||
# sheet's gaps are film not billed (app/core/pricing.py).
|
||||
allowed = billed + STEP_GRACE_M * 100 + unbilled_gaps_cm(production) + HEIGHT_TOLERANCE_CM
|
||||
# Up to 8 mm past the billed length is the customer's grace, a ready
|
||||
# sheet's gaps are film not billed, and since one rounding per product
|
||||
# (2026-12-03) an item's share is its length rounded down, short of it by
|
||||
# less than one 10 cm step (app/core/pricing.py bill_order).
|
||||
allowed = (billed + SHARE_STEP_CM + STEP_GRACE_M * 100 + unbilled_gaps_cm(production)
|
||||
+ HEIGHT_TOLERANCE_CM)
|
||||
if not proof and height > allowed:
|
||||
raise Unsupported(f'a montagem tem {height} cm, mas só {billed} cm foram cobrados')
|
||||
lowest = None
|
||||
|
||||
@@ -583,6 +583,10 @@ def order_payload(payload, contact_id, today=None, product_id=None, shipping=Non
|
||||
order = payload['order']
|
||||
items = []
|
||||
for item in order['items']:
|
||||
# A very short sheet can share 0 m of its product's total (one
|
||||
# rounding per product, 2026-12-03): it has no line of its own.
|
||||
if not Decimal(str(item['billed_metres'])):
|
||||
continue
|
||||
note = PRODUCTS[item['mode']] + f" · nota {item['grade']}"
|
||||
prefix, step = sku_prefix(item['mode']), step_sku(item['mode'])
|
||||
if step or prefix:
|
||||
|
||||
Reference in New Issue
Block a user