+
    #BÛi¦  ã            
       óˆ   € R t ^ RIt^ RIHt ^ RIHt ^ RIHtHt R t	R t
R tR tR	 tR
 tR tR tRRRRRRRRRR/R ltR# )z¬
Services de presentation relies aux ecrans client.

Le modele et sa consommation metier restent dans facturation ; seuls les
helpers de consultation sont centralises ici.
N)ÚObjectDoesNotExist)ÚSum)ÚClientÚCommandec                 ó\   € \         P                  P                  R4      P                  4       # )zARetourne la liste client avec les jointures utiles a l'affichage.Úclient_type©r   ÚobjectsÚselect_relatedÚall© ó    Ú2D:\ProjetDjango\FacControl_1.3\clients\services.pyÚget_client_list_querysetr      ó    € ä�>‰>×(Ñ(¨Ó7×;Ñ;Ó=Ð=r   c                 ó\   € \         P                  P                  R4      P                  4       # )zFRetourne le queryset detail sans modifier le comportement fonctionnel.r   r   r   r   r   Úget_client_detail_querysetr      r   r   c           	     ó,  € \         P                  P                  V R7      P                  R4      pVP	                  \        R4      4      R,          ;'       g    ^ pVP	                  \        R4      4      R,          ;'       g    ^ pRVRVR	VR
W#,
          /# )zCConstruit le contexte historique et statistique de la fiche client.)Úclientz-date_commandeÚmontant_totalÚmontant_total__sumÚmontant_payeÚmontant_paye__sumÚ	commandesÚtotal_achatsÚ
total_payeÚreste_a_payer)r   r	   ÚfilterÚorder_byÚ	aggregater   )r   r   r   r   s   &   r   Úbuild_client_detail_contextr       s’   € ä× Ñ ×'Ñ'¨vÐ'Ó6×?Ñ?Ð@PÓQ€IØ×&Ñ&¤s¨?Ó';Ó<Ð=QÕR×WÐWÐVW€LØ×$Ñ$¤S¨Ó%8Ó9Ð:MÕN×SÐSÐRS€Jð 	�YØ˜Ø�jØ˜Õ2ð	ð r   c           	     óž  € . p\        4       pV P                  P                   EF  pVP                  4       pV'       g   K   \	        W4      p\        TR4      '       d    TP                  4       P                  4       pMTRJpT'       g   Ki  \        TP                  P                  P                  ;'       g?    TP                  P                  P                  ;'       g    TP                  P                  4      pYr9   d   Kà  TP                  T4       TP                  RTRTRTP                  /4       EK  	  V#   \
         d     EK(  i ; i)zç
Recense les relations reverse deja liees a un client.

