3 Commits

Author SHA1 Message Date
99434a21e0 Fonctionnalite: verifier qu'aucun contrat n'est actif avant la creation d'un nouveau pour un employe
All checks were successful
Organisation/sirh/pipeline/head This commit looks good
2026-05-06 16:01:37 +00:00
f6b90e7dd0 Verification du statut avant la creation d'un contrat 2026-05-06 15:53:02 +00:00
fcfac71026 clean: remove pycache from tracking 2026-05-06 15:44:16 +00:00
35 changed files with 21 additions and 6 deletions

2
.gitignore vendored
View File

@@ -3,4 +3,4 @@ venv/
media/
staticfiles/
.env
migrations/
migrations/

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,5 @@
import json
from datetime import timedelta, datetime
from datetime import date, timedelta, datetime
from dateutil.relativedelta import relativedelta
from django.utils import timezone
@@ -247,14 +247,25 @@ def suppression_affectation(request):
return JsonResponse({"message": "Affectation supprimée avec succès."})
def creation_contrat(request):
"""Vue pour permettre à un utilisateur de créer un contrat pour un employé"""
"""Créer un contrat pour un employé (avec contrôle d'existence de contrat actif)"""
try:
employe = Employe.objects.get(id=request.POST.get('employe_id'))
except Employe.DoesNotExist:
messages.error(request, "Employé non trouvé.")
return redirect('employe-index')
contrat_actif = Contrat.objects.filter(
employe=employe,
date_fin__gte=date.today()
).exists()
if request.method == "POST":
if contrat_actif:
messages.error(
request,
"Impossible de créer un contrat : cet employé a déjà un contrat actif."
)
return redirect('gestion_employe:index')
form = ContratForm(request.POST, request.FILES)
if form.is_valid():
contrat = form.save(commit=False)
@@ -263,9 +274,13 @@ def creation_contrat(request):
messages.success(request, "Contrat créé avec succès.")
return redirect('gestion_employe:index')
messages.error(request, "Formulaire non valide")
else:
form = ContratForm(initial={'employe': employe})
return render(request, 'gestion_employe/index.html', {'contrat_form': form})
return render(request, 'gestion_employe/index.html', {
'contrat_form': form
})
@login_required
def enregistrer_detail_employe(request):
@@ -413,4 +428,4 @@ def supprimer_formation(request, id_formation):
if request.method == "POST":
formation.delete()
messages.success(request, "Formation supprimée ")
return redirect("mes_formations")
return redirect("mes_formations")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.