[#2653] Importation des responsables d'implantation
authorEric Mc Sween <eric.mcsween@auf.org>
Thu, 16 Feb 2012 19:28:59 +0000 (14:28 -0500)
committerEric Mc Sween <eric.mcsween@auf.org>
Thu, 16 Feb 2012 19:28:59 +0000 (14:28 -0500)
project/legacy/management/commands/rh_import_legacy.py

index 02f8249..b8c0fcf 100644 (file)
@@ -1,6 +1,6 @@
 # coding: utf-8
 
-from datetime import datetime
+from datetime import datetime, date
 from decimal import Decimal
 
 from django.contrib.auth.models import User
@@ -335,12 +335,14 @@ def sync_dossier():
     cursor.execute('TRUNCATE rh_dossier')
     cursor.execute('TRUNCATE rh_remuneration')
     cursor.execute('TRUNCATE rh_dossiercommentaire')
+    cursor.execute('TRUNCATE rh_responsableimplantation')
     odette = User.objects.get(username='odette.tremblay')
     type_contrat_inconnu = rh.TypeContrat.objects.create(
         nom='Inconnu',
         nom_long='Inconnu',
     )
-    dossiers = legacy.Dossiers.objects.annotate(timestamp_modif=Max('historique__stamp'))
+    dossiers = legacy.Dossiers.objects.annotate(timestamp_modif=Max('historique__stamp')) \
+            .order_by('no_dossier')
     for dossier in dossiers:
         date_modification = datetime.fromtimestamp(dossier.timestamp_modif) \
                 if dossier.timestamp_modif else None
@@ -358,12 +360,32 @@ def sync_dossier():
             remplacement=False,
             supprime=False
         )
+
+        # Commentaires
         if dossier.remarque:
             rh.DossierCommentaire.objects.create(
                 dossier=dossier1,
                 texte=dossier.remarque,
                 owner=odette
             )
+
+        # Responsables d'implantation
+        today = date.today().isoformat()
+        if not dossier.date_fin_mandat or dossier.date_fin_mandat >= today:
+            if dossier.responsable_implantation_1:
+                responsable, created = rh.ResponsableImplantation.objects.get_or_create(
+                    implantation_id=dossier.id_implantation_1
+                )
+                responsable.employe_id = dossier.employe_id
+                responsable.save()
+            if dossier.responsable_implantation_2:
+                responsable, created = rh.ResponsableImplantation.objects.get_or_create(
+                    implantation_id=dossier.id_implantation_2
+                )
+                responsable.employe_id = dossier.employe_id
+                responsable.save()
+
+        # Contrats
         rh.Contrat.objects.create(
             dossier=dossier1,
             type_contrat_id=dossier.id_type_contrat or type_contrat_inconnu.id,
@@ -372,7 +394,7 @@ def sync_dossier():
             supprime=False
         )
 
-
+        # Rémunération
         remuns_precedentes = {}
         charges_precedentes = None
         pourcentage_charges = 0
@@ -402,19 +424,16 @@ def sync_dossier():
             if remun.type_remuneration.nature_remuneration != 'Charges' and remun.montant != 0:
                 devise, created = rh.Devise.objects.get_or_create(code=remun.code_devise)
 
-                try:
-                    rh_remun = rh.Remuneration.objects.create(
-                        dossier=dossier1,
-                        type_id=remun.type_remuneration_id,
-                        type_revalorisation_id=remun.id_type_revalorisation,
-                        montant=remun.montant,
-                        devise=devise,
-                        supprime=False,
-                        date_debut=date_debut,
-                        date_fin=date_fin
-                    )
-                except:
-                    import pdb; pdb.set_trace()
+                rh_remun = rh.Remuneration.objects.create(
+                    dossier=dossier1,
+                    type_id=remun.type_remuneration_id,
+                    type_revalorisation_id=remun.id_type_revalorisation,
+                    montant=remun.montant,
+                    devise=devise,
+                    supprime=False,
+                    date_debut=date_debut,
+                    date_fin=date_fin
+                )
 
                 # Se souvenir de ce type de rémunération
                 if remun.type_remuneration.type_paiement == u'Régulier':