feat: products and prices from the database, edited in the Kanban's Site tab (front 8.1)
Gestão and the administrators switch each product on and off and set its price from a start date; a price that has started is history and cannot change, a scheduled one can be cancelled. The Site and the server read the current price; with no row the code's prices and TREATMENT_CENTS still apply, so nothing changes until someone sets one. A switched-off product disappears from the Site and new quotes with it are refused. Approved quotes and paid orders keep their price. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import re
|
||||
from datetime import date
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
from typing import Literal
|
||||
from uuid import UUID
|
||||
@@ -352,6 +352,17 @@ class MachineSheet(StrictModel):
|
||||
minimums: dict[str, Decimal | None] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class SiteProductToggle(StrictModel):
|
||||
"""Ligar ou desligar um produto na aba Site (Fase 2, front 8)."""
|
||||
enabled: bool
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
class Contraction(StrictModel):
|
||||
item_index: int = Field(ge=0, le=100)
|
||||
# None returns the item to the class the browser measured.
|
||||
|
||||
@@ -44,10 +44,12 @@ def is_manual(item, names) -> bool:
|
||||
for source in item['production']['sources'])
|
||||
|
||||
|
||||
def price(mode: str, metres: str, grade: int, extra_cents: int = 0, minimum: Decimal = Decimal('1')) -> dict:
|
||||
def price(mode: str, metres: str, grade: int, extra_cents: int = 0, minimum: Decimal = Decimal('1'),
|
||||
unit_cents: int | None = None) -> dict:
|
||||
"""The item's charge. The grade is validated and kept with the item; the
|
||||
price does not depend on it. A split sheet has no minimum of its own: its
|
||||
group has one (bill_splits)."""
|
||||
group has one (bill_splits). `unit_cents` is the current price from the
|
||||
database (app/catalog.py); without it, the table above."""
|
||||
length = Decimal(str(metres))
|
||||
if mode not in PRICES or not length.is_finite() or not 0 < length <= 12000:
|
||||
raise ValueError('Invalid product or length')
|
||||
@@ -56,7 +58,7 @@ def price(mode: str, metres: str, grade: int, extra_cents: int = 0, minimum: Dec
|
||||
billed = max(minimum, (length * 10).to_integral_value(rounding=ROUND_CEILING) / 10)
|
||||
if isinstance(extra_cents, bool) or not isinstance(extra_cents, int) or extra_cents < 0:
|
||||
raise ValueError('Invalid extra charge')
|
||||
unit = PRICES[mode] + extra_cents
|
||||
unit = (PRICES[mode] if unit_cents is None else unit_cents) + extra_cents
|
||||
priced = {'mode': mode, 'metres': str(length), 'grade': grade,
|
||||
'billed_metres': str(billed), 'unit_cents': unit,
|
||||
'total_cents': int(billed * unit)}
|
||||
|
||||
Reference in New Issue
Block a user