+
    hwÚid  ã                   ó‚   € R t ^ RIt^ RIHt ^ RIHt ^RIHtHtH	t	 ^RI
Ht ]P                  ! ]4      t ! R R4      tR# )zÍ
Orchestrateur principal de la fiscalisation.

Ce module choisit le canal fiscal, prepare le payload unique, gere le fallback
technique et applique les elements de securite retournes par la DGI ou le MCF.
N)ÚEmcfAdapter)Ú
MCFAdapter)ÚFiscalBusinessErrorÚFiscalFallbackRequiredÚFiscalTechnicalError)ÚFiscalPayloadBuilderc                   óX   a € ] tR t^t o RtR]R]/tRR ltR t	R t
R tR	 tR
 tRtV tR# )ÚFiscalOrchestratorzË
Point de decision fiscal central.

Il prepare la facture une seule fois, choisit un seul canal final,
gere le fallback technique, puis applique les elements de securite
uniquement apres un succes reel.
ÚEMCFÚMCFNc                óØ  € \        VR7      P                  V4      pVR,          pVR,          p V P                  WaV4      pT P                  TTR,          TR,          \        TP                  R4      4      R	7       R
RRTR,          RTP                  RTP                  RTR,          RTR,          /#   \         d    h \         d!   pT P                  TTTTTR7      p Rp?L£Rp?ii ; i)zç
Lance la fiscalisation complete d'une commande.

Le flux suit toujours la meme sequence :
1. preparation des donnees ;
2. choix du canal principal ;
3. fallback technique eventuel ;
4. application finale des elements de securite.
)Úfiscal_transaction_idÚpolicyÚprimary_channel)ÚcommandeÚprepared_payloadr   Úallow_fallbackÚprimary_errorNÚchannelÚsecurityÚrequire_security_before_save)r   r   r   Úrequire_securityÚsuccessTÚcommande_idÚcommande_numeror   )r   ÚbuildÚ_call_channelr   r   Ú_handle_technical_failureÚ_apply_security_elementsÚboolÚgetÚpkÚnumero)	Úselfr   r   r   r   r   r   Úresultr   s	   &&&&     ÚAD:\ProjetDjango\FacControl_1.3\facturation\fiscal_orchestrator.pyÚfiscalize_commandeÚ%FiscalOrchestrator.fiscalize_commande'   s  € ô 0ÐF[Ô\×bÑbÐckÓlÐØ! (Õ+ˆØ Ð!2Õ3ˆð	Ø×'Ñ'¨ÐCSÓTˆFð 	×%Ñ%ØØ˜9Õ%Ø˜JÕ'Ü! &§*¡*Ð-KÓ"LÓMð	 	&ô 	
ð �tØ�v˜iÕ(Ø˜8Ÿ;™;Ø˜xŸ™Ø#Ð%5Ð6MÕ%NØ˜˜zÕ*ð
ð 	
øô) #ô 	àÜ#ô 	Ø×3Ñ3Ø!Ø!1Ø /Ø-Ø+ð 4ó �Fûð	ús   ¯B3 Â3C)ÃC)Ã	C$Ã$C)c                óî   € V P                   P                  V4      pV'       g   \        RV 24      hV! 4       p\        P	                  RVVR,          R,          VR,          4       VP                  W#4      # )zHInstancie l'adaptateur du canal cible puis lui remet le payload prepare.zCanal fiscal inconnu: z1Tentative de fiscalisation via %s pour %s (tx=%s)r   r"   r   )ÚADAPTERSr    r   ÚloggerÚinfoÚ	fiscalize)r#   r   r   r   Úadapter_classÚadapters   &&&&  r%   r   Ú FiscalOrchestrator._call_channelT   sn   € àŸ™×)Ñ)¨'Ó2ˆßÜ%Ð(>¸w¸iÐ&HÓIÐIá“/ˆÜ�‰Ø?ØØ˜ZÕ(¨Õ2ØÐ4Õ5ô		
ð × Ñ  Ó<Ð<ó    c                óL  € V P                  V4      pVR,          R,          pVR8X  d   VhVR8X  d/   V'       g'   \        V P                  W64      VR,          VVR7      Vh V P                  WaV4      #   \         d    h \
         d   p\        \        T4      4      ThRp?ii ; i)zLGere la politique de fallback quand le canal principal echoue techniquement.r   Úfallback_modeÚDISABLEDÚASK_USERr   )r   r   Úfallback_channelN)Ú_get_fallback_channelr   Ú_build_prompt_messager   r   r   Ústr)	r#   r   r   r   r   r   r5   r2   Úfallback_errors	   &&&&&&   r%   r   Ú,FiscalOrchestrator._handle_technical_failurec   s³   € à×5Ñ5°oÓFÐØ(¨Õ2°?ÕCˆà˜JÔ&ØÐà˜JÔ&¯~Ü(Ø×*Ñ*¨?ÓMØ&6Ð7NÕ&OØ /Ø!1ô	ð
 !ð!ð	PØ×%Ñ%Ð&6ÐBRÓSÐSøÜ"ô 	àÜ#ô 	PÜ&¤s¨>Ó':Ó;ÀÐOûð	Pús   Á!A3 Á3B#ÂB#Â	BÂB#c                ó   € VR8X  d   R# R# )zRecupere fallback channel.r
   r   © )r#   r   s   &&r%   r6   Ú(FiscalOrchestrator._get_fallback_channel{   s   € ð (¨6Ô1ˆuÐ=°vÐ=r0   c                ó*   € VR8X  d   VR8X  d    R#  R# )zConstruit prompt message.r
   r   ztLe serveur e-MCF de la DGI est temporairement indisponible. Voulez-vous valider cette facture avec le MCF physique ?ztLe MCF physique est temporairement indisponible. Voulez-vous valider cette facture avec le serveur e-MCF de la DGI ?r<   )r#   r   r5   s   &&&r%   r7   Ú(FiscalOrchestrator._build_prompt_message€   s*   € ð ˜fÔ$Ð)9¸UÔ)BðKñðRñ	
