feat: add operational eligibility and scheduled follow-up
This commit is contained in:
@@ -183,6 +183,7 @@ STAGE_ON_TASK_DONE = {
|
||||
_SCHEMA_READY = False
|
||||
|
||||
FOLLOW_UP_ACTION_CODES = {
|
||||
"CALL_CUSTOMER",
|
||||
"FOLLOW_UP_QUOTE",
|
||||
"FOLLOW_UP_PROFORMA",
|
||||
"FOLLOW_UP_PAYMENT",
|
||||
@@ -198,6 +199,7 @@ OPPORTUNITY_LIFECYCLE_STATES = {
|
||||
"active": "Ativa",
|
||||
"awaiting_customer": "A aguardar cliente",
|
||||
"follow_up_due": "Follow-up vencido",
|
||||
"scheduled_follow_up": "Contacto agendado",
|
||||
"recovery": "Recuperação",
|
||||
"nurture": "Acompanhamento futuro",
|
||||
}
|
||||
@@ -1577,15 +1579,21 @@ def list_opportunities(
|
||||
(
|
||||
SELECT t.action_code FROM tasks t
|
||||
WHERE t.opportunity_id = o.id AND t.status = 'pending'
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CALL_CUSTOMER','CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
ORDER BY t.due_at NULLS LAST, t.created_at DESC LIMIT 1
|
||||
) AS pending_follow_up_action_code,
|
||||
(
|
||||
SELECT t.action FROM tasks t
|
||||
WHERE t.opportunity_id = o.id AND t.status = 'pending'
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CALL_CUSTOMER','CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
ORDER BY t.due_at NULLS LAST, t.created_at DESC LIMIT 1
|
||||
) AS pending_follow_up_action
|
||||
) AS pending_follow_up_action,
|
||||
(
|
||||
SELECT t.due_at FROM tasks t
|
||||
WHERE t.opportunity_id = o.id AND t.status = 'pending'
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CALL_CUSTOMER','CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
ORDER BY t.due_at NULLS LAST, t.created_at DESC LIMIT 1
|
||||
) AS pending_follow_up_due_at
|
||||
FROM opportunities o
|
||||
LEFT JOIN customers c ON c.id = o.local_customer_id
|
||||
{where_sql}
|
||||
@@ -1643,15 +1651,21 @@ def get_opportunity(opportunity_id: str) -> Optional[Dict[str, Any]]:
|
||||
(
|
||||
SELECT t.action_code FROM tasks t
|
||||
WHERE t.opportunity_id = o.id AND t.status = 'pending'
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CALL_CUSTOMER','CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
ORDER BY t.due_at NULLS LAST, t.created_at DESC LIMIT 1
|
||||
) AS pending_follow_up_action_code,
|
||||
(
|
||||
SELECT t.action FROM tasks t
|
||||
WHERE t.opportunity_id = o.id AND t.status = 'pending'
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CALL_CUSTOMER','CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
ORDER BY t.due_at NULLS LAST, t.created_at DESC LIMIT 1
|
||||
) AS pending_follow_up_action
|
||||
) AS pending_follow_up_action,
|
||||
(
|
||||
SELECT t.due_at FROM tasks t
|
||||
WHERE t.opportunity_id = o.id AND t.status = 'pending'
|
||||
AND (t.action_code LIKE 'FOLLOW_UP_%' OR t.action_code IN ('CALL_CUSTOMER','CONFIRM_DELIVERY','RECOVER_OPPORTUNITY','REVIEW_NURTURE'))
|
||||
ORDER BY t.due_at NULLS LAST, t.created_at DESC LIMIT 1
|
||||
) AS pending_follow_up_due_at
|
||||
FROM opportunities o
|
||||
LEFT JOIN customers c ON c.id = o.local_customer_id
|
||||
WHERE o.id = CAST(:opportunity_id AS UUID)
|
||||
|
||||
Reference in New Issue
Block a user