Files
sirh/gestion_employe/models.py
2026-04-29 11:52:03 +02:00

123 lines
5.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
from gestion_projet.models import Projet
class Departement(models.Model):
"""Modèle représentant un département de l'entreprise."""
nom = models.CharField(max_length=100)
def __str__(self):
return self.nom
class Employe(models.Model):
"""Modèle représentant un employé de l'entreprise."""
FONCTION_LISTE = [
('directeur', 'Directeur'),
('assistant_direction', 'Assistante de direction'),
('comptable', 'Comptable'),
('raf', 'RAF'),
('data_manager', 'Data Manager'),
('logisticien', 'Logisticien'),
('post_doctorant', 'Post-Doctorant'),
('qualiticien', 'Qualiticien'),
('technicien_surface', 'Technicien de surface'),
('chauffeur', 'Chauffeur'),
]
user = models.OneToOneField(User, on_delete=models.CASCADE)
matricule = models.CharField(max_length=10, unique=True, null=True, blank=True)
departement = models.ForeignKey(Departement, on_delete=models.SET_NULL, null=True, blank=True)
fonction = models.CharField(max_length=50, blank=True, null=True, choices=FONCTION_LISTE)
date_embauche = models.DateField(blank=True, null=True)
adresse = models.CharField(max_length=100, null=True, blank=True)
telephone = models.CharField(max_length=15, null=True, blank=True)
sexe = models.CharField(max_length=1, null=True, blank=True, choices=[('m', 'Masculin'), ('f', 'Féminin')])
date_naissance = models.DateField(blank=True, null=True)
CV = models.FileField(upload_to='cv/', blank=True, null=True)
diplome = models.FileField(upload_to='diplomes/', blank=True, null=True)
rib = models.FileField(upload_to='rib/', blank=True, null=True)
photo = models.ImageField(upload_to='photos/', blank=True, null=True)
casier_judiciaire = models.FileField(upload_to='casier/', blank=True, null=True)
chef = models.BooleanField(
default=False,
verbose_name="Cet utilisateur est-il chef de ce département ?"
)
def __str__(self):
return f"{self.user.first_name or 'N/A'} {self.user.last_name or ' '} ({self.matricule or ' '})"
class Contrat(models.Model):
"""Modèle représentant un contrat de travail d'un employé."""
TYPE_CONTRAT = [
('contrat_duree_determinee', 'Contrat à Durée Déterminée'),
('contrat_duree_indeterminee', 'Contrat à Durée Indéterminée'),
('contrat_prestation', 'Contrat de Prestation de Service'),
('contrat_stage', 'Contrat de Stage'),
('convention_bourse_entretien', 'Convention de bourse dentretien'),
]
STATUT_CONTRAT = [
('actif', 'Actif'),
('termine', 'Terminé'),
('suspendu', 'Suspendu'),
('rupture_contrat', 'Rupture de Contrat'),
]
employe = models.ForeignKey(Employe, on_delete=models.CASCADE)
numero_contrat = models.CharField(max_length=100, unique=True)
type_contrat = models.CharField(
max_length=50,
choices=TYPE_CONTRAT,
)
date_debut = models.DateField()
date_fin = models.DateField(null=True, blank=True)
salaire_mensuel = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
statut = models.CharField(max_length=50, choices=STATUT_CONTRAT)
fichier_contrat = models.FileField(upload_to='contrats/', null=True, blank=True)
@property
def nombre_jours_restant(self):
if self.date_fin:
return (self.date_fin - timezone.now().date()).days
return 100
def __str__(self):
return f"{self.numero_contrat} - {self.type_contrat}"
class Affectation(models.Model):
"""Modèle représentant l'affectation d'un employé à un projet avec un rôle spécifique."""
ROLE_CHOICES = [
('chef_projet', 'Chef de projet'),
('doctorant','Doctorant'),
('mastorant','Mastorant'),
('consultant','Consultant'),
('stagiaire','Stagiaire'),
('laborantin','Laborantin'),
('medecin','Médecin'),
('autre','Autre'),
]
employe = models.ForeignKey(Employe, on_delete=models.CASCADE)
projet = models.ForeignKey(Projet, on_delete=models.CASCADE)
date_affectation = models.DateField()
date_fin_daffectation = models.DateField(null=True, blank=True)
role = models.CharField(max_length=20, choices=ROLE_CHOICES, default='Membre')
pourcentage_temps_affectation = models.DecimalField(max_digits=5, decimal_places=2)
class Meta:
unique_together = ('projet', 'employe')
class Formation(models.Model):
"""Modèle représentant une formation suivie par un employé."""
employe = models.ForeignKey(Employe, on_delete=models.CASCADE, null=True, related_name='employe_formation')
titre = models.CharField(max_length=255, verbose_name="Nom du certificat")
organisme = models.CharField(max_length=255, verbose_name="Nom de l'organisme")
description = models.TextField(blank=True, null=True, verbose_name="Description de la formation")
date_obtention = models.DateField(blank=True, null=True, verbose_name="Date d'obtention")
date_fin = models.DateField(blank=True, null=True, verbose_name="Date de fin de validité")
certificat = models.FileField(upload_to='documents/formations/', blank=True, null=True, verbose_name="Certificat (PDF/Image)")
def __str__(self):
return self.titre