feat(sage_connector): enhance document reading with client and article details
This commit is contained in:
parent
ae5fa9e0be
commit
cc56821c70
1 changed files with 32 additions and 7 deletions
|
|
@ -963,10 +963,7 @@ class SageConnector:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def lire_document(self, numero, type_doc):
|
def lire_document(self, numero, type_doc):
|
||||||
"""Lecture générique document (pour PDF)"""
|
"""Lecture générique document (pour PDF et lecture commandes/factures)"""
|
||||||
if type_doc == 0:
|
|
||||||
return self.lire_devis(numero)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self._com_context(), self._lock_com:
|
with self._com_context(), self._lock_com:
|
||||||
factory = self.cial.FactoryDocumentVente
|
factory = self.cial.FactoryDocumentVente
|
||||||
|
|
@ -978,6 +975,19 @@ class SageConnector:
|
||||||
doc = win32com.client.CastTo(persist, "IBODocumentVente3")
|
doc = win32com.client.CastTo(persist, "IBODocumentVente3")
|
||||||
doc.Read()
|
doc.Read()
|
||||||
|
|
||||||
|
# ✅ Charger client via .Client
|
||||||
|
client_code = ""
|
||||||
|
client_intitule = ""
|
||||||
|
|
||||||
|
try:
|
||||||
|
client_obj = getattr(doc, "Client", None)
|
||||||
|
if client_obj:
|
||||||
|
client_obj.Read()
|
||||||
|
client_code = getattr(client_obj, "CT_Num", "").strip()
|
||||||
|
client_intitule = getattr(client_obj, "CT_Intitule", "").strip()
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"Erreur chargement client: {e}")
|
||||||
|
|
||||||
# Lire lignes
|
# Lire lignes
|
||||||
lignes = []
|
lignes = []
|
||||||
try:
|
try:
|
||||||
|
|
@ -995,8 +1005,21 @@ class SageConnector:
|
||||||
ligne = win32com.client.CastTo(ligne_p, "IBODocumentLigne3")
|
ligne = win32com.client.CastTo(ligne_p, "IBODocumentLigne3")
|
||||||
ligne.Read()
|
ligne.Read()
|
||||||
|
|
||||||
|
# ✅ Charger article via .Article
|
||||||
|
article_ref = ""
|
||||||
|
try:
|
||||||
|
article_ref = getattr(ligne, "AR_Ref", "").strip()
|
||||||
|
if not article_ref:
|
||||||
|
article_obj = getattr(ligne, "Article", None)
|
||||||
|
if article_obj:
|
||||||
|
article_obj.Read()
|
||||||
|
article_ref = getattr(article_obj, "AR_Ref", "").strip()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
lignes.append(
|
lignes.append(
|
||||||
{
|
{
|
||||||
|
"article": article_ref, # ✅ Ajout référence article
|
||||||
"designation": getattr(ligne, "DL_Design", ""),
|
"designation": getattr(ligne, "DL_Design", ""),
|
||||||
"quantite": getattr(ligne, "DL_Qte", 0.0),
|
"quantite": getattr(ligne, "DL_Qte", 0.0),
|
||||||
"prix_unitaire": getattr(ligne, "DL_PrixUnitaire", 0.0),
|
"prix_unitaire": getattr(ligne, "DL_PrixUnitaire", 0.0),
|
||||||
|
|
@ -1010,15 +1033,17 @@ class SageConnector:
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"numero": getattr(doc, "DO_Piece", ""),
|
"numero": getattr(doc, "DO_Piece", ""),
|
||||||
|
"reference": getattr(doc, "DO_Ref", ""), # ✅ Ajout référence
|
||||||
"date": str(getattr(doc, "DO_Date", "")),
|
"date": str(getattr(doc, "DO_Date", "")),
|
||||||
"client_code": getattr(doc, "CT_Num", ""),
|
"client_code": client_code,
|
||||||
"client_intitule": getattr(doc, "CT_Intitule", ""),
|
"client_intitule": client_intitule,
|
||||||
"total_ht": getattr(doc, "DO_TotalHT", 0.0),
|
"total_ht": getattr(doc, "DO_TotalHT", 0.0),
|
||||||
"total_ttc": getattr(doc, "DO_TotalTTC", 0.0),
|
"total_ttc": getattr(doc, "DO_TotalTTC", 0.0),
|
||||||
|
"statut": getattr(doc, "DO_Statut", 0), # ✅ Ajout statut
|
||||||
"lignes": lignes,
|
"lignes": lignes,
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f" Erreur lecture document: {e}")
|
logger.error(f"❌ Erreur lecture document: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# =========================================================================
|
# =========================================================================
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue