feat: the proof card, machine pull and print file corrections (Dropstar, 05/11)
The proof card owns its final PNG, keeps its parent locked until the seller answers, enters the queue first, and shares one machine with the parent. The board no longer assigns a machine at payment; the puller records it. A stalled print file times out with a card warning and a retry, finished orders sort by completion, and finals are stored as PNG. The original download carries the order number (items 0.1, 0.4 to 0.7 and 0.9).
This commit is contained in:
28
app/proof.py
28
app/proof.py
@@ -14,6 +14,7 @@ from decimal import Decimal
|
||||
from uuid import NAMESPACE_URL, uuid4, uuid5
|
||||
|
||||
from psycopg.types.json import Jsonb
|
||||
from fastapi import HTTPException
|
||||
|
||||
PROOF_ABOVE_METRES = Decimal('10')
|
||||
CUSTOMER_NOTE = ('O cliente pediu uma prova antes de imprimir: mande a foto da prova pelo WhatsApp '
|
||||
@@ -33,13 +34,13 @@ def needs_proof(snapshot):
|
||||
#
|
||||
# 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
|
||||
# sheet of up to 15 cm per contraction class, 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')
|
||||
PROOF_SHEET_CM = Decimal('15')
|
||||
# Three proofs at most per order, one per item (Dropstar, 2026-10-23).
|
||||
MAX_PROOFS = 3
|
||||
PROVIDER = 'prova'
|
||||
@@ -55,8 +56,20 @@ def create_child(c, parent):
|
||||
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']}
|
||||
# A class has one proof. When several items share it, use the one with the
|
||||
# finest measured line; no metre or product value is sold on this card.
|
||||
classes = {}
|
||||
for index, item in enumerate(parent['snapshot']['items']):
|
||||
kind = item.get('stroke_class') or 'C3'
|
||||
width = item.get('stroke_px') or 10000
|
||||
if kind not in classes or width < classes[kind][0]:
|
||||
classes[kind] = (width, index, item)
|
||||
selected = [classes[kind] for kind in ('C1', 'C2', 'C3') if kind in classes][:MAX_PROOFS]
|
||||
proof_items = [{**item, 'billed_metres': '0', 'total_cents': 0, 'unit_cents': 0,
|
||||
'proof_parent_item_index': index} for _, index, item in selected]
|
||||
freight = {**parent['snapshot'].get('freight', {}), 'total_cents': 0}
|
||||
snapshot = {**parent['snapshot'], 'items': proof_items, 'total_cents': 0,
|
||||
'freight': freight, '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}),
|
||||
@@ -74,3 +87,10 @@ def open_child(c, parent_id):
|
||||
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']))
|
||||
|
||||
|
||||
def require_unlocked(c, order):
|
||||
"""A parent cannot enter production or have its final changed before the proof answer."""
|
||||
if waiting(c, order):
|
||||
child = open_child(c, order['id'])
|
||||
raise HTTPException(409, f'Aguardando prova do #{child["number"]}: responda no card da prova.')
|
||||
|
||||
Reference in New Issue
Block a user