feat: "Arte tratada" flags the orders whose final the team prepared, counted in Números
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 3m20s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 58s

Dropstar's internal rules (2026-10-26) asked how to tell art that arrived
ready from art the designer had to fix, and Marcus agreed on 2026-10-27 to
mark it automatically, for the designer's productivity.

- an order whose approved final is not the customer's art (not the file the
  system generated from it, not one of their originals, not a correction
  they sent) shows "Arte tratada" on its card and in the order, with who
  approved it
- Números counts the period's treated orders, the share of all orders, and
  how many each person approved
- the Kanban's cancel text: the money stays as the customer's credit, in
  Dropstar's financial control (rule D-15), no longer a refund
- Números' machine table shows the orders waiting in Arte conferida again;
  it still looked for the old print queue

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-27 10:01:35 -03:00
parent f77de40b7f
commit 35e64d77d7
6 changed files with 72 additions and 4 deletions

View File

@@ -175,6 +175,15 @@ def company_names(c, *groups):
# An item's final counts while its file is still there and scanned clean: the
# same rule that lets an order into the print queue.
FINAL_OK = """f.kind='final' AND f.active AND u.expires_at>now() AND u.purged_at IS NULL AND u.scan_state='clean'"""
# "Arte tratada" (Dropstar, 2026-10-27): a final someone prepared, not the
# customer's own artwork. It is neither the file the system generated from
# their art, nor one of their originals, nor a correction they sent. `f` is
# the final in dtf_local.order_files, `o` its order.
TREATED = """f.kind='final'
AND NOT EXISTS (SELECT 1 FROM dtf_local.print_files p WHERE p.order_id=f.order_id AND p.upload_id=f.upload_id)
AND NOT EXISTS (SELECT 1 FROM jsonb_array_elements(o.snapshot->'items') i WHERE i->'uploads' ? f.upload_id::text)
AND NOT EXISTS (SELECT 1 FROM dtf_local.order_files k WHERE k.order_id=f.order_id AND k.upload_id=f.upload_id
AND k.kind='correction')"""
def assign_machines(c, orders):
@@ -211,6 +220,10 @@ def with_print_files(c, orders):
(u.expires_at<=now() OR u.purged_at IS NOT NULL) AS expired FROM dtf_local.order_files f
JOIN dtf_local.uploads u ON u.id=f.upload_id
WHERE f.order_id=ANY(%s) AND f.kind='correction' AND f.active ORDER BY f.item_index''', (ids,)).fetchall()
# The items whose approved final someone prepared, and who approved it.
treated = c.execute(f'''SELECT f.order_id,f.item_index,f.created_by FROM dtf_local.order_files f
JOIN dtf_local.orders o ON o.id=f.order_id WHERE f.order_id=ANY(%s) AND f.active AND {TREATED}
ORDER BY f.item_index''', (ids,)).fetchall()
# Why each order was last sent to correction, for the notice to the customer.
reasons = {row['order_id']: row['reason'] for row in c.execute('''SELECT DISTINCT ON (order_id) order_id,reason
FROM dtf_local.movements WHERE order_id=ANY(%s) AND to_state='cor' ORDER BY order_id,id DESC''', (ids,)).fetchall()}
@@ -218,6 +231,8 @@ def with_print_files(c, orders):
order['correction_reason'] = reasons.get(order['id']) if order['state'] == 'cor' else None
order['print_files'] = [row for row in generated if row['order_id'] == order['id']]
order['final_items'] = sorted(row['item_index'] for row in finals if row['order_id'] == order['id'])
mine = [row for row in treated if row['order_id'] == order['id']]
order['treated'] = {'items': [row['item_index'] for row in mine], 'by': mine[0]['created_by']} if mine else None
order['corrections'] = [{k: row[k] for k in ('item_index', 'upload_id', 'name', 'expired')}
for row in fixes if row['order_id'] == order['id']]
return assign_machines(c, orders)
@@ -843,6 +858,15 @@ def production_stats(days: int | None = Query(default=None, ge=7, le=365), start
o.created_at))) / 3600 AS oldest_hours
FROM dtf_local.orders o WHERE {REAL_ORDER} AND o.state<>'fin' GROUP BY o.state''').fetchall()
printed = machine_output(c, start, end)
# Arte tratada, for the designer's productivity: orders of the period
# whose final someone prepared, by who approved it (any version).
treated = c.execute(f'''SELECT COALESCE(op.name, f.created_by) AS who, count(DISTINCT f.order_id) AS orders
FROM dtf_local.order_files f JOIN dtf_local.orders o ON o.id=f.order_id
LEFT JOIN dtf_local.operators op ON op.email=f.created_by
WHERE {REAL_ORDER} AND {within} AND {TREATED} GROUP BY 1 ORDER BY 2 DESC, 1''', period).fetchall()
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']
series = []
for offset in range((end - start).days + 1):
day = start + timedelta(days=offset)
@@ -853,6 +877,7 @@ def production_stats(days: int | None = Query(default=None, ge=7, le=365), start
return {'days': len(series), 'start': start.isoformat(), 'end': end.isoformat(),
'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]},
'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},