79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
from typing import Optional
|
|
from enum import Enum
|
|
from config import settings
|
|
|
|
|
|
class TypeDocumentVente(Enum):
|
|
"""Types de documents de vente supportés"""
|
|
|
|
DEVIS = 0
|
|
COMMANDE = 1
|
|
LIVRAISON = 3
|
|
FACTURE = 6
|
|
AVOIR = 5
|
|
|
|
|
|
class ConfigDocument:
|
|
"""Configuration spécifique pour chaque type de document"""
|
|
|
|
def __init__(self, type_doc: TypeDocumentVente):
|
|
self.type_doc = type_doc
|
|
self.type_sage = self._get_type_sage()
|
|
self.champ_date_principale = self._get_champ_date()
|
|
self.champ_numero = self._get_champ_numero()
|
|
self.nom_document = self._get_nom_document()
|
|
self.champ_date_secondaire = self._get_champ_date_secondaire()
|
|
|
|
def _get_type_sage(self) -> int:
|
|
mapping = {
|
|
TypeDocumentVente.DEVIS: settings.SAGE_TYPE_DEVIS,
|
|
TypeDocumentVente.COMMANDE: settings.SAGE_TYPE_BON_COMMANDE,
|
|
TypeDocumentVente.LIVRAISON: settings.SAGE_TYPE_BON_LIVRAISON,
|
|
TypeDocumentVente.FACTURE: settings.SAGE_TYPE_FACTURE,
|
|
TypeDocumentVente.AVOIR: settings.SAGE_TYPE_BON_AVOIR,
|
|
}
|
|
return mapping[self.type_doc]
|
|
|
|
def _get_champ_date(self) -> str:
|
|
"""Retourne le nom du champ principal dans les données"""
|
|
mapping = {
|
|
TypeDocumentVente.DEVIS: "date_devis",
|
|
TypeDocumentVente.COMMANDE: "date_commande",
|
|
TypeDocumentVente.LIVRAISON: "date_livraison",
|
|
TypeDocumentVente.FACTURE: "date_facture",
|
|
TypeDocumentVente.AVOIR: "date_avoir",
|
|
}
|
|
return mapping[self.type_doc]
|
|
|
|
def _get_champ_date_secondaire(self) -> Optional[str]:
|
|
"""Retourne le nom du champ secondaire (date de livraison, etc.)"""
|
|
mapping = {
|
|
TypeDocumentVente.DEVIS: "date_livraison",
|
|
TypeDocumentVente.COMMANDE: "date_livraison",
|
|
TypeDocumentVente.LIVRAISON: "date_livraison_prevue",
|
|
TypeDocumentVente.FACTURE: "date_livraison",
|
|
TypeDocumentVente.AVOIR: "date_livraison",
|
|
}
|
|
return mapping.get(self.type_doc)
|
|
|
|
def _get_champ_numero(self) -> str:
|
|
"""Retourne le nom du champ pour le numéro de document dans le résultat"""
|
|
mapping = {
|
|
TypeDocumentVente.DEVIS: "numero_devis",
|
|
TypeDocumentVente.COMMANDE: "numero_commande",
|
|
TypeDocumentVente.LIVRAISON: "numero_livraison",
|
|
TypeDocumentVente.FACTURE: "numero_facture",
|
|
TypeDocumentVente.AVOIR: "numero_avoir",
|
|
}
|
|
return mapping[self.type_doc]
|
|
|
|
def _get_nom_document(self) -> str:
|
|
"""Retourne le nom du document pour les logs"""
|
|
mapping = {
|
|
TypeDocumentVente.DEVIS: "devis",
|
|
TypeDocumentVente.COMMANDE: "commande",
|
|
TypeDocumentVente.LIVRAISON: "livraison",
|
|
TypeDocumentVente.FACTURE: "facture",
|
|
TypeDocumentVente.AVOIR: "avoir",
|
|
}
|
|
return mapping[self.type_doc]
|