feat: every order is born with its origin, shown, filtered and counted (Dropstar's rules D-21 and D-35)
All checks were successful
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Successful in 3m21s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m1s
All checks were successful
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Successful in 3m21s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m1s
Orders carry site, dropflow or atendimento, required and with no default, limited to the three. The Site's orders are marked site where they are created; older orders became site. The Kanban shows the origin on each card and in the order panel, filters by it, and Numeros has a Por origem table: orders, metres, money and time from payment to Finalizado per way in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -795,6 +795,8 @@ def thumbnail(uid: UUID, user=Depends(operator)):
|
||||
|
||||
# Real work only: an operator's test order and a cancelled one are not production.
|
||||
REAL_ORDER = "o.cancelled_at IS NULL AND COALESCE(o.payment->>'provider','') <> 'teste'"
|
||||
# Where orders come from (D-21), in the order Números lists them.
|
||||
ORIGINS = ('site', 'dropflow', 'atendimento')
|
||||
LOCAL_DAY = "(o.created_at AT TIME ZONE 'America/Sao_Paulo')::date"
|
||||
|
||||
|
||||
@@ -881,6 +883,16 @@ def production_stats(days: int | None = Query(default=None, ge=7, le=365), start
|
||||
treated_orders = c.execute(f'''SELECT count(DISTINCT f.order_id) AS n FROM dtf_local.order_files f
|
||||
JOIN dtf_local.orders o ON o.id=f.order_id WHERE {REAL_ORDER} AND {within} AND {TREATED}''',
|
||||
period).fetchone()['n']
|
||||
# Each way in apart (D-21): what came from where, and how long it took
|
||||
# from payment to Finalizado, Aguardando contato left out as above.
|
||||
origins = {row['origin']: row for row in c.execute(f'''SELECT o.origin, count(*) AS orders,
|
||||
COALESCE(sum((o.snapshot->>'total_cents')::bigint),0) AS cents, COALESCE(sum({metres}),0) AS metres,
|
||||
count(f.at) AS finished, percentile_cont(0.5) WITHIN GROUP (ORDER BY extract(epoch FROM
|
||||
f.at - o.created_at) - {waited('o.id', 'o.created_at', 'f.at')}) / 3600 AS median_hours
|
||||
FROM dtf_local.orders o
|
||||
LEFT JOIN LATERAL (SELECT min(created_at) AS at FROM dtf_local.movements m
|
||||
WHERE m.order_id=o.id AND m.to_state='fin') f ON true
|
||||
WHERE {REAL_ORDER} AND {within} GROUP BY o.origin''', period).fetchall()}
|
||||
series = []
|
||||
for offset in range((end - start).days + 1):
|
||||
day = start + timedelta(days=offset)
|
||||
@@ -892,6 +904,12 @@ def production_stats(days: int | None = Query(default=None, ge=7, le=365), start
|
||||
'orders': total['orders'], 'cents': int(total['cents']), 'metres': float(total['metres']),
|
||||
'corrected': total['corrected'], 'daily': series,
|
||||
'treated': {'orders': treated_orders, 'by': [{'who': row['who'], 'orders': row['orders']} for row in treated]},
|
||||
'origins': [{'origin': name, 'orders': origins[name]['orders'] if name in origins else 0,
|
||||
'cents': int(origins[name]['cents']) if name in origins else 0,
|
||||
'metres': float(origins[name]['metres']) if name in origins else 0.0,
|
||||
'finished': origins[name]['finished'] if name in origins else 0,
|
||||
'median_hours': hours(origins[name]['median_hours']) if name in origins else None}
|
||||
for name in ORIGINS],
|
||||
'lead': {'orders': lead['orders'], 'median_hours': hours(lead['median_hours'])},
|
||||
'stages': {row['state']: {'orders': row['orders'], 'passages': row['passages'],
|
||||
'median_hours': hours(row['median_hours'])} for row in stages},
|
||||
|
||||
@@ -92,7 +92,8 @@ def create_order(c, quote, payment):
|
||||
require_clean(upload_row(c, UUID(upload_id), quote['owner']))
|
||||
|
||||
order = c.execute(
|
||||
'INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment) VALUES(%s,%s,%s,%s,%s) RETURNING *',
|
||||
'''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin)
|
||||
VALUES(%s,%s,%s,%s,%s,'site') RETURNING *''',
|
||||
(uuid4(), quote['id'], quote['owner'], Jsonb(approved), Jsonb(payment))).fetchone()
|
||||
# Paid: the files are kept for the order's retention, counted from upload.
|
||||
c.execute('''UPDATE dtf_local.uploads SET expires_at=GREATEST(expires_at, created_at+%s::interval)
|
||||
|
||||
@@ -372,3 +372,14 @@ CREATE INDEX IF NOT EXISTS contact_waits_order ON dtf_local.contact_waits(order_
|
||||
INSERT INTO dtf_local.contact_waits(order_id, started_at)
|
||||
SELECT o.id, o.contact_since FROM dtf_local.orders o
|
||||
WHERE o.contact_since IS NOT NULL AND NOT EXISTS (SELECT 1 FROM dtf_local.contact_waits w WHERE w.order_id=o.id);
|
||||
|
||||
-- Every card is born with its origin (Dropstar's rules D-21 and D-35,
|
||||
-- 2026-10-26): site, dropflow (the montador's batches) or atendimento (an
|
||||
-- order the team enters). No order without one, and no default: a default
|
||||
-- would become the origin of almost everything, so each way in names its own.
|
||||
-- The orders from before this column all came from the Site.
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS origin text;
|
||||
UPDATE dtf_local.orders SET origin='site' WHERE origin IS NULL;
|
||||
ALTER TABLE dtf_local.orders ALTER COLUMN origin SET NOT NULL;
|
||||
ALTER TABLE dtf_local.orders DROP CONSTRAINT IF EXISTS orders_origin_check;
|
||||
ALTER TABLE dtf_local.orders ADD CONSTRAINT orders_origin_check CHECK (origin IN ('site','dropflow','atendimento'));
|
||||
|
||||
Reference in New Issue
Block a user