Correction sur l'afficha de la liste de departement pour la modification des informations de l'employer
All checks were successful
Organisation/sirh/pipeline/head This commit looks good
All checks were successful
Organisation/sirh/pipeline/head This commit looks good
This commit is contained in:
@@ -13,16 +13,13 @@ from django.http import JsonResponse
|
||||
from django.forms.models import model_to_dict
|
||||
from django.db.models import Sum
|
||||
|
||||
from .models import Employe, Contrat, Affectation, Formation
|
||||
from .models import Employe, Contrat, Affectation, Formation, Departement
|
||||
from .forms import AffectationForm, ContratForm, FormationForm
|
||||
from fonction_utilitaire import fonctions_utilitaire
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
"""Vue d'index"""
|
||||
if not request.user.groups.filter(name="ressource_humaine").exists():
|
||||
return redirect('gestion_employe:mon-profil')
|
||||
|
||||
employes = Employe.objects.all().order_by('-user__date_joined')
|
||||
nombre_employes = Employe.objects.count()
|
||||
nombre_cps = Contrat.objects.filter(type_contrat='contrat_prestation').count()
|
||||
@@ -41,7 +38,8 @@ def index(request):
|
||||
'nombre_stage': nombre_stage,
|
||||
'nombre_expirants': nombre_expirants,
|
||||
'affectation_form': AffectationForm(),
|
||||
'contrat_form': ContratForm()
|
||||
'contrat_form': ContratForm(),
|
||||
'departements': Departement.objects.all()
|
||||
})
|
||||
|
||||
@login_required
|
||||
@@ -97,7 +95,7 @@ def affecter_employe_projet(request):
|
||||
elif total_affectation + temps_nouveau > 100:
|
||||
messages.warning(
|
||||
request,
|
||||
f"Les pourcentages d'affectation de l'employé {employe.user.first_name} {employe.user.last_name} dépasse 100% sur les différents projets ({total_affectation + temps_nouveau}%)."
|
||||
f"Les pourcentages d'affectation de l'employé {employe.first_name} {employe.last_name} dépasse 100% sur les différents projets ({total_affectation + temps_nouveau}%)."
|
||||
)
|
||||
return redirect('gestion_employe:index')
|
||||
|
||||
@@ -303,10 +301,30 @@ def enregistrer_detail_employe(request):
|
||||
except Employe.DoesNotExist:
|
||||
return JsonResponse({"error": "Employé non trouvé."}, status=404)
|
||||
|
||||
employe.fonction = data['fonction']
|
||||
employe.date_embauche = data['date_embauche']
|
||||
employe.matricule = data['matricule']
|
||||
employe.fonction = data.get('fonction')
|
||||
employe.date_embauche = data.get('date_embauche')
|
||||
employe.matricule = data.get('matricule')
|
||||
|
||||
# Traiter le département
|
||||
dept_value = data.get('departement')
|
||||
print(f"[DEBUG] Département brut: {dept_value!r}")
|
||||
print(f"[DEBUG] Type département: {type(dept_value).__name__}")
|
||||
print(f"[DEBUG] Est vide: {not dept_value}")
|
||||
|
||||
if dept_value and str(dept_value).strip():
|
||||
try:
|
||||
dept_id = int(dept_value)
|
||||
departement = Departement.objects.get(id=dept_id)
|
||||
employe.departement = departement
|
||||
except Departement.DoesNotExist:
|
||||
employe.departement = None
|
||||
except (ValueError, TypeError) as e:
|
||||
employe.departement = None
|
||||
else:
|
||||
employe.departement = None
|
||||
|
||||
employe.save()
|
||||
|
||||
return JsonResponse({"message": "Détails de l'employé mis à jour avec succès."})
|
||||
else:
|
||||
return JsonResponse({"message": "Méthode non autorisée."}, status=405)
|
||||
@@ -368,7 +386,7 @@ def liste_employe(request):
|
||||
"affectations": affectations,
|
||||
"projet": projets,
|
||||
"contrats": contrats,
|
||||
"departement": employe.departement.nom if employe.departement else "",
|
||||
"departement": employe.departement.id if employe.departement else "",
|
||||
"fonction": employe.fonction,
|
||||
"date_embauche": employe.date_embauche,
|
||||
"adresse": employe.adresse,
|
||||
@@ -440,3 +458,15 @@ def supprimer_formation(request, id_formation):
|
||||
formation.delete()
|
||||
messages.success(request, "Formation supprimée ")
|
||||
return redirect("mes_formations")
|
||||
|
||||
def liste_departements(request):
|
||||
"""Vue pour retourner la liste de tous les départements en JSON"""
|
||||
departements = Departement.objects.all()
|
||||
data = [
|
||||
{
|
||||
"id": dept.id,
|
||||
"nom": dept.nom
|
||||
}
|
||||
for dept in departements
|
||||
]
|
||||
return JsonResponse(data, safe=False)
|
||||
|
||||
Reference in New Issue
Block a user