feat: an order in correction offers the customer's WhatsApp with the message written
Customers are not told automatically that their artwork needs a fix: Tiny has no situação for it. An order in Correção now opens with the reason and "Avisar no WhatsApp", which opens the customer's chat with the message ready: the order code, the reason and the link to send the new file in Minha conta. "Copiar mensagem" covers orders without a WhatsApp number. The board carries each corrected order's last reason and the Site's address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,8 +17,8 @@ from ..core.models import Move, OperatorLogin, Resolution, Review, StrictModel
|
||||
from ..printjobs import queue as queue_print_files
|
||||
from .. import payments, quote_review
|
||||
from .. import tiny
|
||||
from ..runtime import (BACK, BOARD_FINISHED_LIMIT, BOARD_QUOTE_LIMIT, ENVIRONMENT, STATES, TRANSITIONS, payment,
|
||||
enqueue, freight, quote_view, storage)
|
||||
from ..runtime import (BACK, BOARD_FINISHED_LIMIT, BOARD_QUOTE_LIMIT, ENVIRONMENT, PUBLIC_ORIGIN, STATES,
|
||||
TRANSITIONS, payment, enqueue, freight, quote_view, storage)
|
||||
from ..scanning import require_clean
|
||||
|
||||
router = APIRouter()
|
||||
@@ -122,7 +122,7 @@ def board(user=Depends(operator)):
|
||||
quotes = [quote_view(c, q) for q in pending + approved]
|
||||
return {'states': STATES, 'transitions': TRANSITIONS, 'back': BACK,
|
||||
'orders': orders, 'payment_issues_total': issues_total, 'tiny': tiny_status(), 'operator': user,
|
||||
'providers': {'payment': payment.name, 'freight': freight_status(), 'backup': backup}, 'environment': ENVIRONMENT,
|
||||
'providers': {'payment': payment.name, 'freight': freight_status(), 'backup': backup}, 'environment': ENVIRONMENT, 'site_origin': PUBLIC_ORIGIN,
|
||||
'finished_shown': len(finished), 'finished_total': finished_total,
|
||||
'quotes': quotes, 'thumbnails': thumbnails(c, orders, quotes),
|
||||
'pending_total': pending_total, 'approved_total': approved_total}
|
||||
@@ -168,7 +168,11 @@ def with_print_files(c, orders):
|
||||
(u.expires_at<=now() OR u.purged_at IS NOT NULL) AS expired FROM dtf_local.order_files f
|
||||
JOIN dtf_local.uploads u ON u.id=f.upload_id
|
||||
WHERE f.order_id=ANY(%s) AND f.kind='correction' AND f.active ORDER BY f.item_index''', (ids,)).fetchall()
|
||||
# Why each order was last sent to correction, for the notice to the customer.
|
||||
reasons = {row['order_id']: row['reason'] for row in c.execute('''SELECT DISTINCT ON (order_id) order_id,reason
|
||||
FROM dtf_local.movements WHERE order_id=ANY(%s) AND to_state='cor' ORDER BY order_id,id DESC''', (ids,)).fetchall()}
|
||||
for order in orders:
|
||||
order['correction_reason'] = reasons.get(order['id']) if order['state'] == 'cor' else None
|
||||
order['print_files'] = [row for row in generated if row['order_id'] == order['id']]
|
||||
order['final_items'] = sorted(row['item_index'] for row in finals if row['order_id'] == order['id'])
|
||||
order['corrections'] = [{k: row[k] for k in ('item_index', 'upload_id', 'name', 'expired')}
|
||||
|
||||
@@ -329,6 +329,7 @@ a.zap{display:inline-flex;align-items:center;gap:4px;vertical-align:bottom}
|
||||
.copy:hover{color:var(--tx);border-color:var(--line3)}
|
||||
.zapbtn{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px;border-radius:7px;background:rgba(111,209,156,.1);color:var(--ok);text-decoration:none;font-size:13px;font-weight:600}
|
||||
.zapbtn:hover{background:rgba(111,209,156,.18)}
|
||||
.zapbtn.big{height:36px;padding:0 14px;font-size:14px;border-radius:8px}
|
||||
|
||||
/* Facts: small labelled boxes */
|
||||
.factgrid{margin:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:6px}
|
||||
|
||||
@@ -490,6 +490,9 @@ function moves(order){
|
||||
},'btn danger');remove.style.alignSelf='flex-start';
|
||||
box.append(note,remove);return box;
|
||||
}
|
||||
// In correction, the customer has to be told: a message ready to send on
|
||||
// WhatsApp with the reason and where to send the new file.
|
||||
const waiting=order.state==='cor'?correctionNotice(order):null;
|
||||
const row=node('div',undefined,'moves');
|
||||
// One form open at a time under the buttons.
|
||||
const forms=[];
|
||||
@@ -572,7 +575,26 @@ 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(...(step?[step]:[]),row,...(sub.children.length?[sub]:[]),...forms.filter(f=>!f.parentNode));return box;
|
||||
box.append(...(waiting?[waiting]:[]),...(step?[step]:[]),row,...(sub.children.length?[sub]:[]),...forms.filter(f=>!f.parentNode));return box;
|
||||
}
|
||||
function correctionNotice(order){
|
||||
const s=order.snapshot, reason=order.correction_reason||'';
|
||||
const link=board.site_origin+'/conta/pedidos?order='+order.id;
|
||||
const message='Olá! Aqui é da Dropstar. O seu pedido '+orderCode(order.id)+' precisa de um ajuste na arte antes da impressão'+
|
||||
(reason?': '+reason:'.')+'\n\nEnvie o arquivo corrigido por aqui: '+link;
|
||||
const text=node('div');
|
||||
text.append(node('b','Aguardando a correção do cliente'),node('span',reason?'Motivo: '+reason:'O motivo está no histórico.'));
|
||||
const actions=node('div',undefined,'stepactions');
|
||||
const zap=whatsappLink(s.customer.zap);
|
||||
if(zap){
|
||||
const a=node('a','Avisar no WhatsApp','zapbtn big');a.href=zap+'?text='+encodeURIComponent(message);
|
||||
a.target='_blank';a.rel='noopener noreferrer';a.prepend(icon(ICON_CHAT));actions.append(a);
|
||||
}
|
||||
const copy=button('Copiar mensagem',async()=>{await navigator.clipboard.writeText(message);say('Mensagem copiada.');},'btn ghost');
|
||||
actions.append(copy);
|
||||
text.append(actions);
|
||||
if(!zap)text.append(node('span','Sem WhatsApp no pedido: envie a mensagem para '+s.customer.mail+'.'));
|
||||
const box=node('div',undefined,'nextstep lead');box.append(node('span','!','nextmark'),text);return box;
|
||||
}
|
||||
// ---- Final files: the file each item is printed from, approved by an operator.
|
||||
const finalDone=order=>order.snapshot.items.every((_,index)=>(order.final_items||[]).includes(index));
|
||||
|
||||
Reference in New Issue
Block a user