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

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:
Cauê Faleiros
2026-10-27 11:39:08 -03:00
parent bba55a83f3
commit 0319039328
13 changed files with 98 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ from urllib.request import Request
from uuid import uuid4
import httpx
import psycopg
from psycopg.types.json import Jsonb
from app.core import db
@@ -81,8 +82,8 @@ def run():
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved)
VALUES(%s,%s,%s,%s,%s,%s)''', (qid, owner, uuid4(), 'kanban-fixture', Jsonb(content),
Jsonb(accepted) if accepted else None))
number = c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment)
VALUES(%s,%s,%s,%s,%s) RETURNING number''',
number = c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin)
VALUES(%s,%s,%s,%s,%s,'site') RETURNING number''',
(order_id, paid, owner, Jsonb({**draft(item('file')), 'total_cents': 1490}),
Jsonb({'provider': 'teste', 'id': f'kanban-{tag}'}))).fetchone()['number']
@@ -126,6 +127,20 @@ def run():
assert (after['orders'], after['cents']) == (before['orders'] + 1, before['cents'] + 1490), (before, after)
assert after['daily'][-1]['orders'] == before['daily'][-1]['orders'] + 1
assert after['waiting']['rec']['orders'] == before.get('waiting', {}).get('rec', {}).get('orders', 0) + 1
# Each way in apart (D-21), all three listed even when empty.
assert [o['origin'] for o in after['origins']] == ['site', 'dropflow', 'atendimento']
site = lambda stats: next(o for o in stats['origins'] if o['origin'] == 'site')
assert (site(after)['orders'], site(after)['cents']) == (site(before)['orders'] + 1, site(before)['cents'] + 1490)
# No order without an origin, and only the three (D-21, D-35).
for origin in (None, 'whatsapp'):
try:
with db.connect() as c:
c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin)
VALUES(%s,%s,%s,'{}','{}',%s)''', (uuid4(), approved, owner, origin))
except (psycopg.errors.NotNullViolation, psycopg.errors.CheckViolation):
pass
else:
raise AssertionError(f'an order with origin {origin!r} was accepted')
client.call('/operator/stats?days=3', operator=True, expected=422)
# Or two dates: the same week asked as a range gives the same numbers.
week = client.call(f"/operator/stats?start={after['start']}&end={after['end']}", operator=True)

View File

@@ -17,7 +17,7 @@ def run():
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
VALUES(%s,%s,%s,'reset-fixture',%s,%s,now())''',
(quote, owner, uuid4(), Jsonb({'customer': {}, 'items': []}), Jsonb({'items': [], 'total_cents': 1490})))
c.execute('INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment) VALUES(%s,%s,%s,%s,%s)',
c.execute("INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin) VALUES(%s,%s,%s,%s,%s,'site')",
(order, quote, owner, Jsonb({'items': [], 'total_cents': 1490}), Jsonb({'provider': 'teste'})))
live = c.execute('''INSERT INTO dtf_local.payment_intents(id,quote_id,provider,provider_payment_id,method,
status,amount_cents,response) VALUES(%s,%s,'mercadopago',%s,'card','approved',1490,%s) RETURNING id''',
@@ -52,8 +52,8 @@ def run():
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
VALUES(%s,%s,%s,'reset-fixture',%s,%s,now())''',
(quote, owner, uuid4(), Jsonb({'customer': {}, 'items': []}), Jsonb({'items': [], 'total_cents': 1490})))
first = c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment)
VALUES(%s,%s,%s,%s,%s) RETURNING number''', (uuid4(), quote, owner, Jsonb({'items': []}),
first = c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin)
VALUES(%s,%s,%s,%s,%s,'site') RETURNING number''', (uuid4(), quote, owner, Jsonb({'items': []}),
Jsonb({'provider': 'teste'}))).fetchone()['number']
assert first == 1, first
c.execute('DELETE FROM dtf_local.orders WHERE quote_id=%s', (quote,))

View File

