updated devis to command logics transformation
This commit is contained in:
parent
6e8aa332ce
commit
02b6780d3f
1 changed files with 40 additions and 13 deletions
|
|
@ -1027,14 +1027,14 @@ class SageConnector:
|
||||||
def transformer_document(self, numero_source, type_source, type_cible):
|
def transformer_document(self, numero_source, type_source, type_cible):
|
||||||
"""
|
"""
|
||||||
Transformation avec transaction
|
Transformation avec transaction
|
||||||
✅ CORRIGÉ: Utilise CreateProcess_Document au lieu de CreateProcess_DocumentVente
|
✅ CORRIGÉ: Gestion du statut avant transformation
|
||||||
"""
|
"""
|
||||||
if not self.cial:
|
if not self.cial:
|
||||||
raise RuntimeError("Connexion Sage non établie")
|
raise RuntimeError("Connexion Sage non établie")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self._com_context(), self._lock_com:
|
with self._com_context(), self._lock_com:
|
||||||
# Lecture source
|
# ===== LECTURE SOURCE =====
|
||||||
factory = self.cial.FactoryDocumentVente
|
factory = self.cial.FactoryDocumentVente
|
||||||
persist_source = factory.ReadPiece(type_source, numero_source)
|
persist_source = factory.ReadPiece(type_source, numero_source)
|
||||||
|
|
||||||
|
|
@ -1044,6 +1044,31 @@ class SageConnector:
|
||||||
doc_source = win32com.client.CastTo(persist_source, "IBODocumentVente3")
|
doc_source = win32com.client.CastTo(persist_source, "IBODocumentVente3")
|
||||||
doc_source.Read()
|
doc_source.Read()
|
||||||
|
|
||||||
|
# ✅ VÉRIFICATION STATUT
|
||||||
|
statut_actuel = getattr(doc_source, "DO_Statut", 0)
|
||||||
|
logger.info(
|
||||||
|
f"📊 Statut actuel du document {numero_source}: {statut_actuel}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# ✅ BLOQUER SI DÉJÀ TRANSFORMÉ
|
||||||
|
if statut_actuel == 5:
|
||||||
|
raise ValueError(
|
||||||
|
f"❌ Le document {numero_source} a déjà été transformé (statut=5)"
|
||||||
|
)
|
||||||
|
|
||||||
|
# ✅ FORCER STATUT "ACCEPTÉ" (2) SI BROUILLON (0)
|
||||||
|
if type_source == 0 and statut_actuel == 0: # Devis brouillon
|
||||||
|
logger.warning(
|
||||||
|
f"⚠️ Devis {numero_source} en brouillon (statut=0), "
|
||||||
|
f"passage à 'Accepté' (statut=2)"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
doc_source.DO_Statut = 2 # Accepté
|
||||||
|
doc_source.Write()
|
||||||
|
logger.info(f"✅ Statut changé: 0 → 2")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Impossible de changer le statut: {e}")
|
||||||
|
|
||||||
# Récupérer le client
|
# Récupérer le client
|
||||||
client_code = ""
|
client_code = ""
|
||||||
try:
|
try:
|
||||||
|
|
@ -1059,7 +1084,7 @@ class SageConnector:
|
||||||
f"Impossible de récupérer le client du document {numero_source}"
|
f"Impossible de récupérer le client du document {numero_source}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Transaction
|
# ===== TRANSACTION =====
|
||||||
transaction_active = False
|
transaction_active = False
|
||||||
try:
|
try:
|
||||||
self.cial.CptaApplication.BeginTrans()
|
self.cial.CptaApplication.BeginTrans()
|
||||||
|
|
@ -1069,7 +1094,7 @@ class SageConnector:
|
||||||
logger.warning(f"⚠️ BeginTrans échoué: {e}")
|
logger.warning(f"⚠️ BeginTrans échoué: {e}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# ✅ CORRECTION: CreateProcess_Document (sans Vente)
|
# ✅ CRÉATION DOCUMENT CIBLE
|
||||||
process = self.cial.CreateProcess_Document(type_cible)
|
process = self.cial.CreateProcess_Document(type_cible)
|
||||||
doc_cible = process.Document
|
doc_cible = process.Document
|
||||||
|
|
||||||
|
|
@ -1110,7 +1135,7 @@ class SageConnector:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Copie lignes
|
# ===== COPIE LIGNES =====
|
||||||
try:
|
try:
|
||||||
factory_lignes_source = doc_source.FactoryDocumentLigne
|
factory_lignes_source = doc_source.FactoryDocumentLigne
|
||||||
factory_lignes_cible = doc_cible.FactoryDocumentLigne
|
factory_lignes_cible = doc_cible.FactoryDocumentLigne
|
||||||
|
|
@ -1216,7 +1241,7 @@ class SageConnector:
|
||||||
if index > 1000:
|
if index > 1000:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Validation
|
# ===== VALIDATION =====
|
||||||
doc_cible.Write()
|
doc_cible.Write()
|
||||||
process.Process()
|
process.Process()
|
||||||
|
|
||||||
|
|
@ -1230,17 +1255,19 @@ class SageConnector:
|
||||||
self.cial.CptaApplication.CommitTrans()
|
self.cial.CptaApplication.CommitTrans()
|
||||||
logger.info("✅ Transaction committée")
|
logger.info("✅ Transaction committée")
|
||||||
|
|
||||||
# MAJ statut source si transformation devis → commande
|
# ✅ MAJ STATUT SOURCE → TRANSFORMÉ (5)
|
||||||
try:
|
try:
|
||||||
if type_source == 0 and type_cible == 3:
|
doc_source.DO_Statut = 5 # Transformé
|
||||||
doc_source.DO_Statut = 5 # Transformé
|
doc_source.Write()
|
||||||
doc_source.Write()
|
logger.info(
|
||||||
logger.info(f"✅ Statut source mis à jour: TRANSFORMÉ (5)")
|
f"✅ Statut source mis à jour: {statut_actuel} → 5 (TRANSFORMÉ)"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Impossible de MAJ statut source: {e}")
|
logger.warning(f"⚠️ Impossible de MAJ statut source: {e}")
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"✅ Transformation: {numero_source} ({type_source}) → {numero_cible} ({type_cible})"
|
f"✅ Transformation: {numero_source} ({type_source}) → "
|
||||||
|
f"{numero_cible} ({type_cible}) - {nb_lignes} lignes"
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue