feat: an order can be marked "Aguardando contato" until the customer is reached
All checks were successful
Build and deploy / Validate source (push) Successful in 16s
Build and deploy / Integration suite on a real stack (push) Successful in 4m8s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m7s
All checks were successful
Build and deploy / Validate source (push) Successful in 16s
Build and deploy / Integration suite on a real stack (push) Successful in 4m8s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m7s
The 7 October meeting asked for a way to flag orders whose file needs a word with the customer before printing: rename Arte tratada, or tag the card. A tag keeps the stage meaning "file checked" and the order where it is in the queue. In the order panel, "☎ Aguardando contato" asks what has to be agreed; the card then shows the mark, the board has an "Aguardando contato" filter, and the panel shows the note, who marked it and when, the customer's WhatsApp and "Contato feito", which clears it. The customer is not told. Sellers see the mark but cannot set it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response
|
||||
from fastapi.responses import RedirectResponse
|
||||
from pydantic import Field
|
||||
|
||||
from ..core import db
|
||||
from ..core.auth import (COOKIE_SECURE, DUMMY_PASSWORD_HASH, audit, can, client_ip, operator,
|
||||
@@ -514,6 +515,30 @@ def choose_machine(uid: UUID, body: MachineChoice, user=Depends(can('produce')))
|
||||
return {'ok': True}
|
||||
|
||||
|
||||
class ContactWait(StrictModel):
|
||||
waiting: bool
|
||||
note: str = Field(default='', max_length=500)
|
||||
|
||||
|
||||
@router.post('/api/operator/orders/{uid}/contact')
|
||||
def contact(uid: UUID, body: ContactWait, user=Depends(can('produce'))):
|
||||
"""Mark an order as waiting for a word with the customer, with what has to
|
||||
be agreed, or clear the mark once that is done. The stage does not change
|
||||
and the customer is not told."""
|
||||
note = ' '.join(body.note.split())
|
||||
if body.waiting and len(note) < 3:
|
||||
raise HTTPException(422, 'Escreva o que precisa ser combinado com o cliente.')
|
||||
with db.connect() as c:
|
||||
row = c.execute('''UPDATE dtf_local.orders SET contact_since=CASE WHEN %s THEN now() END,
|
||||
contact_by=CASE WHEN %s THEN %s END, contact_note=CASE WHEN %s THEN %s END
|
||||
WHERE id=%s AND cancelled_at IS NULL RETURNING number''',
|
||||
(body.waiting, body.waiting, user, body.waiting, note, uid)).fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, 'Pedido não encontrado.')
|
||||
audit('order_contact_waiting' if body.waiting else 'order_contact_done', order=row['number'], operator=user)
|
||||
return {'ok': True}
|
||||
|
||||
|
||||
class QueuePlace(StrictModel):
|
||||
"""Where a dragged card lands: between two orders of its column, either
|
||||
of them absent at the top or the bottom."""
|
||||
|
||||
@@ -276,3 +276,9 @@ CREATE TABLE IF NOT EXISTS dtf_local.password_resets (
|
||||
CREATE INDEX IF NOT EXISTS password_resets_account ON dtf_local.password_resets(account_id);
|
||||
-- Kanban users who get the team's alerts by e-mail.
|
||||
ALTER TABLE dtf_local.operators ADD COLUMN IF NOT EXISTS alerts boolean NOT NULL DEFAULT false;
|
||||
|
||||
-- "Aguardando contato": an order whose file needs a word with the customer
|
||||
-- before printing. A mark on the card, not a stage: the order stays where it is.
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS contact_since timestamptz;
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS contact_by text;
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS contact_note text;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""Discarding an unpaid quote, deleting a test order, cancelling a paid one.
|
||||
"""Discarding an unpaid quote, deleting a test order, marking an order as waiting
|
||||
for contact, cancelling a paid one.
|
||||
|
||||
Run inside the API container: python -m tests.order_actions_test
|
||||
"""
|
||||
@@ -52,6 +53,17 @@ def run():
|
||||
test_order = None
|
||||
assert str(test_quote) in listed()
|
||||
|
||||
# "Aguardando contato": a mark with what to agree, on the board until cleared.
|
||||
client.call(f'/operator/orders/{paid_order}/contact', {'waiting': True, 'note': ' '}, operator=True, expected=422)
|
||||
client.call(f'/operator/orders/{paid_order}/contact', {'waiting': True, 'note': 'Confirmar a cor do fundo'},
|
||||
operator=True)
|
||||
marked = {o['id']: o for o in client.call('/operator/board', operator=True)['orders']}[str(paid_order)]
|
||||
assert marked['contact_note'] == 'Confirmar a cor do fundo' and marked['contact_since'], marked
|
||||
assert marked['contact_by'] and marked['state'] == 'rec'
|
||||
client.call(f'/operator/orders/{paid_order}/contact', {'waiting': False}, operator=True)
|
||||
cleared = {o['id']: o for o in client.call('/operator/board', operator=True)['orders']}[str(paid_order)]
|
||||
assert cleared['contact_since'] is None and cleared['contact_note'] is None
|
||||
|
||||
# A paid order is cancelled with a reason, kept, and can no longer move.
|
||||
# A paid order in progress is not deleted: it is cancelled first.
|
||||
client.call(f'/operator/orders/{paid_order}/delete', {}, operator=True, expected=409)
|
||||
|
||||
@@ -88,6 +88,7 @@ def run():
|
||||
seller.call(f'/operator/orders/{textil_o}/move', {'state': 'tra', 'version': 1, 'reason': ''}, expected=403)
|
||||
seller.call(f'/operator/quotes/{uv_q}/discard', {}, expected=403)
|
||||
seller.call(f'/operator/orders/{textil_o}/machine', {'machine_id': None}, expected=403)
|
||||
seller.call(f'/operator/orders/{textil_o}/contact', {'waiting': True, 'note': 'Ligar'}, expected=403)
|
||||
assert seller.call('/operator/me')['can'] == ['view']
|
||||
# Their own password: the current one is asked for.
|
||||
seller.call('/operator/me/password', {'current': 'errada', 'new': 'outra-senha-de-teste'}, expected=403)
|
||||
|
||||
@@ -389,6 +389,8 @@ a.zap{display:inline-flex;align-items:center;gap:4px;vertical-align:bottom}
|
||||
.callout{display:flex;flex-direction:column;gap:3px;padding:10px 12px;border-radius:9px;background:rgba(242,179,61,.1)}
|
||||
.callout b{font-size:13.5px;color:var(--warn)}
|
||||
.callout span{font-size:13px;color:var(--tx2)}
|
||||
.callout span.faint{color:var(--faint)}
|
||||
.callout .buttons{margin-top:6px;align-items:center}
|
||||
|
||||
/* Order panel */
|
||||
.paidline{display:flex;align-items:baseline;flex-wrap:wrap;gap:8px;font-size:14px;color:var(--muted)}
|
||||
@@ -410,7 +412,7 @@ a.zap{display:inline-flex;align-items:center;gap:4px;vertical-align:bottom}
|
||||
.readyfile b{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13.5px}
|
||||
.stepactions{display:flex;gap:10px;margin-top:12px;flex-wrap:wrap}
|
||||
.btn.small{height:30px;padding:0 10px;font-size:13px}
|
||||
.subactions{display:flex;margin-top:-4px}
|
||||
.subactions{display:flex;flex-wrap:wrap;gap:4px 18px;margin-top:-4px}
|
||||
.timeline li{display:flex;align-items:baseline;gap:10px;font-size:14px}
|
||||
.timeline li div{flex:1;min-width:0}
|
||||
.timeline small{flex-shrink:0;color:var(--faint);font-size:13px}
|
||||
|
||||
@@ -475,6 +475,10 @@ function printState(order){
|
||||
return {text:'Sem arquivo gerado',tone:'warn'};
|
||||
}
|
||||
const stalled=order=>['rec','tra','fil','imp'].includes(order.state)&&Date.now()-new Date(order.updated_at)>LATE_HOURS*3600000;
|
||||
// "Aguardando contato": a word with the customer is needed before printing.
|
||||
// A mark on the card, not a stage; a finished order no longer needs it.
|
||||
const waitingContact=order=>!!order.contact_since&&!order.cancelled_at&&order.state!=='fin';
|
||||
const contactWho=order=>(order.contact_by||'')+' em '+when(order.contact_since);
|
||||
function matchesFilter(order,key){
|
||||
// A cancelled order shows only under "Cancelados", and only there.
|
||||
if(key==='cancelados')return !!order.cancelled_at;
|
||||
@@ -485,6 +489,7 @@ function matchesFilter(order,key){
|
||||
if(key==='entrega')return !!order.snapshot.destination;
|
||||
if(key==='retirada')return !order.snapshot.destination;
|
||||
if(key==='parados')return stalled(order);
|
||||
if(key==='contato')return waitingContact(order);
|
||||
if(key==='manual')return ['rec','tra'].includes(order.state)&&!finalDone(order)&&(order.print_files||[]).some(r=>
|
||||
(r.status==='manual'||r.status==='failed')&&!(order.corrections||[]).some(f=>f.item_index===r.item_index));
|
||||
return true;
|
||||
@@ -492,7 +497,7 @@ function matchesFilter(order,key){
|
||||
const matches=order=>matchesFilter(order,filter);
|
||||
function renderBoard(){
|
||||
const filters=[['all','Todos'],['textil','Têxtil'],['uv','UV'],['entrega','Entrega'],['retirada','Retirada'],
|
||||
['parados','Parados'],['manual','Preparar à mão'],['cancelados','Cancelados']];
|
||||
['parados','Parados'],['contato','Aguardando contato'],['manual','Preparar à mão'],['cancelados','Cancelados']];
|
||||
// Each chip says how many orders in progress it would show.
|
||||
const inProgress=board.orders.filter(o=>o.state!=='fin'&&!o.cancelled_at);
|
||||
$('filters').replaceChildren(...filters.map(([key,label])=>{
|
||||
@@ -563,6 +568,7 @@ function card(order){
|
||||
flags.append(badge((p.tone==='ok'?'✓ ':p.tone==='warn'?'! ':'')+p.text,p.tone));
|
||||
if(s.items.some(i=>i.quality_status==='warning'))flags.append(badge('! Ressalva','warn','O cliente aceitou a ressalva de resolução'));
|
||||
if(stalled(order))flags.append(badge('⏱ Parado '+hoursSince(order.updated_at)+' h','bad','Sem mudar de etapa desde '+when(order.updated_at)));
|
||||
if(waitingContact(order))flags.append(badge('☎ Aguardando contato','warn',order.contact_note+' · '+contactWho(order)));
|
||||
}
|
||||
c.append(artBox(s.items,'card-art'),top,buyerBlock(s,'cust'),meta,place(s.destination));
|
||||
if(order.machine&&order.state!=='fin'){const m=node('div',undefined,'place machine');m.append(icon(ICON_PRINTER),order.machine.name);c.append(m);}
|
||||
@@ -694,6 +700,7 @@ function moves(order){
|
||||
if(!may('produce')){
|
||||
// Sellers read the order; a correction's notice is theirs to send too.
|
||||
if(order.state==='cor'&&!order.cancelled_at)box.append(correctionNotice(order));
|
||||
if(waitingContact(order))box.append(contactNotice(order,false));
|
||||
box.append(node('p',order.cancelled_at?'Pedido cancelado.':'Somente consulta: seu perfil não move pedidos.','muted'));
|
||||
return box;
|
||||
}
|
||||
@@ -762,6 +769,20 @@ function moves(order){
|
||||
backForm.append(why,go);
|
||||
backForm.onsubmit=async e=>{e.preventDefault();go.disabled=true;try{await move(order,previous,why.value.trim());}catch(error){say(error.message,true);go.disabled=false;}};
|
||||
}
|
||||
// Waiting for a word with the customer: shown on top with "Contato feito";
|
||||
// otherwise marked from here, with what has to be agreed.
|
||||
const contactForm=node('form',undefined,'reason');contactForm.hidden=true;forms.push(contactForm);
|
||||
if(order.state!=='fin'&&!waitingContact(order)){
|
||||
const b=node('button','☎ Aguardando contato','linkbtn');b.type='button';b.dataset.contact='';
|
||||
b.title='Marcar que é preciso falar com o cliente antes de imprimir';b.onclick=()=>toggle(contactForm);sub.append(b);
|
||||
const what=node('input');what.placeholder='O que precisa ser combinado com o cliente';what.setAttribute('aria-label','O que precisa ser combinado');
|
||||
what.required=true;what.minLength=3;what.maxLength=500;
|
||||
const go=node('button','Marcar aguardando contato','btn');
|
||||
contactForm.append(what,go);
|
||||
contactForm.onsubmit=async e=>{e.preventDefault();go.disabled=true;
|
||||
try{await api('/orders/'+order.id+'/contact',{waiting:true,note:what.value.trim()});say('Pedido #'+order.number+' aguardando contato.');await load();}
|
||||
catch(error){say(error.message,true);go.disabled=false;}};
|
||||
}
|
||||
// Rare and destructive: behind a menu. A test order is deleted; a paid one
|
||||
// is cancelled, with a reason, and kept.
|
||||
const cancelForm=node('form',undefined,'reason');cancelForm.hidden=true;forms.push(cancelForm);
|
||||
@@ -791,7 +812,19 @@ function moves(order){
|
||||
const sendFix=node('button','Enviar para correção','btn danger');
|
||||
reason.append(text,sendFix);
|
||||
reason.onsubmit=async e=>{e.preventDefault();sendFix.disabled=true;try{await move(order,'cor',text.value.trim());}catch(error){say(error.message,true);sendFix.disabled=false;}};
|
||||
box.append(...(waiting?[waiting]:[]),...(step?[step]:[]),row,...(sub.children.length?[sub]:[]),...forms.filter(f=>!f.parentNode));return box;
|
||||
const contactNow=waitingContact(order)?contactNotice(order,true):null;
|
||||
box.append(...(waiting?[waiting]:[]),...(contactNow?[contactNow]:[]),...(step?[step]:[]),row,...(sub.children.length?[sub]:[]),...forms.filter(f=>!f.parentNode));return box;
|
||||
}
|
||||
function contactNotice(order,canClear){
|
||||
const box=node('div',undefined,'callout contact');
|
||||
box.append(node('b','☎ Aguardando contato com o cliente'),node('span',order.contact_note),node('span',contactWho(order),'faint'));
|
||||
const actions=node('div',undefined,'buttons');
|
||||
const zap=whatsappLink(order.snapshot.customer.zap);
|
||||
if(zap){const a=node('a','Abrir conversa','zapbtn');a.href=zap;a.target='_blank';a.rel='noopener noreferrer';a.prepend(icon(ICON_CHAT));actions.append(a);}
|
||||
if(canClear)actions.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 small'));
|
||||
if(actions.children.length)box.append(actions);
|
||||
return box;
|
||||
}
|
||||
function correctionNotice(order){
|
||||
const s=order.snapshot, reason=order.correction_reason||'';
|
||||
|
||||
Reference in New Issue
Block a user