Cette verification permet de bloquer les suppressions qui casseraient
l'historique des ventes, des avoirs, des proformas ou d'autres donnees
metier deja rattachees au client.
r   NÚaccessor_nameÚlabelÚmodel)ÚsetÚ_metaÚrelated_objectsÚget_accessor_nameÚgetattrr   Úhasattrr   ÚexistsÚstrÚrelated_modelÚverbose_name_pluralÚverbose_nameÚ__name__ÚaddÚappend)r   Úblocking_relationsÚseen_labelsÚrelationr"   ÚaccessorÚhas_related_recordsÚrelation_labels   &       r   Úget_client_blocking_relationsr9   (   s0  € ð ÐÜ“%€Kà—L‘L×0Õ0ˆØ ×2Ñ2Ó4ˆßÙð	Ü˜vÓ5ˆHô �8˜U×#Ò#Ø"*§,¡,£.×"7Ñ"7Ó"9Ñà"*°$Ð"6Ðç"ÙäØ×"Ñ"×(Ñ(×<Ñ<÷ /ð /Ø×%Ñ%×+Ñ+×8Ñ8÷/ð /à×%Ñ%×.Ñ.ó
ˆð Ô(Ùà�‰˜Ô'Ø×!Ñ!à Ø˜Ø˜×/Ñ/ð÷	
ñ9 1ðH Ðøô; "ô 	Ûð	ús   ÁD<Ä<EÅEc                ó˜   € \        T ;'       g    R4      P                  4       p \        P                  ! RRV 4      p V P	                  4       # )zGNormalise un texte libre en ignorant la casse et les espaces superflus.Ú ú\s+Ú )r,   ÚstripÚreÚsubÚcasefold©Úvalues   &r   Únormalize_client_textrD   [   s<   € ô �—�˜Ó×"Ñ"Ó$€EÜ�FŠF�6˜3 Ó&€EØ�>‰>ÓÐr   c                ó˜   € \        T ;'       g    R4      P                  4       p \        P                  ! RRV 4      p V P	                  4       # )zFNormalise un identifiant type NIF en supprimant les espaces parasites.r;   r<   )r,   r>   r?   r@   ÚupperrB   s   &r   Únormalize_client_identifierrG   c   s;   € ô �—�˜Ó×"Ñ"Ó$€EÜ�FŠF�6˜2˜uÓ%€EØ�;‰;‹=Ðr   c                óx   € \        T ;'       g    R4      P                  4       p \        P                  ! RRV 4      # )zDNormalise un numero de telephone en supprimant les espaces inutiles.r;   r<   )r,   r>   r?   r@   rB   s   &r   Únormalize_client_phonerI   k   s0   € ô �—�˜Ó×"Ñ"Ó$€EÜ�6Š6�&˜"˜eÓ$Ð$r   c                ód   € \        T ;'       g    R4      P                  4       P                  4       # )zJNormalise une adresse e-mail en ignorant la casse et les espaces externes.r;   )r,   r>   rA   rB   s   &r   Únormalize_client_emailrK   r   s'   € ô ˆu�{ˆ{˜Ó×!Ñ!Ó#×,Ñ,Ó.Ð.r   ÚinstanceÚnom_completr;   Ú	telephoneÚemailÚnifc           
     ób  € \        V4      p\        V4      p\        V4      p\        V4      p\        P
                  P                  4       p	\        V RR4      '       d   V	P                  V P                  R7      p	Rp
RpRpRp. p\        4       pV	 EF�  p\        \        VRR4      4      p\        \        VRR4      ;'       g    \        VRR4      4      p\        \        VRR4      4      p\        \        VR	R4      4      p\        T;'       d    T;'       d    VV8H  4      p\        T;'       d    T;'       d    VV8H  4      p\        T;'       d    T;'       d    VV8H  4      pV'       d   V'       d   VV8X  d   T
;'       g    Tp
V'       d   V'       d   T;'       g    TpMbV'       d   V'       d   T;'       g    TpMEV'       d>   VP                  V9  d-   VP                  V4       VP                  VP                  4       V'       g   EK„  T;'       g    TpEK“  	  R
V
RVRVRVRV/# )a:  
Analyse les differents types de conflits possibles pour un client.

Regles appliquees :
- conflit strict sur le NIF si renseigne ;
- conflit strict sur le telephone si renseigne ;
- conflit strict sur nom + telephone ;
- conflit strict sur nom + e-mail ;
- signalement simple si seul le nom normalise correspond.
ÚpkN)rR   rP   r;   rM   ÚnamerN   rO   Ústrict_nif_matchÚstrict_phone_matchÚstrict_name_phone_matchÚstrict_name_email_matchÚsimilar_name_matches)rD   rI   rK   rG   r   r	   r   r)   ÚexcluderR   r%   Úboolr2   r1   )rL   rM   rN   rO   rP   Únormalized_nameÚnormalized_phoneÚnormalized_emailÚnormalized_nifÚquerysetrT   rU   rV   rW   rX   Úsimilar_name_idsr   Ú
client_nifÚclient_nameÚclient_phoneÚclient_emailÚ	same_nameÚ
same_phoneÚ
same_emails   $$$$$                   r   Ú#analyze_client_duplicate_candidatesrh   x   s  € ô& ,¨KÓ8€OÜ-¨iÓ8ÐÜ-¨eÓ4ÐÜ0°Ó5€Nä�~‰~×!Ñ!Ó#€HÜˆx˜˜t×$Ò$Ø×#Ñ# x§{¡{Ð#Ó3ˆàÐØÐØ"ÐØ"ÐØÐÜ“uÐäˆÜ0´¸ÀÈÓ1KÓLˆ
Ü+Ü�F˜M¨4Ó0×OÐO´G¸FÀFÈBÓ4Oó
ˆô .¬g°f¸kÈ2Ó.NÓOˆÜ-¬g°f¸gÀrÓ.JÓKˆä˜×[Ð[¨[×[Ð[¸_ÐP[Ñ=[Ó\ˆ	ÜÐ*×`Ð`¨|×`Ð`Ð@PÐT`Ñ@`Óaˆ
ÜÐ*×`Ð`¨|×`Ð`Ð@PÐT`Ñ@`Óaˆ
çŸj¨^¸zÔ-IØ/×9Ð9°6ÐçŸØ&=×&GÐ&GÀÑ#ßŸ:Ø&=×&GÐ&GÀÑ#ß˜6Ÿ9™9Ð,<Ô<Ø ×'Ñ'¨Ô/Ø× Ñ  §¡Ô+çŠ:Ø!3×!=Ð!=°vÓñ1 ð6 	Ð,ØÐ0Ø!Ð#:Ø!Ð#:ØÐ 4ðð r   )Ú__doc__r?   Údjango.core.exceptionsr   Údjango.db.modelsr   Úfacturation.modelsr   r   r   r   r    r9   rD   rG   rI   rK   rh   r   r   r   Ú<module>rm      s|   ðñó 
å 5Ý  ç /ò>ò
>ò
ò0òfòò%ò/ðCàðCð ðCð ð	Cð
 ðCð 	öCr   