feat: designer treatment as an optional paid line (front 5)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 4m20s
Build and deploy / Publish images (push) Successful in 1m5s
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 4m20s
Build and deploy / Publish images (push) Successful in 1m5s
TREATMENT_CENTS sets a fixed price per order; 0 keeps the option hidden. The cart shows the designer treatment and adds 24 h; the quote total and Tiny line carry it, and the card gets the "Tratamento pago" label. The designer uploads the treated file through the existing card flow.
This commit is contained in:
@@ -9,7 +9,7 @@ from ..core import db
|
||||
from .. import mail
|
||||
from ..core.auth import client_ip, owner, new_session, rate_limit
|
||||
from ..core.limits import upload_limit_bytes
|
||||
from ..core.pricing import manual_extra_cents
|
||||
from ..core.pricing import manual_extra_cents, treatment_cents
|
||||
from ..core.models import FreightAsk, FreightEstimate
|
||||
from ..runtime import (ENVIRONMENT, GUEST_SESSION_LIMIT, PART_BYTES, delivery_services, freight, payment,
|
||||
require_delivery_available, storage)
|
||||
@@ -43,6 +43,7 @@ def session(request: Request, response: Response):
|
||||
'password_recovery': mail.configured(),
|
||||
# Per metre on a finished sheet someone opens by hand (app/core/pricing.py).
|
||||
'manual_extra_cents': manual_extra_cents(),
|
||||
'treatment_cents': treatment_cents(),
|
||||
# Public by design: Mercado Pago's card form needs it in the browser.
|
||||
'payment_public_key': os.environ.get('MP_PUBLIC_KEY', '') if payment.name == 'mercadopago' else '',
|
||||
# The delivery options the cart quotes, or none: pickup only.
|
||||
|
||||
@@ -264,6 +264,8 @@ class QuoteRequest(StrictModel):
|
||||
destination: Destination | None = None
|
||||
# "Quero aprovar uma prova antes de imprimir": the order waits for the customer.
|
||||
proof: bool = False
|
||||
# "Quero o tratamento pelo designer": a fixed service line, when priced (front 5).
|
||||
treatment: bool = False
|
||||
# What the browser measured while the customer built the cart (item 0.12).
|
||||
timings: ClientTimings | None = None
|
||||
|
||||
|
||||
@@ -24,6 +24,18 @@ def manual_extra_cents() -> int:
|
||||
return value
|
||||
|
||||
|
||||
def treatment_cents() -> int:
|
||||
"""The designer's treatment, a fixed amount per order (front 5).
|
||||
|
||||
Zero keeps the option hidden: the price is the client's decision, and the
|
||||
server and the Site read the same `TREATMENT_CENTS`.
|
||||
"""
|
||||
value = int(os.environ.get('TREATMENT_CENTS', '0') or 0)
|
||||
if not 0 <= value <= 1000000:
|
||||
raise ValueError('TREATMENT_CENTS must be between 0 and 1000000')
|
||||
return value
|
||||
|
||||
|
||||
def is_manual(item, names) -> bool:
|
||||
"""Whether a finished-sheet item has a file someone must open by hand: one
|
||||
the customer measured, or one in a format the Site cannot read."""
|
||||
|
||||
@@ -22,7 +22,7 @@ from psycopg.types.json import Jsonb
|
||||
from . import payments
|
||||
from .proof import PROOF_ABOVE_METRES
|
||||
from .core.models import PRODUCTION_VERSIONS
|
||||
from .core.pricing import bill_splits, is_manual, manual_extra_cents, price
|
||||
from .core.pricing import bill_splits, is_manual, manual_extra_cents, price, treatment_cents
|
||||
from .runtime import freight, upload_row
|
||||
from .scanning import require_clean
|
||||
|
||||
@@ -96,13 +96,16 @@ def approve(c, row, items, reviewer):
|
||||
metres, sum(i['total_cents'] for i in priced))
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc))
|
||||
treatment = treatment_cents() if draft.get('treatment') else 0
|
||||
approved = {'customer': draft['customer'], 'items': priced, 'freight': quoted_freight,
|
||||
'destination': draft.get('destination'),
|
||||
# The customer's proof only above 10 m (Dropstar, 2026-10-28).
|
||||
**({'proof': True} if draft.get('proof') and metres > PROOF_ABOVE_METRES else {}),
|
||||
# Designer treatment is one fixed service line (front 5).
|
||||
**({'treatment': {'cents': treatment, 'hours': 24}} if treatment else {}),
|
||||
# Browser timings are kept for Números, never for the price (0.12).
|
||||
**({'timings': draft['timings']} if draft.get('timings') else {}),
|
||||
'total_cents': sum(i['total_cents'] for i in priced) + quoted_freight['total_cents']}
|
||||
'total_cents': sum(i['total_cents'] for i in priced) + quoted_freight['total_cents'] + treatment}
|
||||
c.execute('UPDATE dtf_local.quotes SET approved=%s, reviewed_by=%s, approved_at=now() WHERE id=%s',
|
||||
(Jsonb(approved), reviewer, row['id']))
|
||||
# Approved and payable now: the files wait for the payment, not for ever.
|
||||
|
||||
@@ -33,6 +33,7 @@ if os.environ.get('FREIGHT_ADAPTER') == 'jadlog':
|
||||
_carriers.append(JadlogFreight())
|
||||
from . import correios as _correios
|
||||
from . import prumo
|
||||
from .core.pricing import treatment_cents
|
||||
if _correios.configured():
|
||||
_carriers.append(_correios.CorreiosFreight())
|
||||
freight = FreightOptions(_carriers or [FakeFreight()])
|
||||
@@ -134,9 +135,12 @@ def quote_view(c, row, order=None, attempt=None, known=False):
|
||||
attempt = {**attempt, 'message': rejection(attempt['status_detail'])}
|
||||
expired = row['approved_at'] and row['approved_at'] < datetime.now(timezone.utc)-timedelta(hours=24)
|
||||
items = (row['approved'] or row['draft']).get('items') or []
|
||||
treatment = (row['approved'] or {}).get('treatment')
|
||||
if not treatment and (row['draft'] or {}).get('treatment') and treatment_cents():
|
||||
treatment = {'cents': treatment_cents(), 'hours': 24}
|
||||
return {'id': row['id'], 'created_at': row['created_at'],
|
||||
'draft': row['draft'], 'approved': row['approved'],
|
||||
'prumo': prumo.customer_summary(items),
|
||||
'prumo': prumo.customer_summary(items), 'treatment': treatment,
|
||||
'status': 'paid' if order else 'discarded' if row.get('discarded_at') else 'expired' if expired
|
||||
else 'approved' if row['approved'] else 'pending_review',
|
||||
'auto_approved': row.get('reviewed_by') == 'auto',
|
||||
|
||||
11
app/tiny.py
11
app/tiny.py
@@ -489,6 +489,14 @@ def order_payload(payload, contact_id, today=None, product_id=None, shipping=Non
|
||||
'quantidade': float(Decimal(item['billed_metres'])),
|
||||
'valorUnitario': money(item['unit_cents']),
|
||||
'infoAdicional': note})
|
||||
treatment = order.get('treatment') or {}
|
||||
if treatment.get('cents'):
|
||||
setting = os.environ.get('TINY_PRODUCT_TREATMENT', '')
|
||||
if not setting.isdigit():
|
||||
raise TinyError('TINY_PRODUCT_TREATMENT must be the Tiny product id')
|
||||
items.append({'produto': {'id': int(setting)}, 'quantidade': 1,
|
||||
'valorUnitario': money(treatment['cents']),
|
||||
'infoAdicional': 'Tratamento da arte pelo designer · +24 h'})
|
||||
freight = order['freight']
|
||||
service = freight.get('service')
|
||||
pickup = service == 'pickup'
|
||||
@@ -506,7 +514,8 @@ def order_payload(payload, contact_id, today=None, product_id=None, shipping=Non
|
||||
# The carrier's time already counts production; a pickup is ready after it.
|
||||
days = freight.get('days') if not pickup else int(os.environ.get('FREIGHT_PRODUCTION_DAYS') or 0)
|
||||
if days is not None:
|
||||
pedido['dataPrevista'] = business_days_after(day, int(days)).isoformat()
|
||||
days = int(days) + (1 if treatment.get('cents') else 0)
|
||||
pedido['dataPrevista'] = business_days_after(day, days).isoformat()
|
||||
# Paid at once, in full, as the store's orders: one parcel on the day.
|
||||
pedido['pagamento'] = {'categoria': {'id': CATEGORIES.get(payload.get('origin'), CATEGORY)}}
|
||||
received = RECEIPT_METHODS.get((payload.get('payment') or {}).get('method'))
|
||||
|
||||
Reference in New Issue
Block a user