feat: Ajuste Fino priced per art, with the offer under each Prumo warning (Marcus 10/11, point 1)
The designer treatment becomes Ajuste Fino, priced per art with a batch band set in the Site tab (e.g. R$ 9,90, from 10 arts R$ 6,90). Under each art the Prumo warns about, the Site offers 'Quer que um designer resolva? Ajuste Fino'; the cart keeps 'Ajuste Fino em todas as artes'. The server counts the chosen arts, Tiny gets the line with that quantity, the card shows 'Ajuste Fino · N artes'. Old carts asking the treatment for the whole order keep working. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,13 +7,14 @@ app/core/pricing.py stays as the seed and the fallback for the five modes;
|
||||
changed or deleted once its start date has passed (the table is the history),
|
||||
and an approved quote keeps the price it was approved with.
|
||||
|
||||
`tratamento` is the designer's treatment (front 5), a fixed amount per order:
|
||||
it counts as offered only when it is switched on and priced above zero.
|
||||
`tratamento` is Ajuste Fino (front 1a): a price per art, with an optional band
|
||||
by the order's number of arts (front 8.2). It counts as offered only when it is
|
||||
switched on and priced above zero.
|
||||
|
||||
A price row may carry bands by the order's total metres of that product (front
|
||||
8.2): below the first band the base price, then the highest band reached wins
|
||||
and the whole quantity is charged at that one price. The bands travel with the
|
||||
row, so they start and become history with it.
|
||||
A price row may carry bands by the order's quantity of that product (metres, or
|
||||
arts for Ajuste Fino): below the first band the base price, then the highest
|
||||
band reached wins and the whole quantity is charged at that one price. The
|
||||
bands travel with the row, so they start and become history with it.
|
||||
"""
|
||||
from decimal import Decimal
|
||||
|
||||
@@ -29,10 +30,10 @@ TITLES = {
|
||||
'uvfile': 'UV folha pronta',
|
||||
'uv': 'UV artes avulsas',
|
||||
'premium': 'Têxtil Premium · 8 passadas',
|
||||
'tratamento': 'Tratamento pelo designer',
|
||||
'tratamento': 'Ajuste Fino',
|
||||
}
|
||||
UNITS = {'file': 'metro', 'avulsa': 'metro', 'uvfile': 'metro', 'uv': 'metro',
|
||||
'premium': 'metro', 'tratamento': 'pedido'}
|
||||
'premium': 'metro', 'tratamento': 'arte'}
|
||||
|
||||
|
||||
def fallback_cents(product: str) -> int:
|
||||
@@ -40,15 +41,16 @@ def fallback_cents(product: str) -> int:
|
||||
return pricing.treatment_cents() if product == 'tratamento' else pricing.PRICES[product]
|
||||
|
||||
|
||||
def band_price(base_cents: int, bands: list, metres: Decimal) -> int:
|
||||
"""The per-metre price for this quantity: the base, or the highest band
|
||||
reached. The whole quantity is charged at one price, not in steps."""
|
||||
metres = Decimal(str(metres))
|
||||
def band_price(base_cents: int, bands: list, quantity: Decimal) -> int:
|
||||
"""The unit price for this quantity: the base, or the highest band reached.
|
||||
The quantity is metres for a product and arts for Ajuste Fino; the whole
|
||||
quantity is charged at one price, not in steps."""
|
||||
quantity = Decimal(str(quantity))
|
||||
price = base_cents
|
||||
best = None
|
||||
for band in bands or []:
|
||||
start = Decimal(str(band['from_metres']))
|
||||
if metres >= start and (best is None or start >= best):
|
||||
if quantity >= start and (best is None or start >= best):
|
||||
best = start
|
||||
price = band['unit_cents']
|
||||
return price
|
||||
@@ -77,14 +79,14 @@ def unit_cents(c, product: str) -> int:
|
||||
return row['unit_cents'] if row else fallback_cents(product)
|
||||
|
||||
|
||||
def unit_cents_for(c, product: str, metres: Decimal) -> int:
|
||||
def unit_cents_for(c, product: str, quantity: Decimal) -> int:
|
||||
"""The current price of one product for this quantity, bands included."""
|
||||
row = c.execute('''SELECT unit_cents, bands FROM dtf_local.product_prices
|
||||
WHERE product=%s AND starts_at <= now()
|
||||
ORDER BY starts_at DESC, id DESC LIMIT 1''', (product,)).fetchone()
|
||||
if not row:
|
||||
return fallback_cents(product)
|
||||
return band_price(row['unit_cents'], row['bands'], metres)
|
||||
return band_price(row['unit_cents'], row['bands'], quantity)
|
||||
|
||||
|
||||
def treatment_offered(c) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user