Ë
    ¾yþj(  ã                   óê   — d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZmZmZ  G d	„ d
ej(                  «      Z G d„ dej(                  «      Z G d„ dej(                  «      Zy)z-Modeles de donnees de l'application proforma.é    N)ÚDecimal)Úsettings)Úmodels)Útimezone)Úgettext_lazy)ÚClientÚCommandeÚConfigurationÚModePaiementÚPointDeVenteÚProduitc                   óÖ  ‡ — e Zd ZdZd ed«      fd ed«      fd ed«      ffZ ej                  dd	d
d	¬«      Z ej                  e
ej                  d¬«      Z ej                  ej                  ej                  d¬«      Z ej                  eej"                  d	d	d¬«      Z ej&                  ddd¬«      Z ej&                  ddd¬«      Z ej&                  ddd¬«      Z ej&                  ddd¬«      Z ej                  ded¬«      Z ej&                  ddd	d	¬«      Z ej                  dd¬«      Z ej6                  d	d	¬«      Z ej                  eej"                  d	d	d¬«      Z ej>                  d	d	¬«      Z  ej>                  d	¬«      Z! ej>                  d	¬«      Z" G d „ d!«      Z#e$d+d"„«       Z%e$d#„ «       Z&d$„ Z'd%„ Z(ˆ fd&„Z)e*d'„ «       Z+e*d(„ «       Z,e*d)„ «       Z-d*„ Z.ˆ xZ/S ),ÚProformazÉ
    Entete commercial d'une proforma.

    La structure reste proche d'une commande de vente afin de reutiliser les
    memes reflexes de lecture pour les montants, remises, paiements et devises.
    ÚPAYEEÚPayeeÚ	PARTIELLEzPartiellement payeeÚIMPAYEEÚImpayeeé2   TF)Ú
max_lengthÚuniqueÚeditableÚdb_indexÚ	proformas©Ú	on_deleteÚrelated_nameÚproformas_creees)r   ÚnullÚblankr   é   é   r   ©Ú
max_digitsÚdecimal_placesÚdefaulté   ©r   Úchoicesr&   é
   )r$   r%   r   r    é   Úttc)r   r&   )r    r   Úproformas_facturees)r   r    )Úauto_now_add)Úauto_nowc                   ó   — e Zd ZdZdZdgZy)úProforma.Metaz	Pro-Formaz
Pro-Formasz-date_proformaN©Ú__name__Ú
__module__Ú__qualname__Úverbose_nameÚverbose_name_pluralÚordering© ó    ú-/var/www/faccontrol_acokin/proforma/models.pyÚMetar1   B   s   „ Ø"ˆØ*ÐØ$Ð%‰r:   r<   c                 ó¸   — | r 	 t        j                  | «      j                  S t        j                  «       j                  S # t        $ r | j                  cY S w xY w)z@Determine l'annee a utiliser dans la numerotation des proformas.)r   Ú	localtimeÚyearÚ	ExceptionÚnow)Ú
date_values    r;   Ú_resolve_numero_yearzProforma._resolve_numero_yearG   sR   € ñ ð'Ü×)Ñ)¨*Ó5×:Ñ:Ð:ô �|‰|‹~×"Ñ"Ð"øô ò 'Ø!—‘Ò&ð'ús   „A ÁAÁAc                 ó¶   — t        j                  dt        j                  |«      › d|› d�t        | xs d«      «      }|syt	        |j                  d«      «      S )z?Extrait la sequence numerique d'un numero de proforma existant.ú^ú-z-(\d+)$Ú r   é   )ÚreÚmatchÚescapeÚstrÚintÚgroup)ÚnumeroÚprefixr?   rJ   s       r;   Ú_extract_numero_sequencez!Proforma._extract_numero_sequenceQ   sO   € ô —‘˜AœbŸi™i¨Ó/Ð0°°$°°wÐ?ÄÀVÂ\ÈrÓARÓSˆÙØÜ�5—;‘;˜q“>Ó"Ð"r:   c           	      ó¢  — d}| j                  | j                  «      }| j                  | j                  ||«      }t	        | «      j
                  j                  |› d|› d�¬«      }| j                  r|j                  | j                  ¬«      }|j                  dd¬«      D ]  }t        || j                  |||«      «      }Œ! |› d|› d|dz   d	›�S )