@@ -27,7 +27,7 @@ def run():
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
VALUES(%s,%s,%s,'actions-fixture',%s,%s,now())''',
(qid, owner, uuid4(), Jsonb({'customer': {'mail': mail}, 'items': []}), Jsonb(approved)))
c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment) VALUES(%s,%s,%s,%s,%s)''',
c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin) VALUES(%s,%s,%s,%s,%s,'site')''',
(paid_order, paid_quote, owner, Jsonb(approved), Jsonb({'provider': 'mercadopago', 'id': '1'})))
listed = lambda: {q['id'] for q in client.call('/operator/quotes?' + urlencode({'kind': 'approved', 'q': mail}),
operator=True)['quotes']}
@@ -94,8 +94,8 @@ def run():
# Dragged within its column: first paid first, unless moved; moving on resets it.
with db.connect() as c:
c.execute("UPDATE dtf_local.orders SET created_at=now()-interval '1 hour' WHERE id=%s", (paid_order,))
c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,created_at)
VALUES(%s,%s,%s,%s,%s,now())''', (newer_order, newer_quote, owner, Jsonb(approved),
c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,created_at,origin)
VALUES(%s,%s,%s,%s,%s,now(),'site')''', (newer_order, newer_quote, owner, Jsonb(approved),
Jsonb({'provider': 'teste', 'id': 't'})))
client.call(f'/operator/orders/{newer_order}/queue', {'before': str(paid_order)}, operator=True)
with db.connect() as c:
@@ -129,8 +129,8 @@ def run():
'total_cents': 1490}
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
VALUES(%s,%s,%s,'actions-fixture',%s,%s,now())''', (quote, owner, uuid4(), Jsonb(content), Jsonb(content)))
c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,cancelled_at,cancelled_by,cancel_reason)
VALUES(%s,%s,%s,%s,%s,%s,%s,%s)''', (order, quote, owner, Jsonb(content), Jsonb({'provider': provider, 'id': '1'}),
c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,cancelled_at,cancelled_by,cancel_reason,origin)
VALUES(%s,%s,%s,%s,%s,%s,%s,%s,'site')''', (order, quote, owner, Jsonb(content), Jsonb({'provider': provider, 'id': '1'}),
'now()' if cancelled else None, 'x' if cancelled else None,
'teste' if cancelled else None))
place(gone_quote, gone_order, [files['original'], files['shared']], 'mercadopago', True)

View File

@@ -44,7 +44,7 @@ def run():
items = [{'mode': 'file', 'uploads': [str(image), str(drawing)]}]
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft)
VALUES(%s,%s,%s,'backfill-fixture',%s)''', (quote, owner, uuid4(), Jsonb({'items': items})))
c.execute('INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment) VALUES(%s,%s,%s,%s,%s)',
c.execute("INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin) VALUES(%s,%s,%s,%s,%s,'site')",
(order, quote, owner, Jsonb({'items': items, 'total_cents': 1490}), Jsonb({'provider': 'teste'})))
lines = []
assert backfill_thumbnails.main([], out=lines.append, storage=storage) == 0

View File

@@ -34,7 +34,7 @@ def order_fixture(c, owner, mode, metres='1', printed=None):
'items': [item], 'freight': {'service': 'pickup'}, 'total_cents': 1490}
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
VALUES(%s,%s,%s,'users-fixture',%s,%s,now())''', (quote, owner, uuid4(), Jsonb(content), Jsonb(content)))
c.execute('INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment) VALUES(%s,%s,%s,%s,%s)',
c.execute("INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin) VALUES(%s,%s,%s,%s,%s,'site')",
(order, quote, owner, Jsonb(content), Jsonb({'provider': 'teste', 'id': str(order)})))
return quote, order

View File

@@ -12,6 +12,8 @@ def run():
q=customer.call('/quotes',{'request_key':str(uuid4()),'customer':profile,'items':[item],'freight':{'service':'pickup'}})
approved_quote(customer,q,[item])
order=customer.call('/orders/dev-paid',{'quote_id':q['id']});oid=order['id']
# A Site order is born marked as one (Dropstar's rule D-21).
assert next(o for o in customer.call('/operator/board',operator=True)['orders'] if o['id']==oid)['origin']=='site'
before=list(customer.jar)[0].value
password='local-test-password-'+uuid4().hex
register(customer,profile,password)