first commit
This commit is contained in:
commit
e6c52820cd
227 changed files with 16156 additions and 0 deletions
52
modules/crm/scoring.py
Normal file
52
modules/crm/scoring.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
from datetime import date
|
||||
from typing import Literal
|
||||
|
||||
from modules.crm.prospect_handler import ProspectHandler
|
||||
|
||||
|
||||
def categorize(score: int) -> Literal["Froid", "Tiède", "Chaud"]:
|
||||
if score is None:
|
||||
score = 0
|
||||
if score >= 50:
|
||||
return "Chaud"
|
||||
if score >= 20:
|
||||
return "Tiède"
|
||||
return "Froid"
|
||||
|
||||
|
||||
def adjust_score(prospect_id: str, delta: int) -> int:
|
||||
"""
|
||||
Ajuste le score d'un prospect et met à jour la dernière interaction.
|
||||
Retourne le score à jour.
|
||||
"""
|
||||
handler = ProspectHandler()
|
||||
p = handler.get_prospect_by_id(prospect_id)
|
||||
if not p:
|
||||
return 0
|
||||
try:
|
||||
current = int(getattr(p, "score", 0) or 0)
|
||||
except Exception:
|
||||
current = 0
|
||||
new_score = max(0, current + int(delta))
|
||||
setattr(p, "score", new_score)
|
||||
setattr(p, "last_interaction", date.today().isoformat())
|
||||
# On ne change pas le statut ici, sauf règle spécifique (reply)
|
||||
handler.update_prospect(p)
|
||||
return new_score
|
||||
|
||||
|
||||
def adjust_score_for_event(prospect_id: str, event: Literal["open", "click", "reply"]) -> int:
|
||||
if event == "open":
|
||||
return adjust_score(prospect_id, 10)
|
||||
if event == "click":
|
||||
return adjust_score(prospect_id, 20)
|
||||
if event == "reply":
|
||||
score = adjust_score(prospect_id, 30)
|
||||
# Règle: un reply passe le prospect en statut "Chaud"
|
||||
handler = ProspectHandler()
|
||||
p = handler.get_prospect_by_id(prospect_id)
|
||||
if p:
|
||||
p.status = "Chaud"
|
||||
handler.update_prospect(p)
|
||||
return score
|
||||
return adjust_score(prospect_id, 0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue