From 83b7692b2a23ce27de064385fd4bab4806d1900e Mon Sep 17 00:00:00 2001 From: davin baragiotta Date: Tue, 26 Apr 2011 14:10:54 -0400 Subject: [PATCH] rh.models ~= dae.models --- project/rh/models.py | 417 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 306 insertions(+), 111 deletions(-) diff --git a/project/rh/models.py b/project/rh/models.py index 91fd591..644e1a6 100644 --- a/project/rh/models.py +++ b/project/rh/models.py @@ -1,8 +1,157 @@ # -=- encoding: utf-8 -=- import datetime + +from django.core.files.storage import FileSystemStorage from django.db import models -from datamaster_modeles.models import Pays, Implantation +import settings + +import datamaster_modeles.models as ref + + +# Upload de fichiers +storage_prive = FileSystemStorage(settings.PRIVE_MEDIA_ROOT, + base_url=settings.PRIVE_MEDIA_URL) + +def poste_piece_dispatch(instance, filename): + path = "poste/%s/%s" % (instance.poste_id, filename) + return path + +def dossier_piece_dispatch(instance, filename): + path = "dossier/%s/%s" % (instance.dossier_id, filename) + return path + + +### POSTE + +POSTE_APPEL_CHOICES = ( + ('interne', 'Interne'), + ('externe', 'Externe'), +) + +class Poste(models.Model): + # Identification + id = models.IntegerField(primary_key=True) + nom = models.CharField(verbose_name="Titre du poste", max_length=255) + implantation = models.ForeignKey(ref.Implantation) + type_poste = models.ForeignKey(rh.TypePoste, null=True, related_name='+') + service = models.ForeignKey(rh.Service, related_name='+', + verbose_name=u"Direction/Service/Pôle support") + responsable = models.ForeignKey(rh.Poste, related_name='+', + verbose_name="Poste du responsable") + + # Contrat + regime_travail = models.DecimalField(max_digits=12, decimal_places=2, + default=100, + verbose_name="Temps de travail", + help_text="% du temps complet") + regime_travail_nb_heure_semaine = models.DecimalField(max_digits=12, + decimal_places=2, + default=35, + verbose_name="Nb. heures par semaine") + + # Recrutement + local = models.BooleanField(verbose_name="Local", default=True, blank=True) + expatrie = models.BooleanField(verbose_name="Expatrié", default=False, + blank=True) + + # TODO null? + mise_a_disposition = models.BooleanField(verbose_name="Mise à disposition") + appel = models.CharField(max_length=10, default='interne', + verbose_name="Appel à candidature", + choices=POSTE_APPEL_CHOICES) + + # Rémunération + classement_min = models.ForeignKey(rh.Classement, related_name='+') + classement_max = models.ForeignKey(rh.Classement, related_name='+') + valeur_point_min = models.ForeignKey(rh.ValeurPoint, related_name='+', + blank=True, null=True) + valeur_point_max = models.ForeignKey(rh.ValeurPoint, related_name='+', + blank=True, null=True) + devise_min = models.ForeignKey(rh.Devise, default=5, related_name='+') + devise_max = models.ForeignKey(rh.Devise, default=5, related_name='+') + salaire_min = models.DecimalField(max_digits=12, decimal_places=2, + default=0) + salaire_max = models.DecimalField(max_digits=12, decimal_places=2, + default=0) + indemn_min = models.DecimalField(max_digits=12, decimal_places=2, + default=0) + indemn_max = models.DecimalField(max_digits=12, decimal_places=2, + default=0) + autre_min = models.DecimalField(max_digits=12, decimal_places=2, + default=0) + autre_max = models.DecimalField(max_digits=12, decimal_places=2, + default=0) + + # Comparatifs de rémunération + devise_comparaison = models.ForeignKey(rh.Devise, related_name='+', + default=5) + comp_locale_min = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + comp_locale_max = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + comp_universite_min = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + comp_universite_max = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + comp_fonctionpub_min = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + comp_fonctionpub_max = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + comp_ong_min = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + comp_ong_max = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + comp_autre_min = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + comp_autre_max = models.DecimalField(max_digits=12, decimal_places=2, + null=True, blank=True) + + # Justification + justification = models.TextField() + + # Méta + date_validation = models.DateTimeField() #dae + date_creation = models.DateTimeField(auto_now_add=True) + date_modification = models.DateTimeField(auto_now=True) + date_debut = models.DateField(verbose_name="Date de début", + help_text="format: aaaa-mm-jj") + date_fin = models.DateField(null=True, blank=True, + verbose_name="Date de fin", + help_text="format: aaaa-mm-jj") + actif = models.BooleanField(default=True) + + def __unicode__(self): + # gérer si poste est vacant ou non dans affichage + return u'%s - %s [%s]' % (self.implantation, self.nom, self.id) + + +POSTE_FINANCEMENT_CHOICES = ( + ('A', 'A - Frais de personnel'), + ('B', 'B - Projet(s)-Titre(s)'), + ('C', 'C - Autre') +) + +class PosteFinancement(models.Model): + poste = models.ForeignKey('Poste', related_name='financements') + type = models.CharField(max_length=1, choices=POSTE_FINANCEMENT_CHOICES) + pourcentage = models.DecimalField(max_digits=12, decimal_places=2, + help_text="ex.: 33.33 % (décimale avec point)") + commentaire = models.TextField( + help_text="Spécifiez la source de financement.") + + class Meta: + ordering = ['type'] + +class PostePiece(models.Model): + poste = models.ForeignKey("Poste") + nom = models.CharField(verbose_name="Nom", max_length=255) + fichier = models.FileField(verbose_name="Fichier", + upload_to=poste_piece_dispatch, + storage=storage_prive) + + +### EMPLOYÉ/PERSONNE GENRE_CHOICES = ( ('M', 'Homme'), @@ -14,21 +163,23 @@ SITUATION_CHOICES = ( ('M', 'Marié'), ) -class Employe(models.Model): +class Employe(models.Model): # Identification id = models.IntegerField(primary_key=True) nom = models.CharField(max_length=255) prenom = models.CharField(max_length=255) - nationalite = models.ForeignKey('datamaster_modeles.Pays', to_field='code', + nationalite = models.ForeignKey(ref.Pays, to_field='code', related_name='employes_nationalite', db_column='nationalite') date_naissance = models.DateField(null=True, blank=True) + # Infos personnelles genre = models.CharField(max_length=1, null=True, blank=True, choices=GENRE_CHOICES) situation_famille = models.CharField(max_length=1, null=True, blank=True, choices=SITUATION_CHOICES) date_entree = models.DateField(null=True, blank=True) #devrait pas être là + # Coordonnées tel_domicile = models.CharField(max_length=255, null=True, blank=True) tel_cellulaire = models.CharField(max_length=255, null=True, blank=True) @@ -37,9 +188,10 @@ class Employe(models.Model): ville = models.CharField(max_length=255, null=True, blank=True) province = models.CharField(max_length=255, null=True, blank=True) code_postal = models.CharField(max_length=255, null=True, blank=True) - pays = models.ForeignKey('datamaster_modeles.Pays', to_field='code', + pays = models.ForeignKey(ref.Pays, to_field='code', null=True, blank=True, related_name='employes', db_column='pays') + # Métas date_creation = models.DateField(auto_now_add=True) date_maj = models.DateField(auto_now=True) @@ -49,69 +201,6 @@ class Employe(models.Model): return u'%s %s' % (self.prenom, self.nom) -TYPE_DOSSIER_CHOICES = ( - ('2', 'Local'), - ('1', 'Expatrié'), -) - -class Dossier(models.Model): - # Identification - id = models.IntegerField(primary_key=True) - code = models.CharField(max_length=10, unique=True) - employe = models.ForeignKey('Employe', db_column='employe') - # Postes - poste1 = models.ForeignKey('Poste', db_column='poste1', - related_name='dossiers_poste1') - implantation1 = models.ForeignKey('datamaster_modeles.Implantation', - db_column='implantation1', - related_name='dossiers_implantation1', - blank=True, null=True) - complement1 = models.TextField(null=True, blank=True) - responsable_implantation1 = models.IntegerField() - poste2 = models.ForeignKey('Poste', db_column='poste2', - related_name='dossiers_poste2', - blank=True, null=True) - implantation2 = models.ForeignKey('datamaster_modeles.Implantation', - db_column='implantation2', - related_name='dossiers_implantation2', - null=True, blank=True) - complement2 = models.TextField(null=True, blank=True) - responsable_implantation2 = models.IntegerField() - # Relations - service = models.ForeignKey('Service', db_column='service', - blank=True, null=True) - responsable = models.ForeignKey('Employe', db_column='responsable', - related_name='responsable_de', - blank=True, null=True) - remplacement_de = models.ForeignKey('Employe', db_column='remplacement_de', - related_name='replaced_by', - blank=True, null=True) - type = models.CharField(max_length=1, choices=TYPE_DOSSIER_CHOICES) - statut = models.ForeignKey('Statut', db_column='statut', - blank=True, null=True) - organisme_bstg = models.ForeignKey('OrganismeBstg', - db_column='organisme_bstg', - blank=True, null=True) - # Rémunération - classement = models.ForeignKey('Classement', db_column='classement', - blank=True, null=True) - regime_travail = models.IntegerField() - # Mandat - mandat_date_debut = models.DateField() - mandat_date_fin = models.DateField(null=True, blank=True) - # Contrat - contrat_date_debut = models.DateField() - contrat_date_fin = models.DateField() - type_contrat = models.ForeignKey('TypeContrat', db_column='type_contrat', - blank=True, null=True) - # Meta - date_creation = models.DateField(auto_now_add=True) - date_maj = models.DateField(auto_now=True) - commentaire = models.TextField(null=True, blank=True) - - def __unicode__(self): - return u'%s : %s %s' % (self.employe, self.poste1, self.complement1) - LIEN_PARENTE_CHOICES = ( ('Conjoint', 'Conjoint'), ('Conjointe', 'Conjointe'), @@ -124,38 +213,139 @@ class AyantDroit(models.Model): id = models.IntegerField(primary_key=True) nom = models.CharField(max_length=255) prenom = models.CharField(max_length=255) + # Relation employe = models.ForeignKey('Employe', db_column='employe', related_name='ayants_droit') lien_parente = models.CharField(max_length=10, null=True, blank=True, choices=LIEN_PARENTE_CHOICES) + # Méta commentaire = models.TextField(null=True, blank=True) actif = models.BooleanField() + + +### DOSSIER + +STATUT_RESIDENCE_CHOICES = ( + ('local', 'Local'), + ('expat', 'Expatrié'), +) + +COMPTE_COMPTA_CHOICES = ( + ('coda', 'CODA'), + ('scs', 'SCS'), + ('aucun', 'Aucun'), +) + +class Dossier(models.Model): + # Identification + id = models.IntegerField(primary_key=True) + #code = models.CharField(max_length=10, unique=True) + employe = models.ForeignKey('Employe', db_column='employe') + poste = models.ForeignKey('Poste', related_name='+', editable=False) + #responsable_implantation1 = models.IntegerField() + statut = models.ForeignKey('Statut', related_name='+') # blank=True, null=True ? + organisme_bstg = models.ForeignKey('OrganismeBstg', + null=True, blank=True, + verbose_name="Organisme", + help_text="Si détaché (DET) ou mis à disposition (MAD), \ + préciser l'organisme.", + related_name='+') + organisme_bstg_autre = models.CharField(max_length=255, + verbose_name="Autre organisme", + help_text="indiquer l'organisme ici s'il n'est pas dans la liste", + null=True, + blank=True,) + + # Recrutement + remplacement = models.BooleanField() + #remplacement_de = models.ForeignKey('Employe', db_column='remplacement_de', +# related_name='replaced_by', +# blank=True, null=True) + statut_residence = models.CharField(max_length=10, default='local', + verbose_name="Statut", + choices=STATUT_RESIDENCE_CHOICES) + + # Rémunération + classement = models.ForeignKey(rh.Classement, related_name='+', + verbose_name='Classement proposé') + regime_travail = models.DecimalField(max_digits=12, decimal_places=2, + verbose_name="Régime de travail", + help_text="% du temps complet") + regime_travail_nb_heure_semaine = models.DecimalField(max_digits=12, + decimal_places=2, verbose_name="Nb. heures par semaine") + + # Mandat +# mandat_date_debut = models.DateField() +# mandat_date_fin = models.DateField(null=True, blank=True) + # Contrat + type_contrat = models.ForeignKey('TypeContrat', related_name='+') + contrat_date_debut = models.DateField(help_text="format: aaaa-mm-jj") + contrat_date_fin = models.DateField(null=True, blank=True, + help_text="format: aaaa-mm-jj") + # Comptes + compte_compta = models.CharField(max_length=10, default='aucun', + verbose_name=u'Compte comptabilité', + choices=COMPTE_COMPTA_CHOICES) + compte_courriel = models.BooleanField() + # Méta + date_creation = models.DateTimeField(auto_now_add=True) + date_modification = models.DateField(auto_now=True) + commentaire = models.TextField(null=True, blank=True) + + def __unicode__(self): + return u'%s - %s' % (self.poste.nom, self.employe) + +class DossierPiece(models.Model): + dossier = models.ForeignKey("Dossier") + nom = models.CharField(verbose_name="Nom", max_length=255) + fichier = models.FileField(verbose_name="Fichier", + upload_to=dossier_piece_dispatch, + storage=storage_prive) + + +### RÉMUNÉRATION class Remuneration(models.Model): # Identification id = models.IntegerField(primary_key=True) dossier = models.ForeignKey('Dossier', db_column='dossier') - type = models.ForeignKey('TypeRemuneration', db_column='type') - type_revalorisation = models.ForeignKey('TypeRevalorisation', - db_column='type_revalorisation', - null=True, blank=True) - montant = models.FloatField(null=True, blank=True) - devise = models.ForeignKey('Devise', to_field='code', db_column='devise', - null=True, blank=True) - date_effective = models.DateField(null=True, blank=True) - pourcentage = models.IntegerField(null=True, blank=True) + type = models.ForeignKey('TypeRemuneration', db_column='type', + related_name='+') + # TODO: what's that? +# type_revalorisation = models.ForeignKey('TypeRevalorisation', +# db_column='type_revalorisation', +# null=True, blank=True) + montant = models.FloatField(null=True, blank=True) # Annuel + devise = models.ForeignKey('Devise', to_field='code', db_column='devise')#, + #null=True, blank=True) + precision = models.CharField(max_length=255, null=True, blank=True) + #date_effective = models.DateField(null=True, blank=True) + #pourcentage = models.IntegerField(null=True, blank=True) + # Méta date_creation = models.DateField(auto_now_add=True) user_creation = models.IntegerField(null=True, blank=True) #User ou employé - desactivation = models.BooleanField(null=True, blank=True) # - date_desactivation = models.DateField(null=True, blank=True) - user_desactivation = models.IntegerField(null=True, blank=True) #User ou employé - annulation = models.BooleanField(null=True, blank=True) - date_annulation = models.DateField(null=True, blank=True) - user_annulation = models.IntegerField(null=True, blank=True) #User ou employé +# desactivation = models.BooleanField(null=True, blank=True) # +# date_desactivation = models.DateField(null=True, blank=True) +# user_desactivation = models.IntegerField(null=True, blank=True) #User ou employé +# annulation = models.BooleanField(null=True, blank=True) +# date_annulation = models.DateField(null=True, blank=True) +# user_annulation = models.IntegerField(null=True, blank=True) #User ou employé + + def montant_mois(self): + return round(self.montant / 12, 2) + + def taux_devise(self): + return self.devise.tauxchange_set.order_by('-annee').all()[0].taux + + def montant_euro(self): + return round(float(self.montant) / float(self.taux_devise()), 2) + + def montant_euro_mois(self): + return round(self.montant_euro() / 12, 2) def __unicode__(self): try: @@ -163,7 +353,35 @@ class Remuneration(models.Model): except: devise = "???" return "%s %s" % (self.montant, devise) + + +### JUSTIFICATIONS + +TYPE_JUSTIFICATIONS = ( + ('N', 'Nouvel employé'), + ('R', 'Renouvellement employé'), +) + +class JustificationQuestion(models.Model): + question = models.CharField(max_length=255) + type = models.CharField(max_length=255, choices=TYPE_JUSTIFICATIONS) + def __unicode__(self,): + return self.question + +class JustificationNouvelEmploye(models.Model): + dossier = models.ForeignKey("Dossier") + question = models.ForeignKey("JustificationQuestion") + reponse = models.TextField() + +class JustificationAutreEmploye(models.Model): + dossier = models.ForeignKey("Dossier") + question = models.ForeignKey("JustificationQuestion") + reponse = models.TextField() + + +### RÉFÉRENCES RH + class FamilleEmploi(models.Model): # Identification id = models.IntegerField(primary_key=True) @@ -222,29 +440,6 @@ class TypeRevalorisation(models.Model): # Méta actif = models.BooleanField() -PROPORTION_CHOICES = ( - ('0.5', '0.5'), - ('1', '1'), -) - -class Poste(models.Model): - # Identification - id = models.IntegerField(primary_key=True) - implantation = models.ForeignKey('datamaster_modeles.Implantation', - db_column='implantation', related_name='postes') - type_poste = models.ForeignKey('TypePoste', db_column='type_poste') - proportion = models.CharField(max_length=10, choices=PROPORTION_CHOICES) - #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%) - # Méta - date_modification = models.DateField(auto_now=True) - actif = models.BooleanField() - - - def __unicode__(self): - return u'%s - %s [%s]' % (self.implantation, self.type_poste.nom, - self.id) - - class Service(models.Model): # Identification id = models.IntegerField(primary_key=True) @@ -278,10 +473,12 @@ class OrganismeBstg(models.Model): class Meta: ordering = ['type', 'nom'] + CONTRAT_CATEGORIE_CHOICES= ( ('A', 'A'), ('C', 'C'), ) + class Statut(models.Model): # Identification id = models.IntegerField(primary_key=True) @@ -296,10 +493,12 @@ class Statut(models.Model): def __unicode__(self): return u'%s : %s' % (self.code, self.nom) + TYPE_CLASSEMENT_CHOICES = ( ('S', 'S'), ('T', 'T'), ) + class Classement(models.Model): # Identification id = models.IntegerField(primary_key=True) @@ -318,7 +517,6 @@ class Classement(models.Model): class Meta: ordering = ['type','echelon','degre','coefficient'] - class TauxChange(models.Model): # Identification id = models.IntegerField(primary_key=True) @@ -326,16 +524,15 @@ class TauxChange(models.Model): annee = models.IntegerField() taux = models.FloatField() # Relations - implantation = models.ForeignKey('datamaster_modeles.Implantation', + implantation = models.ForeignKey(ref.Implantation, db_column='implantation', related_name='taux_change') - class ValeurPoint(models.Model): # Identification id = models.IntegerField(primary_key=True) valeur = models.FloatField() - implantation = models.ForeignKey('datamaster_modeles.Implantation', + implantation = models.ForeignKey(ref.Implantation, db_column='implantation', related_name='valeurs_point') # Méta @@ -356,7 +553,6 @@ class ValeurPoint(models.Model): class Meta: ordering = ['valeur'] - class Devise(models.Model): id = models.IntegerField(primary_key=True) code = models.CharField(max_length=10, unique=True) @@ -365,7 +561,6 @@ class Devise(models.Model): def __unicode__(self): return u'%s - %s' % (self.code, self.nom) - class TypeContrat(models.Model): # Identification id = models.IntegerField(primary_key=True) -- 1.7.10.4