Some checks failed
Build and deploy / Validate source (push) Successful in 1m8s
Build and deploy / Integration suite on a real stack (push) Failing after 3m14s
Build and deploy / Publish images (push) Has been skipped
Build and deploy / Secret scan and release gate (push) Successful in 9s
An order with a proof (asked for at checkout, or above 10 m) gets a child
card "Prova": an order of its own (orders.parent_id), no sale, with the
film's first 30 cm as DTF-N-item-1-prova.png ("Prova do pedido DTF-N" in its
footer), which follows the flow up to Revisão like any card, hot folder
included. The order waits outside the queue, "Aguardando prova": it is not
pulled to Imprimindo, nor counted in the queue's places.
In Revisão the card is answered by the Vendedor, Gestão or the
Administrador (capability "proof"): Prova OK records who and when and puts
the order in Arte conferida when its finals are approved; Prova reprovada,
with its reason, sends the order back to Arte recebida, its final to be
approved again, and offers "Nova prova". Either way the card closes and
leaves the board. An order from before the cards keeps the old Prova OK.
The card is kept out of Tiny, e-mails, Números, the search, Finalizado and
the customer's account. Deleting an order takes its cards and their rows:
movements, order files and print files now cascade with their order.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
3.5 KiB
Python
77 lines
3.5 KiB
Python
"""The print proof (Dropstar, 2026-10-21).
|
|
|
|
An order above 10 m prints a proof before the rest, checked by the print room
|
|
without stopping the order. Dropstar's rule (2026-10-23): up to 30 cm, from
|
|
the part with the thinnest lines, a piece of each different artwork, at most
|
|
three proofs per order, never billed. On an order above 10 m the customer
|
|
may also ask for a proof at checkout (below 10 m there is none, Dropstar
|
|
2026-10-28): that order waits for them, marked "Aguardando contato", until
|
|
they approve the photo sent by WhatsApp. Either way the room
|
|
marks "Prova OK" once the proof is checked, and without it the order does not
|
|
reach Finalizado.
|
|
"""
|
|
from decimal import Decimal
|
|
from uuid import NAMESPACE_URL, uuid4, uuid5
|
|
|
|
from psycopg.types.json import Jsonb
|
|
|
|
PROOF_ABOVE_METRES = Decimal('10')
|
|
CUSTOMER_NOTE = ('O cliente pediu uma prova antes de imprimir: mande a foto da prova pelo WhatsApp '
|
|
'e espere o aceite.')
|
|
|
|
|
|
def billed_metres(snapshot):
|
|
return sum((Decimal(str(item.get('billed_metres') or 0)) for item in snapshot.get('items') or []), Decimal(0))
|
|
|
|
|
|
def needs_proof(snapshot):
|
|
"""Whether the order prints a proof first: asked for, or above 10 m."""
|
|
return bool(snapshot.get('proof')) or billed_metres(snapshot) > PROOF_ABOVE_METRES
|
|
|
|
|
|
# ---- The proof card (Dropstar's third round, 2026-10-30 and 2026-11-03) -----
|
|
#
|
|
# An order with a proof becomes a parent and a child. The child, the card
|
|
# "Prova", is an order of its own (orders.parent_id) with a pre-built proof
|
|
# sheet of up to 30 cm, DTF-N-item-1-prova.png, and follows the normal flow up
|
|
# to Revisão. The parent waits outside the queue, "Aguardando prova". On the
|
|
# child, the Vendedor (Gestão and the Administrador too) marks Prova OK, and
|
|
# the parent enters the queue; or Prova reprovada, with its reason, and the
|
|
# parent goes back to Arte recebida and the child closes. The child is no
|
|
# sale: it is not in Tiny, Números, the customer's account or their e-mails.
|
|
PROOF_SHEET_CM = Decimal('30')
|
|
# Three proofs at most per order, one per item (Dropstar, 2026-10-23).
|
|
MAX_PROOFS = 3
|
|
PROVIDER = 'prova'
|
|
|
|
|
|
def proof_identity(order_id):
|
|
return uuid5(NAMESPACE_URL, f'dtf-proof:{order_id}')
|
|
|
|
|
|
def create_child(c, parent):
|
|
"""The parent's proof card, in Arte recebida, its proof sheets queued to be
|
|
generated. Returns it, or None when the order needs no proof."""
|
|
if parent.get('parent_id') or not needs_proof(parent['snapshot']):
|
|
return None
|
|
from .printjobs import queue
|
|
snapshot = {**parent['snapshot'], 'items': parent['snapshot']['items'][:MAX_PROOFS],
|
|
'proof_of': parent['number']}
|
|
child = c.execute('''INSERT INTO dtf_local.orders(id,owner,snapshot,payment,origin,parent_id,machine_id,machine_chosen)
|
|
VALUES(%s,%s,%s,%s,%s,%s,%s,%s) RETURNING *''',
|
|
(uuid4(), proof_identity(parent['id']), Jsonb(snapshot), Jsonb({'provider': PROVIDER}),
|
|
parent['origin'], parent['id'], parent.get('machine_id'), parent.get('machine_chosen', False))).fetchone()
|
|
queue(c, child['id'], len(snapshot['items']))
|
|
return child
|
|
|
|
|
|
def open_child(c, parent_id):
|
|
"""The parent's proof card still waiting for its answer, if any."""
|
|
return c.execute('''SELECT * FROM dtf_local.orders WHERE parent_id=%s AND proof_result IS NULL
|
|
AND cancelled_at IS NULL ORDER BY created_at DESC LIMIT 1''', (parent_id,)).fetchone()
|
|
|
|
|
|
def waiting(c, order):
|
|
"""Whether the order waits for its proof: it has a proof card without an OK."""
|
|
return not order.get('parent_id') and not order.get('proof_ok_at') and bool(open_child(c, order['id']))
|