fix: a reprint keeps an all-items choice, an undone pass to Revisão prints nothing again, and Prova OK tells Tiny (#105)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m56s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m26s
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m56s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m26s
- Every item ticked was saved as NULL, which also means "not chosen", so the pass to the queue replaced it with the suggestion and only the changed item went to the machine; the panel showed the suggestion again. The choice is now the whole list. - Undoing a pass to Revisão (back to Imprimindo) started a new round with every file, so FlexiPRINT printed the order again. It now writes back only what Flexi had not taken, and the reprint choice of that pass returns. A pass undone this way no longer counts its film twice in the machine's metres (machine log and Números). - An order entering the queue by Prova OK never sent Tiny's "Preparando envio". The stage's Tiny event is now one function, used by the move and by the Prova OK. Integration test follows the real moves: suggestion, all items kept, pull onto a machine, two undone passes to Revisão, metres counted once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -398,7 +398,13 @@ def run():
|
||||
final = c.execute('''SELECT note,created_by FROM dtf_local.order_files
|
||||
WHERE order_id=%s AND kind='final' AND active''', (parent['id'],)).fetchone()
|
||||
assert final['created_by'] == 'Prumo' and 'prova' in final['note'].lower(), final
|
||||
print('PASS: Prova OK turns Prumo\'s full file into the parent final and queues it')
|
||||
# Entering the queue by Prova OK is Tiny's "Preparando envio", as a card
|
||||
# moved by hand (orders with a proof skipped it).
|
||||
with db.connect() as c:
|
||||
started = c.execute("SELECT payload FROM dtf_local.outbox WHERE event_key=%s",
|
||||
(f"{parent['id']}:production_started:tiny",)).fetchone()
|
||||
assert started and started['payload']['event'] == 'production_started', started
|
||||
print('PASS: Prova OK turns Prumo\'s full file into the parent final, queues it and tells Tiny')
|
||||
|
||||
# Prova OK while the parent's file is still being generated (#81, 91,5 m,
|
||||
# 2026-11-24): the parent waits in Arte recebida and enters the queue on
|
||||
@@ -433,7 +439,10 @@ def run():
|
||||
moved = c.execute('''SELECT operator,reason FROM dtf_local.movements
|
||||
WHERE order_id=%s AND to_state='tra' ORDER BY id DESC LIMIT 1''', (parent['id'],)).fetchone()
|
||||
assert (moved['operator'], moved['reason']) == ('Prumo', 'Prova OK'), moved
|
||||
print('PASS: a file finished after Prova OK becomes the final and queues the order')
|
||||
with db.connect() as c:
|
||||
assert c.execute("SELECT 1 FROM dtf_local.outbox WHERE event_key=%s",
|
||||
(f"{parent['id']}:production_started:tiny",)).fetchone()
|
||||
print('PASS: a file finished after Prova OK becomes the final, queues the order and tells Tiny')
|
||||
|
||||
# Reprinting some items (Marcus, 2026-11-26, #105): an order the machine
|
||||
# already printed, back in the queue after one item's final changed, sends
|
||||
@@ -472,30 +481,69 @@ def run():
|
||||
{'item_index': 1, 'upload_id': corrected}]}, operator=True)['version']
|
||||
board_order = next(o for o in client.call('/operator/board', operator=True)['orders'] if o['id'] == rid)
|
||||
assert board_order['printed_before'] and board_order['print_suggested'] == [1], board_order.get('print_suggested')
|
||||
client.call('/operator/orders/' + rid + '/move', {'state': 'tra', 'version': v}, operator=True)
|
||||
from app import hotfolder
|
||||
v = client.call('/operator/orders/' + rid + '/move', {'state': 'tra', 'version': v}, operator=True)['version']
|
||||
|
||||
def print_items():
|
||||
with db.connect() as c:
|
||||
return c.execute('SELECT print_items FROM dtf_local.orders WHERE id=%s', (rid,)).fetchone()['print_items']
|
||||
|
||||
def version():
|
||||
return next(o for o in client.call('/operator/board', operator=True)['orders'] if o['id'] == rid)['version']
|
||||
|
||||
assert print_items() == [1], print_items()
|
||||
# Every item ticked by hand in Arte recebida is a choice too: entering the
|
||||
# queue keeps it, the suggestion does not take its place.
|
||||
client.call('/operator/orders/' + rid + '/move', {'state': 'rec', 'version': v, 'reason': 'teste'}, operator=True)
|
||||
assert client.call('/operator/orders/' + rid + '/print-items', {'items': [0, 1]}, operator=True)['print_items'] == [0, 1]
|
||||
client.call('/operator/orders/' + rid + '/move', {'state': 'tra', 'version': version()}, operator=True)
|
||||
assert print_items() == [0, 1], print_items()
|
||||
# Back to only the corrected item, then pulled onto a machine for real.
|
||||
assert client.call('/operator/orders/' + rid + '/print-items', {'items': [1]}, operator=True)['print_items'] == [1]
|
||||
machine = client.call('/operator/machines', {'name': f'Reprint {uuid4().hex[:6]}', 'products': ['textil']},
|
||||
operator=True)['id']
|
||||
v = client.call('/operator/orders/' + rid + '/move', {'state': 'imp', 'version': version(), 'machine_id': machine},
|
||||
operator=True)['version']
|
||||
with db.connect() as c:
|
||||
assert c.execute('SELECT print_items FROM dtf_local.orders WHERE id=%s', (rid,)).fetchone()['print_items'] == [1]
|
||||
hotfolder.start(c, rid)
|
||||
queued = c.execute('SELECT item_index,upload_id FROM dtf_local.hot_parts WHERE order_id=%s AND round=2',
|
||||
(rid,)).fetchall()
|
||||
assert [(q['item_index'], str(q['upload_id'])) for q in queued] == [(1, corrected)], queued
|
||||
c.execute("UPDATE dtf_local.hot_parts SET state='consumed' WHERE order_id=%s AND round=2", (rid,))
|
||||
c.execute("UPDATE dtf_local.orders SET state='imp' WHERE id=%s", (rid,))
|
||||
v = c.execute('SELECT version FROM dtf_local.orders WHERE id=%s', (rid,)).fetchone()['version']
|
||||
client.call('/operator/orders/' + rid + '/move', {'state': 'rev', 'version': v}, operator=True)
|
||||
assert [(q['item_index'], str(q['upload_id'])) for q in queued] == [(1, corrected)], queued
|
||||
# Sent to Revisão by mistake before Flexi took the file, and undone: the
|
||||
# file goes back to the folder, alone, and the choice is the same.
|
||||
v = client.call('/operator/orders/' + rid + '/move', {'state': 'rev', 'version': v}, operator=True)['version']
|
||||
assert print_items() is None
|
||||
v = client.call('/operator/orders/' + rid + '/move', {'state': 'imp', 'version': v, 'reason': 'engano'},
|
||||
operator=True)['version']
|
||||
assert print_items() == [1], print_items()
|
||||
with db.connect() as c:
|
||||
moved = c.execute('''SELECT items FROM dtf_local.movements WHERE order_id=%s AND to_state='rev'
|
||||
ORDER BY id DESC LIMIT 1''', (rid,)).fetchone()
|
||||
left = c.execute('SELECT print_items FROM dtf_local.orders WHERE id=%s', (rid,)).fetchone()['print_items']
|
||||
assert moved['items'] == [1] and left is None, (moved, left)
|
||||
# Chosen by hand: every item means all, as on a first print.
|
||||
again = c.execute('SELECT item_index,upload_id,state FROM dtf_local.hot_parts WHERE order_id=%s AND round=3',
|
||||
(rid,)).fetchall()
|
||||
assert [(r['item_index'], str(r['upload_id']), r['state']) for r in again] == [(1, corrected, 'queued')], again
|
||||
c.execute("UPDATE dtf_local.hot_parts SET state='consumed' WHERE order_id=%s AND round=3", (rid,))
|
||||
# Flexi took it: undoing a later pass to Revisão writes nothing again.
|
||||
v = client.call('/operator/orders/' + rid + '/move', {'state': 'rev', 'version': v}, operator=True)['version']
|
||||
v = client.call('/operator/orders/' + rid + '/move', {'state': 'imp', 'version': v, 'reason': 'engano'},
|
||||
operator=True)['version']
|
||||
with db.connect() as c:
|
||||
assert not c.execute('SELECT 1 FROM dtf_local.hot_parts WHERE order_id=%s AND round>3', (rid,)).fetchone()
|
||||
client.call('/operator/orders/' + rid + '/move', {'state': 'rev', 'version': v}, operator=True)
|
||||
from app import machine_log
|
||||
with db.connect() as c:
|
||||
moved = c.execute("SELECT items FROM dtf_local.movements WHERE order_id=%s AND to_state='rev' "
|
||||
"ORDER BY id DESC LIMIT 1", (rid,)).fetchone()
|
||||
item = c.execute('SELECT snapshot FROM dtf_local.orders WHERE id=%s', (rid,)).fetchone()['snapshot']['items'][1]
|
||||
metres = machine_log.printed_since(c, machine, None)
|
||||
assert moved['items'] == [1] and print_items() is None, moved
|
||||
# Three passes to Revisão, two of them undone: item 2's film, once.
|
||||
expected = Decimal(str(item['metres'] if item.get('metres') is not None else item.get('billed_metres') or 0))
|
||||
assert metres == expected, (metres, expected)
|
||||
# Chosen by hand: every item, or some; never an item the order lacks.
|
||||
with db.connect() as c:
|
||||
c.execute("UPDATE dtf_local.orders SET state='rec' WHERE id=%s", (rid,))
|
||||
assert client.call('/operator/orders/' + rid + '/print-items', {'items': [0, 1]}, operator=True)['print_items'] is None
|
||||
assert client.call('/operator/orders/' + rid + '/print-items', {'items': [1, 0, 1]}, operator=True)['print_items'] == [0, 1]
|
||||
assert client.call('/operator/orders/' + rid + '/print-items', {'items': [0]}, operator=True)['print_items'] == [0]
|
||||
client.call('/operator/orders/' + rid + '/print-items', {'items': [5]}, operator=True, expected=422)
|
||||
print('PASS: a reprint sends only the item whose final changed, and the choice ends with the print')
|
||||
print('PASS: a reprint sends only the items chosen, keeps an all-items choice, and an undone pass to Revisão '
|
||||
'neither writes again what Flexi took nor counts the film twice')
|
||||
|
||||
# A CDR cannot be decoded by the worker. The designer prepares the full
|
||||
# parent PNG, then the worker automatically cuts the child's proof from it.
|
||||
|
||||
@@ -23,7 +23,7 @@ class Database:
|
||||
"""Just the reads and writes approve_parent makes."""
|
||||
|
||||
def __init__(self, parts, active):
|
||||
self.parts, self.active, self.inserted = parts, active, []
|
||||
self.parts, self.active, self.inserted, self.outbox = parts, active, [], []
|
||||
|
||||
def execute(self, sql, params=()):
|
||||
text = ' '.join(sql.split())
|
||||
@@ -37,10 +37,17 @@ class Database:
|
||||
return Rows([{'upload_id': u} for u in self.active])
|
||||
if text.startswith('INSERT INTO dtf_local.order_files'):
|
||||
self.inserted.append(params[2])
|
||||
if text.startswith('UPDATE dtf_local.orders SET state'):
|
||||
return Rows([{'version': 2}])
|
||||
if 'FROM dtf_local.outbox' in text:
|
||||
return Rows([])
|
||||
if text.startswith('INSERT INTO dtf_local.outbox'):
|
||||
self.outbox.append((params[0], params[2].obj['event']))
|
||||
return Rows([{'ok': 1}])
|
||||
|
||||
|
||||
ORDER = {'id': 'o', 'state': 'rec', 'cancelled_at': None, 'snapshot': {'items': [{'mode': 'file'}]}}
|
||||
ORDER = {'id': 'o', 'number': 131, 'state': 'rec', 'cancelled_at': None, 'payment': {'provider': 'mercadopago'},
|
||||
'snapshot': {'items': [{'mode': 'file'}]}}
|
||||
|
||||
|
||||
class ProofPartsTests(unittest.TestCase):
|
||||
@@ -54,6 +61,13 @@ class ProofPartsTests(unittest.TestCase):
|
||||
approve_parent(db, ORDER, 'Prumo')
|
||||
self.assertEqual(db.inserted, ['p2'])
|
||||
|
||||
def test_entering_the_queue_by_prova_ok_tells_tiny(self):
|
||||
# Tiny's "Preparando envio", as for a card moved by hand: orders with
|
||||
# a proof skipped it.
|
||||
db = Database(['p1'], set())
|
||||
self.assertTrue(approve_parent(db, ORDER, 'Prumo'))
|
||||
self.assertEqual(db.outbox, [('o:production_started:tiny', 'production_started')])
|
||||
|
||||
def test_a_final_someone_prepared_stays(self):
|
||||
db = Database(['p1', 'p2'], {'treated'})
|
||||
approve_parent(db, ORDER, 'Prumo')
|
||||
|
||||
Reference in New Issue
Block a user