r0   c                ó¤  € V'       di   RRRR/P                  VR4      pV Uu. uF  qcP                  V4      '       d   K  VNK  	  ppV'       d"   \        RR	P                  V4      ,           4      hVP                  R4      ;'       g    R
Vn        VP                  R4      ;'       g    R
Vn        VP                  R4      ;'       g    R
Vn        VP                  R4      ;'       g    R
Vn        VP                  R4      ;'       g    R
Vn        VP                  R4      ;'       g    R
Vn        W!n	        VP                  . ROR7       R# u upi )zVRecopie sur la commande locale les elements de securite retournes par le canal fiscal.r
   ÚuidÚcode_def_dgiÚcountersÚnimÚqr_coder   zELa fiscalisation a reussi sans tous les elements de securite requis: z, Ú Ú	date_time)Úupdate_fieldsN)rA   rB   rC   rD   rE   )rB   rC   rD   rE   r<   )rA   ÚdateTimedgiÚ
codedefdgirC   rD   ÚqrCodeÚfiscal_channel)r    r   ÚjoinrA   rI   rJ   rC   rD   rK   rL   Úsave)r#   r   r   r   r   Úrequired_fieldsÚfieldÚmissings   &&&&&   r%   r   Ú+FiscalOrchestrator._apply_security_elementsŽ   s%  € çàÐMØÐEð÷ ‰c�'˜2Óð ñ
 +:ÓU©/ ÇÁÈe×AT—u�u©/ˆGÐUßÜ*Ø[Ø—i‘i Ó(õ)óð ð
  —|‘| EÓ*×0Ð0¨bˆŒØ'Ÿ|™|¨KÓ8×>Ð>¸BˆÔØ&Ÿl™l¨>Ó:×@Ð@¸bˆÔØ$ŸL™L¨Ó4×:Ð:¸ˆÔØ—|‘| EÓ*×0Ð0¨bˆŒØ"Ÿ,™, yÓ1×7Ð7°RˆŒØ")ÔØ�‰òð 	ö 
	
ùò Vs   £EÁ Er<   )FN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r)   r&   r   r   r6   r7   r   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r%   r	   r	      sB   ø‡ € ñð 	�Øˆzð€Hô
+
òZ=òPò0>ò

÷ 
ð  
r0   r	   )rW   ÚloggingÚdgi.emcf_adapterr   Úmcf.mcf_adapterr   Úfiscal_exceptionsr   r   r   Úfiscal_preparationr   Ú	getLoggerrS   r*   r	   r<   r0   r%   Ú<module>ra      s@   ðñó å (Ý &÷ñ õ
 5à	×	Ò	˜8Ó	$€÷U
ó U
r0   