feat: the bobbin footer names the customer and counts the pieces, without price (Rodada 5, C3)
DROPSTAR · Pedido DTF-7 · <cliente> · Item 1/2 · data · metros · N peças (loose arts) or N cópias (a ready sheet repeated). The name is tidied to cp1252 and cut at 24 characters; the proof footer is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -336,11 +336,22 @@ def file_prefix(number, item_index, generation=1):
|
||||
return f'DTF-{number}{version}-item-{item_index + 1}'
|
||||
|
||||
|
||||
def _footer_name(name):
|
||||
"""A customer name for the footer: tidy, printable in cp1252 and at most
|
||||
24 characters, the last one an ellipsis when cut."""
|
||||
cleaned = ' '.join(str(name or '').split())
|
||||
cleaned = cleaned.encode('cp1252', 'ignore').decode('cp1252')
|
||||
cleaned = ' '.join(cleaned.split())
|
||||
if len(cleaned) > 24:
|
||||
cleaned = cleaned[:23] + '…'
|
||||
return cleaned
|
||||
|
||||
|
||||
def footer(job, item):
|
||||
"""The print file's footer line: DROPSTAR · Pedido DTF-123 · Item 1/2 ·
|
||||
21/10/2026 · 0,90 m, and · ESPELHADO when the artwork is mirrored. The
|
||||
order is named by its Kanban number, which Tiny keeps; the length is the
|
||||
one billed."""
|
||||
"""The print file's footer line: DROPSTAR · Pedido DTF-123 · <customer> ·
|
||||
Item 1/2 · 21/10/2026 · 0,90 m · <pieces>, and · ESPELHADO when the
|
||||
artwork is mirrored. The order is named by its Kanban number, which Tiny
|
||||
keeps; 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('.', ',')
|
||||
@@ -348,11 +359,25 @@ def footer(job, item):
|
||||
if proof_of:
|
||||
return ' · '.join(['DROPSTAR', f'PROVA do #{proof_of}',
|
||||
f'Classe {item.get("stroke_class") or "C3"}', day])
|
||||
fields = ['DROPSTAR', f'Pedido {purchase_order(job["number"])}',
|
||||
f'Item {job["item_index"] + 1}/{count}', day, f'{billed} m']
|
||||
fields = ['DROPSTAR', f'Pedido {purchase_order(job["number"])}']
|
||||
customer = _footer_name((job['snapshot'].get('customer') or {}).get('name'))
|
||||
if customer:
|
||||
fields.append(customer)
|
||||
fields += [f'Item {job["item_index"] + 1}/{count}', day, f'{billed} m']
|
||||
production = item.get('production') or {}
|
||||
sources = production.get('sources') or []
|
||||
placements = production.get('placements') or []
|
||||
if any(source.get('kind') == 'artwork' for source in sources):
|
||||
pieces = len(placements)
|
||||
if pieces:
|
||||
fields.append(f'{pieces} peça' if pieces == 1 else f'{pieces} peças')
|
||||
elif any(source.get('kind') == 'sheet' for source in sources):
|
||||
copies = sum(source.get('copies') or 0 for source in sources)
|
||||
if copies > 1:
|
||||
fields.append(f'{copies} cópias')
|
||||
# A mirrored artwork (UV only) is named on the sheet, for the room to see
|
||||
# before printing (Dropstar, 2026-10-23).
|
||||
if any(source.get('mirrored') for source in item['production']['sources']):
|
||||
if any(source.get('mirrored') for source in sources):
|
||||
fields.append('ESPELHADO')
|
||||
return ' · '.join(fields)
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ def download_png(client, upload_id):
|
||||
image = Image.open(io.BytesIO(response.read()))
|
||||
assert image.format == 'PNG' and image.mode == 'RGBA', (image.format, image.mode)
|
||||
return image
|
||||
CUSTOMER = {'cnpj': '11222333000181', 'zap': '11999999999', 'mail': 'print-test@example.test'}
|
||||
CUSTOMER = {'cnpj': '11222333000181', 'zap': '11999999999', 'mail': 'print-test@example.test',
|
||||
'name': 'Cliente Print Test'}
|
||||
|
||||
|
||||
def artwork(kind='PNG'):
|
||||
@@ -104,7 +105,10 @@ def run():
|
||||
for copy in range(2):
|
||||
assert film.getpixel((px(20 * copy + 10), px(5))) == (220, 30, 60, 255), copy
|
||||
assert film.getpixel((px(50), px(5)))[3] == 0
|
||||
assert row['detail']['footer'].startswith('DROPSTAR · Pedido DTF-%d · Item 1/1 · ' % order['number']), row['detail']
|
||||
footer = row['detail']['footer']
|
||||
assert footer.startswith('DROPSTAR · Pedido DTF-%d · %s · Item 1/1 · '
|
||||
% (order['number'], CUSTOMER['name'])), footer
|
||||
assert footer.endswith(' · 2 peças'), footer
|
||||
print('PASS: paid order generated a 57 x 10 cm PNG print file with both copies and its footer')
|
||||
|
||||
# A ready sheet with its empty strips cut (Marcus, 2026-11-18): the cart
|
||||
|
||||
@@ -129,7 +129,7 @@ class PrintFileTests(unittest.TestCase):
|
||||
job = {'snapshot': {'items': [spec, spec]}, 'number': 7, 'item_index': 1,
|
||||
'ordered_at': datetime(2026, 10, 23, 15, 0, tzinfo=timezone.utc)}
|
||||
line = footer(job, spec)
|
||||
self.assertEqual(line, 'DROPSTAR · Pedido DTF-7 · Item 2/2 · 23/10/2026 · 1,00 m · ESPELHADO')
|
||||
self.assertEqual(line, 'DROPSTAR · Pedido DTF-7 · Item 2/2 · 23/10/2026 · 1,00 m · 1 peça · ESPELHADO')
|
||||
self.assertIn(b'/F1 31 Tf ( \xb7 ESPELHADO) Tj', footer_commands(line, (100, 80)))
|
||||
# About 1 cm tall on the 57 cm film (Dropstar, 2026-10-28); on the 27 cm UV
|
||||
# the line shrinks to fit the width instead of running off the film.
|
||||
@@ -149,6 +149,35 @@ class PrintFileTests(unittest.TestCase):
|
||||
self.assertEqual(file_prefix(130, 0, 2), 'DTF-130-v2-item-1')
|
||||
self.assertEqual(file_prefix(130, 0, 1), 'DTF-130-item-1')
|
||||
|
||||
def test_the_footer_names_the_customer_and_the_pieces(self):
|
||||
from datetime import datetime, timezone
|
||||
from app.printjobs import footer
|
||||
|
||||
def line(name, spec, items=2):
|
||||
customer = {} if name is None else {'name': name}
|
||||
job = {'snapshot': {'items': [spec] * items, 'customer': customer},
|
||||
'number': 7, 'item_index': 0,
|
||||
'ordered_at': datetime(2026, 10, 21, 15, 0, tzinfo=timezone.utc)}
|
||||
return footer(job, spec)
|
||||
|
||||
spec = item([placement(0, 0, 20, 10)], [source(20, 10)], 10)
|
||||
start = 'DROPSTAR · Pedido DTF-7 · '
|
||||
end = ' · Item 1/2 · 21/10/2026 · 1,00 m · 1 peça'
|
||||
# An accent stays; an emoji does not; a long name is cut with an ellipsis.
|
||||
self.assertEqual(line('Gráfica São José', spec), start + 'Gráfica São José' + end)
|
||||
self.assertEqual(line('Loja 🌟 Azul', spec), start + 'Loja Azul' + end)
|
||||
self.assertEqual(line('Gráfica São José do Vale do Paraíba', spec),
|
||||
start + 'Gráfica São José do Val…' + end)
|
||||
# Without a name the field is left out, with no stray separator.
|
||||
self.assertEqual(line(None, spec), 'DROPSTAR · Pedido DTF-7' + end)
|
||||
# A ready sheet counts its copies, and only says so above one.
|
||||
sheet = item([placement(0, 0, 20, 10)], [{**source(20, 10), 'kind': 'sheet', 'copies': 3}], 10)
|
||||
self.assertEqual(line('Cliente', sheet),
|
||||
'DROPSTAR · Pedido DTF-7 · Cliente · Item 1/2 · 21/10/2026 · 1,00 m · 3 cópias')
|
||||
single = item([placement(0, 0, 20, 10)], [{**source(20, 10), 'kind': 'sheet', 'copies': 1}], 10)
|
||||
self.assertEqual(line('Cliente', single),
|
||||
'DROPSTAR · Pedido DTF-7 · Cliente · Item 1/2 · 21/10/2026 · 1,00 m')
|
||||
|
||||
def test_jpeg_bytes_are_embedded_unchanged(self):
|
||||
path = self.save(quadrants(), 'a.jpg', quality=90)
|
||||
pdf, _ = self.render(item([placement(0, 0, 20, 10)], [source(20, 10)], 10), [path])
|
||||
|
||||
Reference in New Issue
Block a user