feat: the print PDF ends in a footer naming the order, item, date and length
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 3m55s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Has been skipped

Dropstar's item 4 (2026-10-21): the PDF had no text at all, so a sheet cut
off or dropped in the room was guesswork. A 1,5 cm band after the last
piece, outside the billed length and never over artwork, carries one line
in black with no background:

  DROPSTAR · Pedido DTF-123 · Item 1/2 · 21/10/2026 · 0,90 m

The order is named by its Kanban number, the purchase order Tiny keeps,
since Tiny's own number may not exist yet when the PDF is made. The brand
is text until Dropstar sends the logo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-22 16:50:31 -03:00
parent e3c31e43e5
commit 18120e686f
5 changed files with 88 additions and 12 deletions

View File

@@ -21,6 +21,8 @@ import os
import tempfile
import time
from datetime import timedelta
from decimal import Decimal
from zoneinfo import ZoneInfo
from uuid import NAMESPACE_URL, UUID, uuid4, uuid5
from psycopg.types.json import Jsonb
@@ -28,6 +30,9 @@ from psycopg.types.json import Jsonb
from .core.auth import audit
from .core.db import connect
from .printfile import Unsupported, render
from .tiny import purchase_order
LOCAL = ZoneInfo('America/Sao_Paulo')
CLAIM_TIMEOUT = timedelta(minutes=15)
MAX_ATTEMPTS = 3
@@ -55,7 +60,7 @@ def queue(c, order_id, items, only_missing=False):
def claim(c):
return c.execute('''SELECT p.*, o.snapshot, o.number FROM dtf_local.print_files p
return c.execute('''SELECT p.*, o.snapshot, o.number, o.created_at AS ordered_at FROM dtf_local.print_files p
JOIN dtf_local.orders o ON o.id=p.order_id
WHERE p.status='pending' OR (p.status='rendering' AND p.claimed_at < now()-%s)
ORDER BY p.created_at FOR UPDATE OF p SKIP LOCKED LIMIT 1''', (CLAIM_TIMEOUT,)).fetchone()
@@ -137,6 +142,17 @@ def whole_sheet(item, uploads):
return row
def footer(job, item):
"""The print file's footer line: DROPSTAR · Pedido DTF-123 · Item 1/2 ·
21/10/2026 · 0,90 m. The order is named by its Kanban number, which Tiny
keeps as the purchase order; the length is the one billed."""
count = len(job['snapshot']['items'])
day = job['ordered_at'].astimezone(LOCAL).strftime('%d/%m/%Y')
billed = f"{Decimal(str(item['billed_metres'])):.2f}".replace('.', ',')
return ' · '.join(('DROPSTAR', f'Pedido {purchase_order(job["number"])}',
f'Item {job["item_index"] + 1}/{count}', day, f'{billed} m'))
def produce(storage, job, item, uploads):
"""Fetch the item's artwork and render it. Returns (pdf path, name, size, evidence)."""
for upload_id in item['uploads']:
@@ -156,7 +172,8 @@ def produce(storage, job, item, uploads):
handle, output = tempfile.mkstemp(prefix='print-', suffix='.pdf')
try:
with os.fdopen(handle, 'wb') as out:
detail = render(item, files, out, f'Pedido {number} - item {job["item_index"] + 1}')
detail = render(item, files, out, f'Pedido {number} - item {job["item_index"] + 1}',
footer=footer(job, item))
except BaseException:
os.unlink(output)
raise