fix: Prova OK approves every part of a film, and "Gerar de novo" names the new files with a version (#114, #128, #130)
Some checks failed
Build and deploy / Validate source (push) Successful in 16s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled

The proof's approval took the print file's first upload as the final, so the
other parts of a film in parts never reached Arte conferida or the hot folder
and were downloaded by hand. It now approves every part, and adds the missing
ones to a first part already approved. A one-off migration completes the
open orders still before Imprimindo. Generated again, the files are named
DTF-130-v2-item-1-p2.png, as Marcus asked, so the FlexiPRINT queue and the
Hoson list never take them for the first ones.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-27 12:25:23 -03:00
parent b8496b858f
commit b027bb5013
8 changed files with 117 additions and 13 deletions

View File

@@ -28,7 +28,8 @@ def named_files(rows):
name = row['name']
if name.startswith(older):
name = prefix + name[len(older):]
elif not name.startswith(prefix):
# DTF-23-item-1 or, generated again, DTF-23-v2-item-1: already named.
elif not name.startswith(f"DTF-{row['number']}-"):
name = f"{prefix}-{name}"
stem, dot, ext = name.rpartition('.')
copy = 2

View File

@@ -0,0 +1,19 @@
-- "Gerar de novo" names the new files with a version (Marcus, 2026-11-27,
-- #130): DTF-130-v2-item-1-p2.png, so neither the Kanban, the FlexiPRINT
-- queue nor the Hoson list mixes them up with the first ones.
ALTER TABLE dtf_local.print_files ADD COLUMN IF NOT EXISTS generation integer NOT NULL DEFAULT 1;
-- A Prova OK approved only the first part of a film in parts (the print
-- file's first upload), so the other parts never reached the folders (#114,
-- #128, #130). For the orders still before Imprimindo, the missing parts join
-- the parts the Prumo already approved.
INSERT INTO dtf_local.order_files(id,order_id,upload_id,item_index,kind,note,created_by)
SELECT gen_random_uuid(), p.order_id, p.upload_id, p.item_index, 'final', 'Parte completada (prova)', 'Prumo'
FROM dtf_local.print_parts p JOIN dtf_local.orders o ON o.id=p.order_id
WHERE o.state IN ('rec','tra') AND o.cancelled_at IS NULL AND o.parent_id IS NULL
AND EXISTS (SELECT 1 FROM dtf_local.order_files f JOIN dtf_local.print_parts q
ON q.order_id=f.order_id AND q.item_index=f.item_index AND q.upload_id=f.upload_id
WHERE f.order_id=p.order_id AND f.item_index=p.item_index AND f.kind='final' AND f.active
AND f.created_by='Prumo')
AND NOT EXISTS (SELECT 1 FROM dtf_local.order_files f WHERE f.order_id=p.order_id
AND f.item_index=p.item_index AND f.upload_id=p.upload_id);

View File

@@ -125,7 +125,8 @@ def requeue(c, order_id, items):
for index in range(items):
c.execute('''INSERT INTO dtf_local.print_files(id,order_id,item_index) VALUES(%s,%s,%s)
ON CONFLICT(order_id,item_index) DO UPDATE SET status='pending', attempts=0,
claimed_at=NULL, claim_token=NULL, finished_at=NULL, upload_id=NULL, detail='{}'
claimed_at=NULL, claim_token=NULL, finished_at=NULL, upload_id=NULL, detail='{}',
generation=dtf_local.print_files.generation+1
WHERE dtf_local.print_files.status<>'rendering' ''', (uuid4(), order_id, index))
@@ -323,10 +324,13 @@ def store_tiles(storage, folder, upload_id):
storage.store(f'originals/tiles/{upload_id}/{level}/{strip}', os.path.join(folder, level, strip), 'image/png')
def file_prefix(number, item_index):
def file_prefix(number, item_index, generation=1):
"""How an order's files are named: DTF-23-item-1, the code the Kanban
copies, the footer prints and Tiny keeps (Dropstar, 2026-10-23)."""
return f'DTF-{number}-item-{item_index + 1}'
copies, the footer prints and Tiny keeps (Dropstar, 2026-10-23); after
"Gerar de novo", DTF-23-v2-item-1, so no one takes the new files for the
old ones (Marcus, 2026-11-27, #130)."""
version = f'-v{generation}' if generation and generation > 1 else ''
return f'DTF-{number}{version}-item-{item_index + 1}'
def footer(job, item):
@@ -401,7 +405,7 @@ def produce(storage, job, item, uploads):
proof_of = job['snapshot'].get('proof_of')
# The child owns its final file; the class names its proof.
prefix = (f'DTF-{job["number"]}-prova-{item.get("stroke_class") or "C3"}' if proof_of
else file_prefix(job['number'], job['item_index']))
else file_prefix(job['number'], job['item_index'], job.get('generation')))
parts, detail = render(item, files, output, prefix, footer=footer(job, item), tiles=True,
limit_cm=PROOF_SHEET_CM if proof_of else None,
proof_fraction=item.get('proof_y_fraction') if proof_of else None,

View File

@@ -123,14 +123,25 @@ def approve_parent(c, parent, operator):
if not designer:
generated = c.execute('''SELECT p.item_index,p.upload_id FROM dtf_local.print_files p
WHERE p.order_id=%s AND p.status='ready' AND p.upload_id IS NOT NULL
AND NOT EXISTS (SELECT 1 FROM dtf_local.order_files f
WHERE f.order_id=p.order_id AND f.item_index=p.item_index AND f.kind='final' AND f.active)
ORDER BY p.item_index''', (parent['id'],)).fetchall()
for row in generated:
c.execute('''INSERT INTO dtf_local.order_files(id,order_id,upload_id,item_index,kind,note,created_by)
VALUES(%s,%s,%s,%s,'final',%s,'Prumo')''',
(uuid4(), parent['id'], row['upload_id'], row['item_index'],
f'Aprovado pela prova do #{card["number"]}'))
# Every part of a film in parts, not only its first: the others
# never reached the folders (#114, #128, #130).
parts = [r['upload_id'] for r in c.execute('''SELECT upload_id FROM dtf_local.print_parts
WHERE order_id=%s AND item_index=%s ORDER BY part''', (parent['id'], row['item_index'])).fetchall()]
parts = parts or [row['upload_id']]
active = {r['upload_id'] for r in c.execute('''SELECT upload_id FROM dtf_local.order_files
WHERE order_id=%s AND item_index=%s AND kind='final' AND active''',
(parent['id'], row['item_index'])).fetchall()}
# A final someone prepared or approved stays as it is.
if active and not active <= set(parts):
continue
for upload_id in parts:
if upload_id not in active:
c.execute('''INSERT INTO dtf_local.order_files(id,order_id,upload_id,item_index,kind,note,created_by)
VALUES(%s,%s,%s,%s,'final',%s,'Prumo')''',
(uuid4(), parent['id'], upload_id, row['item_index'],
f'Aprovado pela prova do #{card["number"]}'))
treatment_clause = f'AND {TREATED}' if designer else ''
ready = all(c.execute(f'''SELECT 1 FROM dtf_local.order_files f
JOIN dtf_local.orders o ON o.id=f.order_id