z:Construit le prochain numero PF-ANNEE-SEQUENCE disponible.ÚPFrF   )Únumero__startswith)ÚpkrO   T)ÚflatrH   Ú05d)rC   Údate_proformarQ   rO   ÚtypeÚobjectsÚfilterrU   ÚexcludeÚvalues_listÚmax)ÚselfrP   r?   Úmax_sequenceÚquerysetÚexisting_numeros         r;   Úbuild_next_numerozProforma.build_next_numeroY   sÝ   € àˆØ×(Ñ(¨×);Ñ);Ó<ˆØ×4Ñ4°T·[±[À&È$ÓOˆä˜“:×%Ñ%×,Ñ,À6À(È!ÈDÈ6ÐQRÐ@SÐ,ÓTˆØ�7Š7Ø×'Ñ'¨4¯7©7Ð'Ó3ˆHà'×3Ñ3°HÀ4Ð3ÓHò 	ˆOÜØØ×-Ñ-¨o¸vÀtÓLó‰Lð	ð �˜˜4˜&  <°!Ñ#3°SÐ!9Ð:Ð:r:   c                 ó"  — t        t        | j                  xs d«      «      t        t        | j                  xs d«      «      z
  }|t        d«      k  rd| _        yt        t        | j                  xs d«      «      dkD  rd| _        yd| _        y)z>Met a jour le statut de paiement en fonction du montant verse.r   z0.01r   r   r   N)r   rL   Úmontant_totalÚmontant_payeÚstatut_paiement)r_   Úsoldes     r;   Úcalculer_soldezProforma.calculer_soldek   sx   € äœ˜D×.Ñ.Ò3°!Ó4Ó5¼ÄÀD×DUÑDUÒDZÐYZÓ@[Ó8\Ñ\ˆØ”G˜F“OÒ#Ø#*ˆDÕ Ü”S˜×*Ñ*Ò/¨aÓ0Ó1°AÒ5Ø#.ˆDÕ à#,ˆDÕ r:   c                 ó\  •— | j                   s_| j                  sSddlm}  || j                  «      }|�|| _        n1t
        j                  j                  «       }|r|j                  | _        | j                  s| j                  «       | _	        | j                  «        t        ‰| �4  |i |¤Ž y)zí
        Sauvegarde la proforma en gelant le taux de change et le numero.

        Cette logique garantit qu'une proforma relue plus tard conserve son
        contexte commercial initial, meme si la configuration change ensuite.
        r   )Útaux_configureN)rU   Útaux_change_appliqueÚg_taux.servicesrk   Úpoint_de_venter
   rZ   ÚfirstÚtaux_changerO   rc   ri   ÚsuperÚsave)r_   ÚargsÚkwargsrk   Úresolved_rateÚconfigÚ	__class__s         €r;   rr   zProforma.saveu   sŽ   ø€ ð �wŠw˜t×8Ò8Ý6Ù*¨4×+>Ñ+>Ó?ˆMØÐ(Ø,9�Õ)ä&×.Ñ.×4Ñ4Ó6�ÙØ06×0BÑ0B�DÔ-à�{Š{Ø×0Ñ0Ó2ˆDŒKà×ÑÔÜ‰‰�dÐ%˜fÓ%r:   c                 ó4   — | j                   | j                  z
  S )z3Retourne le solde restant a regler sur la proforma.)re   rf   ©r_   s    r;   Úreste_a_payerzProforma.reste_a_payerŒ   s   € ð ×!Ñ! D×$5Ñ$5Ñ5Ð5r:   c                 ó4   — | j                   | j                  z
  S )z=Retourne le montant hors taxe a partir du total TTC memorise.)re   Útva_montantry   s    r;   Úmontant_total_htzProforma.montant_total_ht’   s   € ð ×!Ñ! D×$4Ñ$4Ñ4Ð4r:   c                 óN   — | j                   xs d}|dkD  r| j                  |z  S dS )zFConvertit le total memorise en USD selon le taux gele sur le document.rH   r   )rl   re   )r_   Útauxs     r;   Úmontant_total_usdzProforma.montant_total_usd˜   s0   € ð ×(Ñ(Ò-¨AˆØ,0°1ªHˆt×!Ñ! DÑ(Ð;¸!Ð;r:   c                 ó   — | j                   S )z*Retourne le numero lisible de la proforma.)rO   ry   s    r;   Ú__str__zProforma.__str__Ÿ   s   € ð �{‰{Ðr:   ©N)0r3   r4   r5   Ú__doc__Ú_ÚSTATUT_PAIEMENTr   Ú	CharFieldrO   Ú
ForeignKeyr   ÚPROTECTrn   r   ÚAUTH_USER_MODELÚvendeurr   ÚSET_NULLÚclientÚDecimalFieldre   rf   Úremise_globaler|   rg   rl   Úmode_dgiÚ	TextFieldÚcommentairer	   ÚfactureÚDateTimeFieldÚdate_facturationrX   Ú
updated_atr<   ÚstaticmethodrC   rQ   rc   ri   rr   Úpropertyrz   r}   r€   r‚   Ú__classcell__©rw   s   @r;   r   r      sT  ø„ ñð 
‘!�G“*ÐØ	‘aÐ-Ó.Ð/Ø	‘A�i“LÐ!ð€Oð ˆV×Ñ¨°DÀ5ÐSWÔX€FØ&�V×&Ñ& |¸v¿~¹~Ð\gÔh€NØˆf×ÑØ× Ñ Ø—.‘.Ø'ô€Gð
 ˆV×ÑØØ—/‘/ØØØ ô€Fð (�F×'Ñ'°2ÀaÐQRÔS€MØ&�6×&Ñ&°"ÀQÐPQÔR€LØ(�V×(Ñ(°BÀqÐRSÔT€NØ%�&×%Ñ%°ÀAÈqÔQ€KØ&�f×&Ñ&°"¸oÐW`Ôa€OØ.˜6×.Ñ.¸"ÈQÐUYÐaeÔfÐØˆv×Ñ¨1°eÔ<€HØ"�&×"Ñ"¨°DÔ9€Kð  ˆf×ÑØØ—/‘/ØØØ*ô€Gð ,�v×+Ñ+°¸TÔBÐØ(�F×(Ñ(°dÔ;€MØ%�×%Ñ%¨tÔ4€J÷&ñ &ð
 ò#ó ð#ð ñ#ó ð#ò;ò$-ô&ð. ñ6ó ð6ð
 ñ5ó ð5ð
 ñ<ó ð<ör:   r   c                   ó˜  ‡ — e Zd ZdZ ej
                  edej                  ¬«      Z ej
                  e	ej                  d¬«      Z ej                  d¬«      Z ej                  dd	¬
«      Z ej                  dd	¬
«      Z ej                   dd¬«      Z ej                   dd¬«      Z ej                   ddd¬«      Z ej                   dd¬«      Z ej                  dd	¬
«      Z ej                   ddd¬«      Z ej.                  d¬«      Z ej                  dd	¬
«      Z ej                  dd	¬
«      Z G d„ d«      Zˆ fd„Zd„ Zˆ xZS )ÚProformaItemzÇ
    Ligne commerciale d'une proforma.

    Chaque ligne memorise l'etat produit retenu au moment de la creation afin
    que le document reste lisible meme si la fiche produit evolue plus tard.
    Úlignes©r   r   Úlignes_proformar   éÿ   )r   r   T)r   r    r*   é   )r$   r%   r!   r"   r   r#   r+   F©r&   éd   c                   ó   — e Zd ZdZdZdgZy)úProformaItem.MetazLigne de Pro-FormazLignes de Pro-FormaÚidNr2   r9   r:   r;   r<   r¥   »   s   „ Ø+ˆØ3ÐØ�6‰r:   r<   c                 óz   •— | j                   | j                  z  | j                  z
  | _        t	        ‰| �  |i |¤Ž y)z@Recalcule le sous-total de ligne avant de persister la proforma.N)ÚquantiteÚprix_unitaireÚremiseÚ
sous_totalrq   rr   )r_   rs   rt   rw   s      €r;   rr   zProformaItem.saveÀ   s5   ø€ ð
  Ÿ=™=¨4×+=Ñ+=Ñ=ÀÇÁÑLˆŒÜ‰‰�dÐ%˜fÓ%r:   c                 ó:   — | j                   › d| j                  › d�S )z;Retourne une representation courte de la ligne de proforma.z (ú))Údesignationr¨   ry   s    r;   r‚   zProformaItem.__str__È   s"   € ð ×"Ñ"Ð# 2 d§m¡m _°AÐ6Ð6r:   )r3   r4   r5   r„   r   rˆ   r   ÚCASCADEÚproformar   r‰   Úproduitr‡   r®   Úcode_skuÚunite_mesurerŽ   r¨   r©   rª   r«   Útax_group_codeÚtax_rateÚBooleanFieldÚest_taxe_specifiqueÚtaxe_specifique_valeurÚtaxe_specifique_descriptionr<   rr   r‚   r™   rš   s   @r;   rœ   rœ   ¥   sF  ø„ ñð !ˆv× Ñ  ¸ÈFÏNÉNÔ[€HØˆf×Ñ °6·>±>ÐPaÔb€GØ"�&×"Ñ"¨cÔ2€KØˆv×Ñ¨2°TÔ:€HØ#�6×#Ñ#¨r¸Ô>€LØ"ˆv×"Ñ"¨bÀÔC€HØ'�F×'Ñ'°2ÀaÔH€MØ ˆV× Ñ ¨B¸qÈ!ÔL€FØ$�×$Ñ$°À1ÔE€JØ%�V×%Ñ%°¸4Ô@€NØ"ˆv×"Ñ"¨aÀÈ1ÔM€HØ-˜&×-Ñ-°eÔ<ÐØ-˜V×-Ñ-¸À4ÔHÐØ"2 &×"2Ñ"2¸cÈÔ"NÐ÷ñ ô
&ö7r:   rœ   c                   óø  ‡ — e Zd ZdZd ed«      fd ed«      ffZ ej                  edej                  ¬«      Z
 ej                  dd	 ed
«      ¬«      Z ej                  dd	d¬«      Z ej                  ded¬«      Z ej                  dd	d¬«      Z ej                  eej$                  d¬«      Z ej(                  ej,                  ¬«      Z ej                  ddd¬«      Z G d„ d«      Zˆ fd„Zd„ Zˆ xZS )ÚProformaPaymentzÄ
    Paiement rattache a une proforma.

    La structure suit le modele des paiements de commande afin de conserver les
    memes conventions de devise, taux applique et mise a jour du solde.
    ÚUSDzDollar AmericainÚCDFzFranc CongolaisÚ	paiementsrž   r!   r"   z(Montant converti en devise systeme (CDF))r$   r%   Ú	help_textr   r#   r¡   r(   r*   rH   Úmode_paiement)r   Ú	db_columnr¢   r£   T)r   r    r   c                   ó   — e Zd ZdZdZddgZy)úProformaPayment.MetazPaiement de Pro-FormazPaiements de Pro-FormaÚdate_paiementr¦   Nr2   r9   r:   r;   r<   rÃ   ã   s   „ Ø.ˆØ6ÐØ# TÐ*‰r:   r<   c                 óÎ  •— | j                   dk(  r.| j                  dkD  r| j                  | j                  z  | _        n| j                  | _        t	        ‰| �  |i |¤Ž t        d„ | j                  j                  j                  «       D «       t        d«      «      }|| j                  _        | j                  j                  «        | j                  j                  ddg¬«       y)	z×
        Convertit le paiement dans la devise systeme puis recalcule le solde.

        Le but est de garder une lecture uniforme des paiements, qu'ils aient
        ete saisis en USD ou directement en CDF.
        r¼   r   c              3   ó4   K  — | ]  }|j                   –— Œ y ­wrƒ   )Úmontant)Ú.0Úpaiements     r;   ú	<genexpr>z'ProformaPayment.save.<locals>.<genexpr>÷   s   è ø€ ÒL (ˆX×ÕÑLùs   ‚Ú0rf   rg   )Úupdate_fieldsN)ÚdeviseÚtaux_transactionÚmontant_verserÇ   rq   rr   Úsumr°   r¾   Úallr   rf   ri   )r_   rs   rt   Ú
total_payerw   s       €r;   rr   zProformaPayment.saveè   s¹   ø€ ð �;‰;˜%Ò D×$9Ñ$9¸AÒ$=Ø×-Ñ-°×0EÑ0EÑEˆD�Là×-Ñ-ˆDŒLä‰‰�dÐ%˜fÒ%äÙL¨d¯m©m×.EÑ.E×.IÑ.IÓ.KÔLÜ�C‹Ló
ˆ
ð &0ˆ�‰Ô"Ø�‰×$Ñ$Ô&Ø�‰×Ñ¨.Ð:KÐ)LÐÕMr:   c                 óR   — | j                   › d| j                  › d| j                  › �S )z<Retourne une representation lisible du paiement de proforma.z - ú )rÀ   rÏ   rÍ   ry   s    r;   r‚   zProformaPayment.__str__þ   s-   € ð ×$Ñ$Ð% S¨×);Ñ);Ð(<¸A¸d¿k¹k¸]ÐKÐKr:   )r3   r4   r5   r„   r…   ÚDEVISE_CHOICESr   rˆ   r   r¯   r°   rŽ   rÇ   rÏ   r‡   rÍ   rÎ   r   r‰   rÀ   r”   r   rA   rÄ   Úreference_transactionr<   rr   r‚   r™   rš   s   @r;   r»   r»   Î   s  ø„ ñð 
‘Ð$Ó%Ð&Ø	‘Ð#Ó$Ð%ð€Nð
 !ˆv× Ñ  ¸ÈvÏ~É~Ô^€HØ!ˆf×!Ñ!¨RÀÉQÐOyÓMzÔ{€GØ'�F×'Ñ'°2ÀaÐQRÔS€MØˆV×Ñ¨°NÈEÔR€FØ*�v×*Ñ*°bÈÐTUÔVÐØ%�F×%Ñ% l¸f¿n¹nÐXgÔh€MØ(�F×(Ñ(°·±Ô>€MØ,˜F×,Ñ,¸À4ÈdÔSÐ÷+ñ +ô
Nö,Lr:   r»   )r„   rI   Údecimalr   Údjango.confr   Ú	django.dbr   Údjango.utilsr   Údjango.utils.translationr   r…   Úfacturation.modelsr   r	   r
   r   r   r   ÚModelr   rœ   r»   r9   r:   r;   ú<module>rÞ      sV   ðÙ 3ã 	Ý å  Ý Ý !Ý 6ç c× côPˆv�|‰|ô Pôf&7�6—<‘<ô &7ôR3L�f—l‘lõ 3Lr:   