95 lines
3.1 KiB
Python
95 lines
3.1 KiB
Python
from datetime import date
|
|
import uuid
|
|
from typing import Union
|
|
|
|
from .status import ProspectStatus
|
|
|
|
|
|
class Prospect:
|
|
def __init__(
|
|
self,
|
|
name: str,
|
|
company: str = "",
|
|
email: str = "",
|
|
phone: str = "",
|
|
source: str = "", # D'où vient ce prospect (site web, référence, etc.)
|
|
notes: str = "",
|
|
status: Union[ProspectStatus, str] = ProspectStatus.NOUVEAU, # Nouveau, Contacté, Qualifié, Proposition, Non intéressé
|
|
tags: list = None,
|
|
last_contact: str = None,
|
|
next_action: str = "",
|
|
linked_docs: dict = None,
|
|
id: str = None,
|
|
created_at: str = None,
|
|
score: int = 0,
|
|
last_interaction: str = None
|
|
):
|
|
self.id = id or f"pros_{uuid.uuid4().hex[:8]}"
|
|
self.name = name
|
|
self.company = company
|
|
self.email = email
|
|
self.phone = phone
|
|
self.source = source
|
|
self.notes = notes
|
|
# Stockage interne en Enum
|
|
self._status: ProspectStatus = ProspectStatus.from_value(status)
|
|
self.tags = tags or []
|
|
self.last_contact = last_contact or str(date.today())
|
|
self.next_action = next_action
|
|
self.linked_docs = linked_docs or {"propositions": []}
|
|
self.created_at = created_at or str(date.today())
|
|
self.score = score or 0
|
|
self.last_interaction = last_interaction
|
|
|
|
@property
|
|
def status(self) -> str:
|
|
"""Exposition publique du statut en chaîne pour compatibilité (templates, JSON)."""
|
|
return self._status.value
|
|
|
|
@status.setter
|
|
def status(self, value: Union[ProspectStatus, str]) -> None:
|
|
"""Permet d'assigner soit une chaîne, soit l'enum directement."""
|
|
self._status = ProspectStatus.from_value(value)
|
|
|
|
def to_dict(self):
|
|
return {
|
|
"id": self.id,
|
|
"name": self.name,
|
|
"company": self.company,
|
|
"email": self.email,
|
|
"phone": self.phone,
|
|
"source": self.source,
|
|
"notes": self.notes,
|
|
"status": self.status, # sérialise en chaîne
|
|
"tags": self.tags,
|
|
"last_contact": self.last_contact,
|
|
"next_action": self.next_action,
|
|
"linked_docs": self.linked_docs,
|
|
"created_at": self.created_at,
|
|
"score": self.score,
|
|
"last_interaction": self.last_interaction
|
|
}
|
|
|
|
@staticmethod
|
|
def from_dict(data: dict):
|
|
# __init__ gère la conversion status -> Enum
|
|
return Prospect(**data)
|
|
|
|
def convert_to_client(self):
|
|
"""Convertit ce prospect en client"""
|
|
from .client import Client
|
|
|
|
return Client(
|
|
name=self.name,
|
|
company=self.company,
|
|
email=self.email,
|
|
phone=self.phone,
|
|
notes=self.notes,
|
|
tags=self.tags,
|
|
last_contact=self.last_contact,
|
|
next_action=self.next_action,
|
|
linked_docs=self.linked_docs
|
|
)
|
|
|
|
def __str__(self):
|
|
return f"Prospect({self.name}, {self.company}, {self.status}, {self.email})"
|