justification embauche
[auf_rh_dae.git] / project / dae / forms.py
index 9c7bb2f..69f10e4 100644 (file)
@@ -19,6 +19,49 @@ class DossierPieceForm(inlineformset_factory(dae.Dossier, dae.DossierPiece)):
 class FinancementForm(inlineformset_factory(dae.Poste, dae.PosteFinancement, extra=1)):
     pass
 
 class FinancementForm(inlineformset_factory(dae.Poste, dae.PosteFinancement, extra=1)):
     pass
 
+class JustificationNouvelEmployeForm(inlineformset_factory(dae.Dossier,
+                                                           dae.JustificationNouvelEmploye,
+                                                           extra=0,
+                                                           can_delete=False,
+                                                           exclude=('question',))):
+    """
+    Formulaire de justification d'un nouvel employé.
+    Le dossier a besoin d'être enregistré une première fois afin de prépopuler les questions.
+    """
+    def __init__(self, *args, **kwargs):
+        instance = kwargs['instance']
+        if instance.id:
+            q_ids = [q.id for q in instance.justificationnouvelemploye_set.all()]
+            for q in dae.JustificationQuestion.objects.filter(type="N"):
+                if q.id in q_ids:
+                    continue
+                j = dae.JustificationNouvelEmploye()
+                j.dossier = instance
+                j.question = q
+                j.save()
+        super(self.__class__, self).__init__(*args, **kwargs)
+
+class JustificationAutreEmployeForm(inlineformset_factory(dae.Dossier,
+                                                           dae.JustificationAutreEmploye,
+                                                           extra=0,
+                                                           can_delete=False,
+                                                           exclude=('question',))):
+    """
+    Formulaire de justification d'un nouvel employé.
+    Le dossier a besoin d'être enregistré une première fois afin de prépopuler les questions.
+    """
+    def __init__(self, *args, **kwargs):
+        instance = kwargs['instance']
+        if instance.id:
+            q_ids = [q.id for q in instance.justificationautreemploye_set.all()]
+            for q in dae.JustificationQuestion.objects.filter(type="R"):
+                if q.id in q_ids:
+                    continue
+                j = dae.JustificationAutreEmploye()
+                j.dossier = instance
+                j.question = q
+                j.save()
+        super(self.__class__, self).__init__(*args, **kwargs)
 
 class PosteValidationForm(forms.ModelForm):
     """ Validation d'un poste"""
 
 class PosteValidationForm(forms.ModelForm):
     """ Validation d'un poste"""