fix: a cancelled order takes its open proof card, a renamed machine keeps its hot folder, a film is approved with all its parts
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 8m8s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m11s
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 8m8s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m11s
- Cancelling an order left its proof card not yet answered on the board, where it could still be pulled and printed. It is cancelled with it. - The hot folder path was the machine's current name, so renaming a machine sent its next files to a folder FlexiPRINT does not watch. Each machine now keeps the folder it was created with (migration fills it with today's names); no other machine may take that name, and the machine form shows the folder. - A final set with only some parts of a film was accepted, the #130 failure through the manual path. The server now refuses it and names the parts missing. - The proof card note says up to 30 cm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -73,6 +73,14 @@ def cancel_order(uid: UUID, body: Resolution, user=Depends(can('cancel'))):
|
||||
if not row:
|
||||
raise HTTPException(404, 'Pedido não encontrado ou já cancelado.')
|
||||
hotfolder.stop(c, uid)
|
||||
# Its proof card not yet answered goes with it: left on the board, it
|
||||
# could still be pulled and printed for an order no one will take.
|
||||
cards = c.execute('''UPDATE dtf_local.orders SET cancelled_at=now(), cancelled_by=%s, cancel_reason=%s,
|
||||
version=version+1, updated_at=now()
|
||||
WHERE parent_id=%s AND cancelled_at IS NULL AND proof_result IS NULL RETURNING id''',
|
||||
(user, f"Pedido #{row['number']} cancelado: {body.note}", uid)).fetchall()
|
||||
for card in cards:
|
||||
hotfolder.stop(c, card['id'])
|
||||
if payments.in_tiny(row):
|
||||
sale = c.execute("SELECT receipt FROM dtf_local.outbox WHERE event_key=%s AND delivered_at IS NOT NULL",
|
||||
(f'{uid}:paid:tiny',)).fetchone()
|
||||
|
||||
@@ -269,11 +269,14 @@ def list_machines(user=Depends(can('view'))):
|
||||
def create_machine(body: MachineIn, user=Depends(can('users'))):
|
||||
mid = uuid4()
|
||||
with db.connect() as c:
|
||||
if c.execute('SELECT 1 FROM dtf_local.machines WHERE lower(name)=lower(%s)', (body.name.strip(),)).fetchone():
|
||||
raise HTTPException(409, 'Já existe uma máquina com este nome.')
|
||||
c.execute('''INSERT INTO dtf_local.machines(id,name,products,active,limit_metres,places)
|
||||
VALUES(%s,%s,%s,%s,%s,%s)''', (mid, body.name.strip(), sorted(set(body.products)), body.active,
|
||||
body.limit_metres, body.places or machines.DEFAULT_PLACES))
|
||||
# A machine's hot folder is its first name, for good: no other machine
|
||||
# may be called that, or two would share one folder.
|
||||
if c.execute('SELECT 1 FROM dtf_local.machines WHERE lower(name)=lower(%s) OR lower(folder)=lower(%s)',
|
||||
(body.name.strip(), body.name.strip())).fetchone():
|
||||
raise HTTPException(409, 'Já existe uma máquina, ou a pasta de uma máquina, com este nome.')
|
||||
c.execute('''INSERT INTO dtf_local.machines(id,name,folder,products,active,limit_metres,places)
|
||||
VALUES(%s,%s,%s,%s,%s,%s,%s)''', (mid, body.name.strip(), body.name.strip(), sorted(set(body.products)),
|
||||
body.active, body.limit_metres, body.places or machines.DEFAULT_PLACES))
|
||||
audit('machine_created', operator=user, machine=body.name)
|
||||
return {'id': str(mid)}
|
||||
|
||||
@@ -281,9 +284,9 @@ def create_machine(body: MachineIn, user=Depends(can('users'))):
|
||||
@router.post('/api/operator/machines/{mid}')
|
||||
def update_machine(mid: UUID, body: MachineIn, user=Depends(can('users'))):
|
||||
with db.connect() as c:
|
||||
if c.execute('SELECT 1 FROM dtf_local.machines WHERE lower(name)=lower(%s) AND id<>%s',
|
||||
(body.name.strip(), mid)).fetchone():
|
||||
raise HTTPException(409, 'Já existe uma máquina com este nome.')
|
||||
if c.execute('''SELECT 1 FROM dtf_local.machines WHERE (lower(name)=lower(%s) OR lower(folder)=lower(%s))
|
||||
AND id<>%s''', (body.name.strip(), body.name.strip(), mid)).fetchone():
|
||||
raise HTTPException(409, 'Já existe uma máquina, ou a pasta de uma máquina, com este nome.')
|
||||
if not c.execute('''UPDATE dtf_local.machines SET name=%s,products=%s,active=%s,limit_metres=%s,
|
||||
places=COALESCE(%s,places) WHERE id=%s RETURNING id''',
|
||||
(body.name.strip(), sorted(set(body.products)), body.active, body.limit_metres,
|
||||
|
||||
@@ -74,6 +74,20 @@ def submit_files(c, order, body, identity, kind, actor):
|
||||
current = {(row['upload_id'], row['item_index']) for row in c.execute(
|
||||
"SELECT upload_id,item_index FROM dtf_local.order_files WHERE order_id=%s AND kind='final' AND active",
|
||||
(order['id'],)).fetchall()} if kind == 'final' else set()
|
||||
# A film in parts is approved whole: with only some of its parts, the
|
||||
# others never reach the folders or the machine (#114, #128, #130).
|
||||
if kind == 'final':
|
||||
sent = {}
|
||||
for ref in body.files:
|
||||
sent.setdefault(ref.item_index, set()).add(str(ref.upload_id))
|
||||
for row in c.execute('''SELECT item_index, array_agg(upload_id::text ORDER BY part) AS uploads,
|
||||
array_agg(part ORDER BY part) AS numbers FROM dtf_local.print_parts WHERE order_id=%s
|
||||
GROUP BY item_index HAVING count(*) > 1''', (order['id'],)).fetchall():
|
||||
mine = sent.get(row['item_index'], set())
|
||||
missing = [n for n, u in zip(row['numbers'], row['uploads']) if u not in mine]
|
||||
if mine & set(row['uploads']) and missing:
|
||||
raise HTTPException(422, f"O filme do item {row['item_index'] + 1} tem {len(row['uploads'])} partes: "
|
||||
f"envie todas (faltam {', '.join('p' + str(n) for n in missing)}).")
|
||||
kept = {ref.upload_id for ref in body.files if (ref.upload_id, ref.item_index) in current}
|
||||
if kept and len(kept) == len(body.files):
|
||||
raise HTTPException(409, 'Estes já são os arquivos finais. Envie o arquivo novo.')
|
||||
|
||||
@@ -119,12 +119,12 @@ def claim(c, user):
|
||||
they entered it, until the machine has its places' worth in its folder."""
|
||||
c.execute('''UPDATE dtf_local.hot_parts SET state='queued', claimed_at=NULL, claimed_by=NULL
|
||||
WHERE state='claimed' AND claimed_at < now() - %s''', (CLAIM_TIMEOUT,))
|
||||
rows = c.execute('''SELECT h.*, o.machine_id, o.contraction, o.snapshot, m.name AS machine_name, m.places,
|
||||
rows = c.execute('''SELECT h.*, o.machine_id, o.contraction, o.snapshot, COALESCE(m.folder, m.name) AS machine_folder, m.places,
|
||||
(SELECT max(v.id) FROM dtf_local.movements v WHERE v.order_id=o.id AND v.to_state='imp') AS entered
|
||||
FROM dtf_local.hot_parts h JOIN dtf_local.orders o ON o.id=h.order_id
|
||||
JOIN dtf_local.machines m ON m.id=o.machine_id
|
||||
WHERE h.state IN ('queued','claimed','written') AND o.state='imp' AND o.cancelled_at IS NULL
|
||||
ORDER BY m.name, entered, h.order_id, h.seq FOR UPDATE OF h''').fetchall()
|
||||
ORDER BY m.created_at, m.id, entered, h.order_id, h.seq FOR UPDATE OF h''').fetchall()
|
||||
due, busy, blocked = [], {}, set()
|
||||
for row in rows:
|
||||
machine = row['machine_id']
|
||||
@@ -139,7 +139,9 @@ def claim(c, user):
|
||||
if busy.get(machine, 0) >= row['places'] or not cls:
|
||||
blocked.add(order)
|
||||
continue
|
||||
folder = f"{row['machine_name']}/{cls}"
|
||||
# The machine's folder, fixed at its creation: a renamed machine keeps
|
||||
# the path FlexiPRINT watches.
|
||||
folder = f"{row['machine_folder']}/{cls}"
|
||||
c.execute('''UPDATE dtf_local.hot_parts SET state='claimed', claimed_at=now(), claimed_by=%s, folder=%s
|
||||
WHERE id=%s''', (user, folder, row['id']))
|
||||
busy[machine] = busy.get(machine, 0) + 1
|
||||
|
||||
@@ -39,7 +39,8 @@ def loads(c):
|
||||
|
||||
def rows(c, with_operators=False):
|
||||
"""Every machine with its load, for the Kanban."""
|
||||
machines = c.execute('''SELECT id, name, products, active, limit_metres, places FROM dtf_local.machines
|
||||
machines = c.execute('''SELECT id, name, COALESCE(folder, name) AS folder, products, active, limit_metres, places
|
||||
FROM dtf_local.machines
|
||||
ORDER BY created_at, name''').fetchall()
|
||||
load = loads(c)
|
||||
operators = {}
|
||||
@@ -55,7 +56,7 @@ def rows(c, with_operators=False):
|
||||
for m in machines:
|
||||
key = str(m['id'])
|
||||
used = load.get(key, {'metres': Decimal(0), 'orders': 0, 'states': {}})
|
||||
row = {'id': key, 'name': m['name'], 'products': m['products'], 'active': m['active'],
|
||||
row = {'id': key, 'name': m['name'], 'folder': m['folder'], 'products': m['products'], 'active': m['active'],
|
||||
'limit_metres': float(m['limit_metres']) if m['limit_metres'] is not None else None,
|
||||
'places': m['places'],
|
||||
'open_metres': float(used['metres']), 'open_orders': used['orders'], 'states': used['states'],
|
||||
|
||||
5
app/migrations/202611272000_machine-folder.sql
Normal file
5
app/migrations/202611272000_machine-folder.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
-- Each machine's hot folder (3. Imprimindo/<folder>/C1..) is fixed when the
|
||||
-- machine is created: FlexiPRINT watches that path, so renaming the machine
|
||||
-- must not send its files to a folder nobody watches (2026-11-27).
|
||||
ALTER TABLE dtf_local.machines ADD COLUMN IF NOT EXISTS folder text;
|
||||
UPDATE dtf_local.machines SET folder=name WHERE folder IS NULL;
|
||||
Reference in New Issue
Block a user