feat: progressive price bands per product (front 8.2)

A price may carry up to five bands, "from N m, R$ Y": the order's total
billed metres of that product chooses one price for its whole quantity,
the manual-file extra still on top. Bands start and become history with
their price row. The Site charges the same band for the cart, shows
"Faltam X m para R$ Y o metro" and lists the bands under the price
table; the Kanban's Site tab edits them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-09 14:30:15 -03:00
parent c5e7a80b64
commit 2a6732eb37
16 changed files with 334 additions and 23 deletions

View File

@@ -357,10 +357,18 @@ class SiteProductToggle(StrictModel):
enabled: bool
class PriceBand(StrictModel):
"""Uma faixa por metragem: a partir de X m, o metro passa a custar Y."""
from_metres: Decimal
unit_cents: int = Field(strict=True)
class SitePriceNew(StrictModel):
"""Um novo preço e a data em que começa; sem data, começa agora."""
unit_cents: int = Field(ge=0, le=10000000, strict=True)
starts_at: datetime | None = None
# As faixas viajam com o preço (front 8.2); vazio é o preço único.
bands: list[PriceBand] = Field(default_factory=list)
class Contraction(StrictModel):

View File

@@ -80,6 +80,18 @@ def bill_splits(priced: list) -> list:
return priced
def apply_bands(priced: list, unit_by_mode: dict) -> list:
"""Rewrite the items of each mode to the band price for the order's total
metres of that product (front 8.2). The manual-file extra stays on top of
each item; a mode absent from `unit_by_mode` is untouched."""
for item in priced:
if item['mode'] in unit_by_mode:
unit = unit_by_mode[item['mode']] + item.get('manual_extra_cents', 0)
item['unit_cents'] = unit
item['total_cents'] = int(Decimal(str(item['billed_metres'])) * unit)
return priced
def sheet_label(item: dict) -> str:
"""' · folha 1 de 2' on a split sheet (item 17), for the customer's lists."""
split = item.get('split')