X-Git-Url: http://git.auf.org/?p=auf_rh_dae.git;a=blobdiff_plain;f=project%2Frh%2Fmodels.py;h=91fd591591ac2d4806990d1bbec679cc7fdc066f;hp=4e2b51ef16dcae85658e08982d9d009a173c676b;hb=9afaa55e963f04472e89c29167eadaeaf763723b;hpb=f2a9bc7a4c59ab544c716761d71445fc433af79d diff --git a/project/rh/models.py b/project/rh/models.py index 4e2b51e..91fd591 100644 --- a/project/rh/models.py +++ b/project/rh/models.py @@ -1,5 +1,6 @@ # -=- encoding: utf-8 -=- +import datetime from django.db import models from datamaster_modeles.models import Pays, Implantation @@ -14,17 +15,21 @@ SITUATION_CHOICES = ( ) class Employe(models.Model): - #Identification + # 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', related_name='employes_nationalite', db_column='nationalite') + nationalite = models.ForeignKey('datamaster_modeles.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, choices=GENRE_CHOICES, null=True, blank=True) - situation_famille = models.CharField(max_length=1, choices=SITUATION_CHOICES, 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 + # Coordonnées tel_domicile = models.CharField(max_length=255, null=True, blank=True) tel_cellulaire = models.CharField(max_length=255, null=True, blank=True) adresse = models.CharField(max_length=255, null=True, blank=True) @@ -32,52 +37,80 @@ 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', null=True, blank=True, related_name='employes', db_column='pays') - #Métas + pays = models.ForeignKey('datamaster_modeles.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) commentaire = models.TextField(null=True, blank=True) - + + def __unicode__(self): + return u'%s %s' % (self.prenom, self.nom) + + TYPE_DOSSIER_CHOICES = ( ('2', 'Local'), ('1', 'Expatrié'), ) class Dossier(models.Model): - #Identification + # 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') + # 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') + 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') - responsable = models.ForeignKey('Employe', db_column='responsable', related_name='responsable_de') - remplacement_de = models.ForeignKey('Employe', db_column='remplacement_de', related_name='replaced_by') + # 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') - organisme_bstg = models.ForeignKey('OrganismeBstg', db_column='organisme_bstg') - #Rémunération - classement = models.ForeignKey('Classement', db_column='classement') + 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 mandat_date_debut = models.DateField() - mandat_date_fin = models.DateField() - #Contrat + 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') - #Meta + 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'), @@ -87,54 +120,67 @@ LIEN_PARENTE_CHOICES = ( ) class AyantDroit(models.Model): - #Identification + # Identification 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, choices=LIEN_PARENTE_CHOICES, null=True, blank=True) - #Méta + # 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() class Remuneration(models.Model): - #Identification + # 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') - montant = models.FloatField() - devise = models.ForeignKey('Devise', to_field='code', db_column='devise') - date_effective = models.DateField() - pourcentage = models.IntegerField() - #Méta + 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) + # Méta date_creation = models.DateField(auto_now_add=True) - user_creation = models.IntegerField() #User ou employé - desactivation = models.BooleanField() # - date_desactivation = models.DateField() - user_desactivation = models.IntegerField() #User ou employé - annule = models.BooleanField() - date_annule = models.DateField() - user_annule = models.IntegerField() #User ou employé + 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é + + def __unicode__(self): + try: + devise = self.devise.code + except: + devise = "???" + return "%s %s" % (self.montant, devise) class FamilleEmploi(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) nom = models.CharField(max_length=255) - #Méta + # Méta actif = models.BooleanField() class TypePoste(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) nom = models.CharField(max_length=255) nom_feminin = models.CharField(max_length=255) description = models.CharField(max_length=255) is_responsable = models.BooleanField() - famille_emploi = models.ForeignKey('FamilleEmploi', db_column='famille_emploi') - #Méta + famille_emploi = models.ForeignKey('FamilleEmploi', + db_column='famille_emploi') + # Méta date_modification = models.DateField(auto_now=True) actif = models.BooleanField() @@ -156,19 +202,24 @@ NATURE_REMUNERATION_CHOICES = ( ) class TypeRemuneration(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) nom = models.CharField(max_length=255) - type_paiement = models.CharField(max_length=30, choices=TYPE_PAIEMENT_CHOICES) - nature_remuneration = models.CharField(max_length=30, choices=NATURE_REMUNERATION_CHOICES) - #Méta + type_paiement = models.CharField(max_length=30, + choices=TYPE_PAIEMENT_CHOICES) + nature_remuneration = models.CharField(max_length=30, + choices=NATURE_REMUNERATION_CHOICES) + # Méta actif = models.BooleanField() + + def __unicode__(self): + return u'%s' % self.nom class TypeRevalorisation(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) nom = models.CharField(max_length=255) - #Méta + # Méta actif = models.BooleanField() PROPORTION_CHOICES = ( @@ -177,30 +228,35 @@ PROPORTION_CHOICES = ( ) class Poste(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) implantation = models.ForeignKey('datamaster_modeles.Implantation', - db_column='implantation', related_name='postes') + 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 + # Méta date_modification = models.DateField(auto_now=True) actif = models.BooleanField() + def __unicode__(self): - return u'%s - %s' % (self.implantation, self.type_poste.nom) + return u'%s - %s [%s]' % (self.implantation, self.type_poste.nom, + self.id) class Service(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) nom = models.CharField(max_length=255) - #Méta + # Méta actif = models.BooleanField() def __unicode__(self): return u'%s' % self.nom + + class Meta: + ordering = ['nom'] TYPE_ORGANISME_CHOICES = ( @@ -209,39 +265,49 @@ TYPE_ORGANISME_CHOICES = ( ) class OrganismeBstg(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) nom = models.CharField(max_length=255) type = models.CharField(max_length=10, choices=TYPE_ORGANISME_CHOICES) - #Méta + # Méta actif = models.BooleanField() + def __unicode__(self): + return u'%s (%s)' % (self.nom, self.type) + + class Meta: + ordering = ['type', 'nom'] + CONTRAT_CATEGORIE_CHOICES= ( ('A', 'A'), ('C', 'C'), ) class Statut(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) code = models.CharField(max_length=25, unique=True) nom = models.CharField(max_length=255) - type_contrat_categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES) + type_contrat_categorie = models.CharField(max_length=10, + choices=CONTRAT_CATEGORIE_CHOICES) #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie - #Méta + # Méta actif = models.BooleanField() + def __unicode__(self): + return u'%s : %s' % (self.code, self.nom) + TYPE_CLASSEMENT_CHOICES = ( ('S', 'S'), ('T', 'T'), ) class Classement(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) type = models.CharField(max_length=10, choices=TYPE_CLASSEMENT_CHOICES) echelon = models.IntegerField() degre = models.IntegerField() coefficient = models.FloatField() - #Méta + # Méta commentaire = models.TextField(null=True, blank=True) date_modification = models.DateField(auto_now=True) actif = models.BooleanField() @@ -249,28 +315,46 @@ class Classement(models.Model): def __unicode__(self): return u'%s.%s.%s (%s)' % (self.type, self.echelon, self.degre, self.coefficient) + class Meta: + ordering = ['type','echelon','degre','coefficient'] -class ValeurPoint(models.Model): - #Identification +class TauxChange(models.Model): + # Identification id = models.IntegerField(primary_key=True) - valeur = models.FloatField() - implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation', related_name='valeurs_point') - #Méta + devise = models.ForeignKey('Devise', to_field='code', db_column='devise') annee = models.IntegerField() - - def __unicode__(self): - return u'%s (%s-%s)' % (self.valeur, self.implantation_id, self.annee) + taux = models.FloatField() + # Relations + implantation = models.ForeignKey('datamaster_modeles.Implantation', + db_column='implantation', + related_name='taux_change') -class TauxChange(models.Model): - #Identification +class ValeurPoint(models.Model): + # Identification id = models.IntegerField(primary_key=True) - devise = models.ForeignKey('Devise', to_field='code', db_column='devise') + valeur = models.FloatField() + implantation = models.ForeignKey('datamaster_modeles.Implantation', + db_column='implantation', + related_name='valeurs_point') + # Méta annee = models.IntegerField() - taux = models.FloatField() - #Relations - implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation', related_name='taux_change') + + # Stockage de tous les taux de change pour optimiser la recherche de la devise associée + annee_courante = datetime.datetime.now().year + tauxchange = TauxChange.objects.select_related('devise').filter(annee=annee_courante) + + def __unicode__(self): + tx = self.get_tauxchange_courant() + if tx: + devise_code = tx.devise.code + else: + devise_code = "??" + return u'%s %s (%s-%s)' % (self.valeur, devise_code, self.implantation_id, self.annee) + + class Meta: + ordering = ['valeur'] class Devise(models.Model): @@ -283,11 +367,14 @@ class Devise(models.Model): class TypeContrat(models.Model): - #Identification + # Identification id = models.IntegerField(primary_key=True) nom = models.CharField(max_length=255) nom_long = models.CharField(max_length=255) #description - categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES) - #Méta + categorie = models.CharField(max_length=10, + choices=CONTRAT_CATEGORIE_CHOICES) + # Méta actif = models.BooleanField() + def __unicode__(self): + return u'%s' % (self.nom)