feat: the phase-2 reset script and the proof-order contact rule (0.11)
reset_board deletes orders, quotes, cards, uploads and their history, and empties the Kanban flow folders while keeping Estampas and every setup record. It is a dry run unless --yes is passed, and never resets the order numbering. A proof order closes contact with Prova OK; orders without a proof keep their "Contato feito" action.
This commit is contained in:
92
ops/reset_board.py
Normal file
92
ops/reset_board.py
Normal file
@@ -0,0 +1,92 @@
|
||||
"""0.11 — wipe the board before the site is announced, keeping the setup.
|
||||
|
||||
Deletes orders, quotes, cards, uploads and their history; keeps operators,
|
||||
machines, integrations, prices, categories and the Tiny ids. Numbering is not
|
||||
reset: orders.number is an identity column and DELETE keeps its sequence, as
|
||||
the PDF requires (DTF-1…DTF-15 already exist in Tiny).
|
||||
|
||||
The Kanban folders are written by the browser, so the server cannot discover
|
||||
them: pass the same root the Kanban's folder setting points at. Only the flow
|
||||
folders and Recibos/ are emptied; Estampas/ (the art library) stays.
|
||||
|
||||
Dry run by default. To execute::
|
||||
|
||||
python -m ops.reset_board --root /srv/Kanban --yes
|
||||
|
||||
Run inside the API container or with DATABASE_URL set.
|
||||
"""
|
||||
import argparse
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from app.core.db import connect
|
||||
|
||||
# Children before parents; uploads after every row that references them.
|
||||
TABLES = (
|
||||
'hot_parts', 'print_parts', 'print_files', 'order_files', 'movements',
|
||||
'reworks', 'contact_waits', 'outbox', 'payment_intents', 'orders', 'quotes',
|
||||
'upload_thumbnails', 'uploads',
|
||||
)
|
||||
# payment_events has no foreign key to orders/quotes, but it is payment history.
|
||||
HISTORY = ('payment_events',)
|
||||
FLOW_FOLDERS = ('1. Arte recebida', '2. Arte conferida', '3. Imprimindo',
|
||||
'4. Revisão', '5. Finalizado', 'Recibos', 'Revisões')
|
||||
|
||||
|
||||
def counts(c):
|
||||
return {table: c.execute(f'SELECT count(*) AS n FROM dtf_local.{table}').fetchone()['n']
|
||||
for table in TABLES + HISTORY}
|
||||
|
||||
|
||||
def clean_folders(root, dry_run=True):
|
||||
"""Empty the flow folders under `root`, recreating them; keep Estampas/."""
|
||||
root = Path(root)
|
||||
if not any((root / name).exists() for name in FLOW_FOLDERS):
|
||||
raise SystemExit(f'{root} does not look like the Kanban root: no flow folders found.')
|
||||
if dry_run:
|
||||
return [str(root / name) for name in FLOW_FOLDERS if (root / name).exists()]
|
||||
cleaned = []
|
||||
for name in FLOW_FOLDERS:
|
||||
path = root / name
|
||||
if path.is_dir():
|
||||
shutil.rmtree(path)
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
cleaned.append(str(path))
|
||||
return cleaned
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--root', type=Path, help='Kanban root folder (the one with 1. Arte recebida)')
|
||||
parser.add_argument('--yes', action='store_true', help='execute; without it, only report')
|
||||
parser.add_argument('--keep-files', action='store_true', help='leave the Kanban folders untouched')
|
||||
args = parser.parse_args(argv)
|
||||
dry = not args.yes
|
||||
with connect() as c:
|
||||
before = counts(c)
|
||||
if dry:
|
||||
print('DRY RUN — nothing was deleted.')
|
||||
for table, number in before.items():
|
||||
print(f' {table}: {number}')
|
||||
if args.root and not args.keep_files:
|
||||
print('Folders that would be emptied:')
|
||||
for folder in clean_folders(args.root, dry_run=True):
|
||||
print(f' {folder}')
|
||||
print('Run again with --yes to execute.')
|
||||
return
|
||||
for table in TABLES + HISTORY:
|
||||
c.execute(f'DELETE FROM dtf_local.{table}')
|
||||
c.execute('ANALYZE')
|
||||
after = counts(c)
|
||||
for table in TABLES + HISTORY:
|
||||
print(f'{table}: {before[table]} -> {after[table]}')
|
||||
if args.root and not args.keep_files:
|
||||
for folder in clean_folders(args.root, dry_run=False):
|
||||
print(f'emptied {folder}')
|
||||
print('Board wiped. Orders.number was not reset; the next card continues the sequence.')
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
32
tests/test_reset_board.py
Normal file
32
tests/test_reset_board.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""0.11 folder cleaning: empty the flow folders, keep the art library."""
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from ops.reset_board import FLOW_FOLDERS, clean_folders
|
||||
|
||||
|
||||
class ResetFoldersTests(unittest.TestCase):
|
||||
def test_empties_flow_folders_and_keeps_estampas(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
root = Path(folder)
|
||||
for name in FLOW_FOLDERS:
|
||||
(root / name).mkdir()
|
||||
(root / name / 'card.txt').write_text('x')
|
||||
library = root / 'Estampas'
|
||||
library.mkdir()
|
||||
(library / '1001.png').write_bytes(b'art')
|
||||
clean_folders(root, dry_run=False)
|
||||
for name in FLOW_FOLDERS:
|
||||
self.assertTrue((root / name).is_dir(), name)
|
||||
self.assertEqual(list((root / name).iterdir()), [], name)
|
||||
self.assertEqual((library / '1001.png').read_bytes(), b'art')
|
||||
|
||||
def test_refuses_a_folder_that_is_not_the_kanban_root(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
with self.assertRaises(SystemExit):
|
||||
clean_folders(folder, dry_run=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1436,6 +1436,10 @@ function contactNotice(order,canClear){
|
||||
box.append(ico,p);
|
||||
const zap=whatsappLink(order.snapshot.customer.zap);
|
||||
if(zap){const a=node('a','Abrir conversa','btn');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.prepend(svgIcon(IC.chat,'i s'));box.append(a);}
|
||||
// A proof order closes its contact wait with Prova OK, the only button
|
||||
// (item 0.1). Other orders still need a way to record that contact is done.
|
||||
if(canClear&&!needsProof(order))box.append(button('Contato feito',async()=>{
|
||||
await api('/orders/'+order.id+'/contact',{waiting:false});say('Contato registrado: a marca saiu do pedido #'+order.number+'.');await load();},'btn'));
|
||||
return box;
|
||||
}
|
||||
// In correction, the customer has to be told: a message ready to send on
|
||||
|
||||
Reference in New Issue
Block a user