feat: two cards at most in Imprimindo per machine, one printing and one ripping (Dropstar's third round, item 11)
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 4m14s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m5s
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 4m14s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m5s
A third pull onto the same machine is refused with "máquina5 já tem 2 em Imprimindo", and so is changing a printing order to a full machine. On the board, the first order to enter Imprimindo on its machine is labelled Imprimindo and the next Ripando; the column shows each machine's count, as "máquina5 · 2/2". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -140,7 +140,7 @@ def board(request: Request, user=Depends(operator)):
|
||||
'mail': mail.status(c)},
|
||||
'environment': ENVIRONMENT, 'site_origin': PUBLIC_ORIGIN,
|
||||
'finished_shown': len(finished), 'finished_total': finished_total,
|
||||
'machines': machines.rows(c),
|
||||
'machines': machines.rows(c), 'printing_cap': machines.PRINTING_CAP,
|
||||
'quotes': quotes, 'thumbnails': thumbnails(c, orders, quotes),
|
||||
'names': company_names(c, orders, quotes),
|
||||
'pending_total': pending_total, 'approved_total': approved_total}
|
||||
@@ -189,12 +189,15 @@ TREATED = """f.kind='final'
|
||||
|
||||
def assign_machines(c, orders):
|
||||
"""Each order's machine as stored (app/machines.py gives it): chosen by
|
||||
someone, or automatic. None while no machine prints its product."""
|
||||
someone, or automatic. None while no machine prints its product. In
|
||||
Imprimindo, also which of its machine's two places it holds."""
|
||||
names = {str(m['id']): m['name'] for m in c.execute('SELECT id,name FROM dtf_local.machines').fetchall()}
|
||||
slots = machines.printing_slots(c)
|
||||
for order in orders:
|
||||
key = str(order.get('machine_id') or '')
|
||||
order['machine'] = ({'id': key, 'name': names[key], 'chosen': bool(order.get('machine_chosen'))}
|
||||
if key in names else None)
|
||||
order['printing'] = slots.get(order['id'])
|
||||
return orders
|
||||
|
||||
|
||||
@@ -634,11 +637,16 @@ def choose_machine(uid: UUID, body: MachineChoice, user=Depends(can('print'))):
|
||||
with db.connect() as c:
|
||||
if body.machine_id and not c.execute('SELECT 1 FROM dtf_local.machines WHERE id=%s', (body.machine_id,)).fetchone():
|
||||
raise HTTPException(404, 'Máquina não encontrada.')
|
||||
row = c.execute('UPDATE dtf_local.orders SET machine_id=%s, machine_chosen=%s WHERE id=%s RETURNING number',
|
||||
(body.machine_id, body.machine_id is not None, uid)).fetchone()
|
||||
row = c.execute('''UPDATE dtf_local.orders SET machine_id=%s, machine_chosen=%s WHERE id=%s
|
||||
RETURNING number, state, cancelled_at''', (body.machine_id, body.machine_id is not None, uid)).fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, 'Pedido não encontrado.')
|
||||
machines.route(c)
|
||||
# Printing already: the machine it goes to must have a place in Imprimindo.
|
||||
if row['state'] == 'imp' and not row['cancelled_at']:
|
||||
now = c.execute('SELECT machine_id FROM dtf_local.orders WHERE id=%s', (uid,)).fetchone()
|
||||
if name := machines.full(c, now['machine_id'], uid):
|
||||
raise HTTPException(409, f'{name} já tem {machines.PRINTING_CAP} em Imprimindo.')
|
||||
audit('order_machine_chosen', order=row['number'], machine=str(body.machine_id or ''), operator=user)
|
||||
return {'ok': True}
|
||||
|
||||
@@ -755,6 +763,9 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
JOIN dtf_local.uploads u ON u.id=f.upload_id WHERE f.order_id=%s AND {FINAL_OK}''', (uid,)).fetchall()
|
||||
if {r['item_index'] for r in coverage} != set(range(len(row['snapshot']['items']))):
|
||||
raise HTTPException(409, 'Aprove os arquivos finais de todos os itens antes de mandar para Arte conferida.')
|
||||
# Two at most per machine in Imprimindo (app/machines.py).
|
||||
if body.state == 'imp' and (name := machines.full(c, row['machine_id'], uid)):
|
||||
raise HTTPException(409, f'{name} já tem {machines.PRINTING_CAP} em Imprimindo.')
|
||||
if body.state == 'fin' and proof.needs_proof(row['snapshot']) and not row['proof_ok_at']:
|
||||
raise HTTPException(409, 'Falta a prova: confira a prova impressa e marque Prova OK antes de finalizar.')
|
||||
if body.state == 'cor':
|
||||
|
||||
@@ -15,6 +15,10 @@ OPEN = ('rec', 'tra', 'imp', 'cor')
|
||||
MOVABLE = ('rec', 'tra', 'cor')
|
||||
# One routing at a time, so two at once cannot both pick the same "least loaded".
|
||||
LOCK = 7_041_901
|
||||
# Two orders at most in Imprimindo per machine (Dropstar, 2026-10-29): one
|
||||
# printing, the next being ripped by FlexiPRINT meanwhile. A third would
|
||||
# make the RIP choke; two mean the next sheet is ready when one ends.
|
||||
PRINTING_CAP = 2
|
||||
|
||||
|
||||
def product_family(order):
|
||||
@@ -104,3 +108,26 @@ def rows(c, with_operators=False):
|
||||
row['operators'] = operators.get(key, [])
|
||||
result.append(row)
|
||||
return result
|
||||
|
||||
|
||||
def full(c, machine_id, order_id):
|
||||
"""The machine's name when it already has PRINTING_CAP other orders in
|
||||
Imprimindo, so this one cannot join them; None when it has room. The
|
||||
machine's row is locked, so two pulls at once cannot both take the last
|
||||
place."""
|
||||
if machine_id is None:
|
||||
return None
|
||||
machine = c.execute('SELECT name FROM dtf_local.machines WHERE id=%s FOR UPDATE', (machine_id,)).fetchone()
|
||||
printing = c.execute('''SELECT count(*) AS n FROM dtf_local.orders WHERE machine_id=%s AND state='imp'
|
||||
AND cancelled_at IS NULL AND id<>%s''', (machine_id, order_id)).fetchone()['n']
|
||||
return machine['name'] if machine and printing >= PRINTING_CAP else None
|
||||
|
||||
|
||||
def printing_slots(c):
|
||||
"""Per order in Imprimindo: 'imprimindo' for the first to enter it on its
|
||||
machine (ripped, running), 'ripando' for the one after it."""
|
||||
return {row['id']: 'imprimindo' if row['place'] == 1 else 'ripando' for row in c.execute('''
|
||||
SELECT o.id, row_number() OVER (PARTITION BY o.machine_id ORDER BY m.at, o.number) AS place
|
||||
FROM dtf_local.orders o, LATERAL (SELECT max(created_at) AS at FROM dtf_local.movements
|
||||
WHERE order_id=o.id AND to_state='imp') m
|
||||
WHERE o.state='imp' AND o.cancelled_at IS NULL AND o.machine_id IS NOT NULL''').fetchall()}
|
||||
|
||||
Reference in New Issue
Block a user