Merge remote branch 'origin/dev' into dae
[auf_rh_dae.git] / project / dae / models.py
CommitLineData
bd28238f 1# -=- encoding: utf-8 -=-
3f3cf5f3 2from django.db import models
3
bd28238f 4import datamaster_modeles.models as ref
5d680e84 5import project.rh_v1.models as rh
bd28238f
NC
6
7
8STATUT_RESIDENCE_CHOICES = (
5d680e84
NC
9 ('local', 'Local'),
10 ('expat', 'Expatrié'),
bd28238f
NC
11)
12
13POSTE_APPEL_CHOICES = (
5d680e84
NC
14 ('interne', 'Interne'),
15 ('externe', 'Externe'),
bd28238f
NC
16)
17
18POSTE_STATUT_CHOICES = (
19 ('MAD', 'Mise à disposition'),
20 ('DET', 'Détachement'),
21)
22
23
24class Poste(models.Model):
bd28238f 25 # Modèle existant
5d680e84
NC
26 id_rh = models.ForeignKey(rh.Poste, null=True, related_name='+',
27 editable=False)
bd28238f 28 nom = models.CharField(max_length=255)
5d680e84
NC
29 implantation = models.ForeignKey(ref.Implantation)
30 type_poste = models.ForeignKey(rh.TypePoste, null=True, related_name='+')
31 service = models.ForeignKey(rh.Service, related_name='+')
32 responsable = models.ForeignKey(rh.Poste, related_name='+')
33 regime_travail = models.DecimalField(max_digits=12, decimal_places=2,
34 default=100)
35 regime_travail_nb_heure_semaine = models.DecimalField(max_digits=12,
36 decimal_places=2,
37 default=40)
bd28238f
NC
38
39 # Recrutement
5d680e84 40 statut_residence = models.CharField(max_length=10, default='MAD',
bd28238f 41 choices=STATUT_RESIDENCE_CHOICES)
5d680e84
NC
42 # TODO null?
43 mise_a_disposition = models.BooleanField()
44 appel = models.CharField(max_length=10, default='interne',
45 choices=POSTE_APPEL_CHOICES)
bd28238f
NC
46
47 # Rémunération
5d680e84
NC
48 classement_min = models.ForeignKey(rh.Classement, related_name='+')
49 classement_max = models.ForeignKey(rh.Classement, related_name='+')
50 valeur_point_min = models.ForeignKey(rh.ValeurPoint, related_name='+')
51 valeur_point_max = models.ForeignKey(rh.ValeurPoint, related_name='+')
52 salaire_min = models.DecimalField(max_digits=12, decimal_places=2,
53 default=0)
54 salaire_max = models.DecimalField(max_digits=12, decimal_places=2,
55 default=0)
56 indemn_min = models.DecimalField(max_digits=12, decimal_places=2,
57 default=0)
58 indemn_max = models.DecimalField(max_digits=12, decimal_places=2,
59 default=0)
60 autre_min = models.DecimalField(max_digits=12, decimal_places=2,
61 default=0)
62 autre_max = models.DecimalField(max_digits=12, decimal_places=2,
63 default=0)
64
65 # Comparatifs de rémunération
66 devise_comparaison = models.ForeignKey(rh.Devise, related_name='+',
67 null=True, blank=True)
68 comp_locale_min = models.DecimalField(max_digits=12, decimal_places=2,
69 null=True, blank=True)
70 comp_locale_max = models.DecimalField(max_digits=12, decimal_places=2,
71 null=True, blank=True)
72 comp_universite_min = models.DecimalField(max_digits=12, decimal_places=2,
73 null=True, blank=True)
74 comp_universite_max = models.DecimalField(max_digits=12, decimal_places=2,
75 null=True, blank=True)
76 comp_fonctionpub_min = models.DecimalField(max_digits=12, decimal_places=2,
77 null=True, blank=True)
78 comp_fonctionpub_max = models.DecimalField(max_digits=12, decimal_places=2,
79 null=True, blank=True)
80 comp_ong_min = models.DecimalField(max_digits=12, decimal_places=2,
81 null=True, blank=True)
82 comp_ong_max = models.DecimalField(max_digits=12, decimal_places=2,
83 null=True, blank=True)
84 comp_autre_min = models.DecimalField(max_digits=12, decimal_places=2,
85 null=True, blank=True)
86 comp_autre_max = models.DecimalField(max_digits=12, decimal_places=2,
87 null=True, blank=True)
bd28238f
NC
88
89 # Méta
5d680e84
NC
90 date_creation = models.DateTimeField(auto_now_add=True)
91 date_modification = models.DateTimeField(auto_now=True)
24d44b1b
OL
92 date_debut = models.DateField(help_text="format: aaaa-mm-jj")
93 date_fin = models.DateField(null=True, help_text="format: aaaa-mm-jj")
bd28238f
NC
94 actif = models.BooleanField(default=True)
95
5d680e84
NC
96 def __unicode__(self):
97 return u'%s - %s (%s)' % (self.implantation, self.type_poste.nom,
98 self.nom)
99
100 def DISABLED_save(self, *args, **kwargs):
bd28238f
NC
101 # calculate nb_mois = nb of months between date_debut and date_fin
102 from datetime import date
bd28238f
NC
103 if not self.salaire_min:
104 self.salaire_min = self.classement_min * self.valeur_point_min
105 if not self.salaire_max:
106 self.salaire_max = self.classement_max * self.valeur_point_min
107 if not self.valeur_point_min:
108 self.valeur_point_min = \
109 rh.ValeurPoint.objects.filter(implantation=self.implantation)
110 if not self.valeur_point_max:
111 self.valeur_point_max = \
112 rh.ValeurPoint.objects.filter(implantation=self.implantation)
113 super(Subject, self).save(*args, **kwargs)
114
115
5d680e84
NC
116POSTE_FINANCEMENT_CHOICES = (
117 ('A', 'A - Frais de personnel'),
118 ('B', 'B - Projet(s)-Titre(s)'),
119 ('C', 'C - Autre')
120)
bd28238f
NC
121
122
5d680e84
NC
123class PosteFinancement(models.Model):
124 montant = models.DecimalField(max_digits=12, decimal_places=2)
125 poste = models.ForeignKey('Poste', related_name='financements')
126 type = models.CharField(max_length=1, choices=POSTE_FINANCEMENT_CHOICES)
127 pourcentage = models.DecimalField(max_digits=12, decimal_places=2)
128 commentaire = models.TextField()
bd28238f
NC
129
130
131GENRE_CHOICES = (
bc2848da
NC
132 ('M', 'Homme'),
133 ('F', 'Femme'),
bd28238f
NC
134)
135
136
137class Employe(models.Model):
138 id = models.IntegerField(primary_key=True)
139
140 # Modèle existant
5d680e84 141 id_rh = models.ForeignKey(rh.Employe, null=True, related_name='+')
bd28238f
NC
142 nom = models.CharField(max_length=255)
143 prenom = models.CharField(max_length=255)
494ff2be
NC
144 genre = models.CharField(max_length=1, choices=GENRE_CHOICES,
145 null=True, blank=True)
bd28238f
NC
146
147
148COMPTE_COMPTA_CHOICES = (
494ff2be
NC
149 ('coda', 'CODA'),
150 ('scs', 'SCS'),
151 ('aucun', 'Aucun'),
bd28238f
NC
152)
153
154
155class Dossier(models.Model):
bd28238f
NC
156
157 # Modèle existant
494ff2be
NC
158 employe = models.ForeignKey('Employe', related_name='+')
159 poste = models.ForeignKey('Poste', related_name='+')
5d680e84
NC
160 statut = models.ForeignKey(rh.Statut, related_name='+')
161 organisme_bstg = models.ForeignKey(rh.OrganismeBstg, related_name='+')
bd28238f 162
494ff2be
NC
163 # Données antérieures
164 employe_anterieur = models.ForeignKey('Employe', related_name='+')
165 statut_anterieur = models.ForeignKey(rh.Statut, related_name='+')
166 classement_anterieur = models.ForeignKey(rh.Classement, related_name='+',
167 verbose_name='Classement proposé')
168 salaire_anterieur = models.DecimalField(max_digits=12, decimal_places=2,
169 verbose_name='Salaire de base',
170 null=True, default=None)
171
bd28238f
NC
172 # Recrutement
173 remplacement = models.BooleanField()
bd28238f
NC
174 statut_residence = models.CharField(max_length=10,
175 choices=STATUT_RESIDENCE_CHOICES)
176
177 # Rémunération
494ff2be
NC
178 classement = models.ForeignKey(rh.Classement, related_name='+',
179 verbose_name='Classement proposé')
180 salaire = models.DecimalField(max_digits=12, decimal_places=2,
bd28238f 181 verbose_name='Salaire de base',
494ff2be 182 null=True, default=None)
5d680e84
NC
183 devise = models.ForeignKey(rh.Devise, related_name='+')
184 regime_travail = models.DecimalField(max_digits=12, decimal_places=2)
bd28238f 185 regime_travail_nb_heure_semaine = \
5d680e84 186 models.DecimalField(max_digits=12, decimal_places=2)
bd28238f
NC
187
188 # Contrat
5d680e84 189 type_contrat = models.ForeignKey(rh.TypeContrat, related_name='+')
bd28238f
NC
190 contrat_date_debut = models.DateField()
191 contrat_date_fin = models.DateField()
bd28238f
NC
192
193 # Comptes
194 compte_compta = models.CharField(max_length=10,
195 choices=COMPTE_COMPTA_CHOICES)
196 compte_courriel = models.BooleanField()
197
198
199class Remuneration(models.Model):
5d680e84 200 # Identification
bd28238f
NC
201 id = models.IntegerField(primary_key=True)
202 dossier = models.ForeignKey('Dossier', db_column='dossier')
203 type = models.ForeignKey('TypeRemuneration', db_column='type')
5d680e84
NC
204 # TODO: what's that?
205 # type_revalorisation = models.ForeignKey('TypeRevalorisation',
206 # db_column='type_revalorisation')
494ff2be
NC
207 montant = models.DecimalField(max_digits=12, decimal_places=2) # Annuel
208 devise = models.ForeignKey(rh.Devise, to_field='code',
5d680e84 209 db_column='devise', related_name='+')
494ff2be
NC
210 date_effective = models.DateField(null=True, blank=True)
211 pourcentage = models.IntegerField(null=True, blank=True)
bd28238f 212
5d680e84 213 # Méta
bd28238f 214 date_creation = models.DateField(auto_now_add=True)
494ff2be
NC
215 user_creation = models.IntegerField(null=True, blank=True)
216 desactivation = models.BooleanField(null=True, blank=True)
217 date_desactivation = models.DateField(null=True, blank=True)
218 user_desactivation = models.IntegerField(null=True, blank=True)
219 annule = models.BooleanField(null=True, blank=True)
220 date_annule = models.DateField(null=True, blank=True)
221 user_annule = models.IntegerField(null=True, blank=True)
bd28238f
NC
222
223
224class JustificationPoste(models.Model):
225 pass
226
227
228class JustificationEmploye(models.Model):
229 pass
230
231
232class DocumentPoste(models.Model):
233 pass
234
235
236class DocumentEmploye(models.Model):
237 pass
238
239
240class Validation(models.Model):
241 # user
242 date = models.DateField()
243
244 # avis = ? (CHOICES?)
245
246
247class ValidationPoste(models.Model):
248 poste = models.ForeignKey('Poste')
249
250
251class ValidationEmploye(models.Model):
252 employe = models.ForeignKey('Employe')
253
254
255class TypeRemuneration(models.Model):
256 ordre = models.IntegerField()
257 groupe = models.ForeignKey('GroupeTypeRemuneration')
258
259
260class GroupeTypeRemuneration(models.Model):
261 nom = models.CharField(max_length=255)
262 ordre = models.IntegerField()