Commit | Line | Data |
---|---|---|
bd28238f | 1 | # -=- encoding: utf-8 -=- |
3f3cf5f3 | 2 | from django.db import models |
3 | ||
bd28238f | 4 | import datamaster_modeles.models as ref |
5d680e84 | 5 | import project.rh_v1.models as rh |
bd28238f NC |
6 | |
7 | ||
8 | STATUT_RESIDENCE_CHOICES = ( | |
5d680e84 NC |
9 | ('local', 'Local'), |
10 | ('expat', 'Expatrié'), | |
bd28238f NC |
11 | ) |
12 | ||
13 | POSTE_APPEL_CHOICES = ( | |
5d680e84 NC |
14 | ('interne', 'Interne'), |
15 | ('externe', 'Externe'), | |
bd28238f NC |
16 | ) |
17 | ||
18 | POSTE_STATUT_CHOICES = ( | |
19 | ('MAD', 'Mise à disposition'), | |
20 | ('DET', 'Détachement'), | |
21 | ) | |
22 | ||
23 | ||
1c7d67ce OL |
24 | class PosteManager(models.Manager): |
25 | """ | |
26 | Chargement de tous les objets FK existants sur chaque QuerySet. | |
27 | """ | |
28 | def get_query_set(self): | |
29 | fkeys = ( | |
30 | 'id_rh', | |
31 | 'responsable', | |
32 | 'implantation', | |
33 | 'type_poste', | |
34 | 'service', | |
35 | 'classement_min', | |
36 | 'classement_max', | |
37 | 'valeur_point_min', | |
38 | 'valeur_point_max', | |
39 | ) | |
98d51b59 NC |
40 | return super(PosteManager, self).get_query_set() \ |
41 | .select_related(*fkeys).all() | |
1c7d67ce OL |
42 | |
43 | ||
bd28238f | 44 | class Poste(models.Model): |
bd28238f | 45 | # Modèle existant |
5d680e84 | 46 | id_rh = models.ForeignKey(rh.Poste, null=True, related_name='+', |
98d51b59 NC |
47 | editable=False, |
48 | verbose_name="Mise à jour du poste") | |
ce110fb9 | 49 | nom = models.CharField(verbose_name="Titre du poste", max_length=255) |
5d680e84 NC |
50 | implantation = models.ForeignKey(ref.Implantation) |
51 | type_poste = models.ForeignKey(rh.TypePoste, null=True, related_name='+') | |
98d51b59 NC |
52 | service = models.ForeignKey(rh.Service, related_name='+', |
53 | verbose_name=u"Direction/Service/Pôle support") | |
54 | responsable = models.ForeignKey(rh.Poste, related_name='+', | |
5efcd48e | 55 | verbose_name="Poste du responsable") |
9a85768a | 56 | |
5d680e84 | 57 | regime_travail = models.DecimalField(max_digits=12, decimal_places=2, |
5efcd48e | 58 | default=100, |
59 | verbose_name="Temps de travail", | |
60 | help_text="% du temps complet") | |
5d680e84 | 61 | regime_travail_nb_heure_semaine = models.DecimalField(max_digits=12, |
5efcd48e | 62 | decimal_places=2, |
63 | default=40, | |
64 | verbose_name="Nb. heures par semaine") | |
bd28238f NC |
65 | |
66 | # Recrutement | |
98d51b59 | 67 | statut_residence = models.CharField(max_length=10, default='MAD', |
5efcd48e | 68 | verbose_name="Statut", |
bd28238f | 69 | choices=STATUT_RESIDENCE_CHOICES) |
5d680e84 NC |
70 | # TODO null? |
71 | mise_a_disposition = models.BooleanField() | |
98d51b59 NC |
72 | appel = models.CharField(max_length=10, default='interne', |
73 | verbose_name="Appel à candidature", | |
5d680e84 | 74 | choices=POSTE_APPEL_CHOICES) |
bd28238f NC |
75 | |
76 | # Rémunération | |
5d680e84 NC |
77 | classement_min = models.ForeignKey(rh.Classement, related_name='+') |
78 | classement_max = models.ForeignKey(rh.Classement, related_name='+') | |
96d32304 | 79 | coefficient_min = models.FloatField(null=True) # pour classement "hors grille" |
80 | coefficient_max = models.FloatField(null=True) # pour classement "hors grille" | |
5d680e84 NC |
81 | valeur_point_min = models.ForeignKey(rh.ValeurPoint, related_name='+') |
82 | valeur_point_max = models.ForeignKey(rh.ValeurPoint, related_name='+') | |
83 | salaire_min = models.DecimalField(max_digits=12, decimal_places=2, | |
84 | default=0) | |
85 | salaire_max = models.DecimalField(max_digits=12, decimal_places=2, | |
86 | default=0) | |
87 | indemn_min = models.DecimalField(max_digits=12, decimal_places=2, | |
88 | default=0) | |
89 | indemn_max = models.DecimalField(max_digits=12, decimal_places=2, | |
90 | default=0) | |
91 | autre_min = models.DecimalField(max_digits=12, decimal_places=2, | |
92 | default=0) | |
93 | autre_max = models.DecimalField(max_digits=12, decimal_places=2, | |
94 | default=0) | |
95 | ||
96 | # Comparatifs de rémunération | |
97 | devise_comparaison = models.ForeignKey(rh.Devise, related_name='+', | |
98 | null=True, blank=True) | |
99 | comp_locale_min = models.DecimalField(max_digits=12, decimal_places=2, | |
100 | null=True, blank=True) | |
101 | comp_locale_max = models.DecimalField(max_digits=12, decimal_places=2, | |
102 | null=True, blank=True) | |
103 | comp_universite_min = models.DecimalField(max_digits=12, decimal_places=2, | |
104 | null=True, blank=True) | |
105 | comp_universite_max = models.DecimalField(max_digits=12, decimal_places=2, | |
106 | null=True, blank=True) | |
107 | comp_fonctionpub_min = models.DecimalField(max_digits=12, decimal_places=2, | |
108 | null=True, blank=True) | |
109 | comp_fonctionpub_max = models.DecimalField(max_digits=12, decimal_places=2, | |
110 | null=True, blank=True) | |
111 | comp_ong_min = models.DecimalField(max_digits=12, decimal_places=2, | |
112 | null=True, blank=True) | |
113 | comp_ong_max = models.DecimalField(max_digits=12, decimal_places=2, | |
114 | null=True, blank=True) | |
115 | comp_autre_min = models.DecimalField(max_digits=12, decimal_places=2, | |
116 | null=True, blank=True) | |
117 | comp_autre_max = models.DecimalField(max_digits=12, decimal_places=2, | |
118 | null=True, blank=True) | |
bd28238f NC |
119 | |
120 | # Méta | |
5d680e84 NC |
121 | date_creation = models.DateTimeField(auto_now_add=True) |
122 | date_modification = models.DateTimeField(auto_now=True) | |
98d51b59 | 123 | date_debut = models.DateField(verbose_name="Date de début", |
9fb2ccd9 | 124 | help_text="format: aaaa-mm-jj") |
125 | date_fin = models.DateField(null=True, blank=True, | |
126 | verbose_name="Date de fin", | |
127 | help_text="format: aaaa-mm-jj") | |
bd28238f NC |
128 | actif = models.BooleanField(default=True) |
129 | ||
1c7d67ce OL |
130 | # Managers |
131 | objects = PosteManager() | |
132 | ||
5d680e84 | 133 | def __unicode__(self): |
6d704629 | 134 | return u'%s - %s (%s) [dae-%s]' % (self.implantation, self.type_poste.nom, |
135 | self.nom, self.id) | |
5d680e84 NC |
136 | |
137 | def DISABLED_save(self, *args, **kwargs): | |
bd28238f NC |
138 | # calculate nb_mois = nb of months between date_debut and date_fin |
139 | from datetime import date | |
bd28238f NC |
140 | if not self.salaire_min: |
141 | self.salaire_min = self.classement_min * self.valeur_point_min | |
142 | if not self.salaire_max: | |
143 | self.salaire_max = self.classement_max * self.valeur_point_min | |
144 | if not self.valeur_point_min: | |
145 | self.valeur_point_min = \ | |
146 | rh.ValeurPoint.objects.filter(implantation=self.implantation) | |
147 | if not self.valeur_point_max: | |
148 | self.valeur_point_max = \ | |
149 | rh.ValeurPoint.objects.filter(implantation=self.implantation) | |
150 | super(Subject, self).save(*args, **kwargs) | |
151 | ||
152 | ||
5d680e84 NC |
153 | POSTE_FINANCEMENT_CHOICES = ( |
154 | ('A', 'A - Frais de personnel'), | |
155 | ('B', 'B - Projet(s)-Titre(s)'), | |
156 | ('C', 'C - Autre') | |
157 | ) | |
bd28238f NC |
158 | |
159 | ||
5d680e84 | 160 | class PosteFinancement(models.Model): |
43d04712 | 161 | montant = models.DecimalField(max_digits=12, decimal_places=2, |
162 | help_text="ex.: 12000.00 € (décimale avec point, devise = EUR)") | |
5d680e84 NC |
163 | poste = models.ForeignKey('Poste', related_name='financements') |
164 | type = models.CharField(max_length=1, choices=POSTE_FINANCEMENT_CHOICES) | |
43d04712 | 165 | pourcentage = models.DecimalField(max_digits=12, decimal_places=2, |
166 | help_text="ex.: 33.33 % (décimale avec point)") | |
167 | commentaire = models.TextField( | |
168 | help_text="Spécifiez la source de financement.") | |
bd28238f | 169 | |
43d04712 | 170 | class Meta: |
171 | ordering = ['type'] | |
bd28238f NC |
172 | |
173 | GENRE_CHOICES = ( | |
139686f2 NC |
174 | ('m', 'Homme'), |
175 | ('f', 'Femme'), | |
bd28238f NC |
176 | ) |
177 | ||
178 | ||
179 | class Employe(models.Model): | |
bd28238f NC |
180 | |
181 | # Modèle existant | |
5d680e84 | 182 | id_rh = models.ForeignKey(rh.Employe, null=True, related_name='+') |
bd28238f NC |
183 | nom = models.CharField(max_length=255) |
184 | prenom = models.CharField(max_length=255) | |
494ff2be NC |
185 | genre = models.CharField(max_length=1, choices=GENRE_CHOICES, |
186 | null=True, blank=True) | |
bd28238f | 187 | |
139686f2 NC |
188 | def __unicode__(self): |
189 | return u'%s %s' % (self.prenom, self.nom) | |
190 | ||
bd28238f NC |
191 | |
192 | COMPTE_COMPTA_CHOICES = ( | |
494ff2be NC |
193 | ('coda', 'CODA'), |
194 | ('scs', 'SCS'), | |
195 | ('aucun', 'Aucun'), | |
bd28238f NC |
196 | ) |
197 | ||
198 | ||
199 | class Dossier(models.Model): | |
bd28238f NC |
200 | |
201 | # Modèle existant | |
139686f2 NC |
202 | employe = models.ForeignKey('Employe', related_name='+', editable=False) |
203 | poste = models.ForeignKey('Poste', related_name='+', editable=False) | |
5d680e84 NC |
204 | statut = models.ForeignKey(rh.Statut, related_name='+') |
205 | organisme_bstg = models.ForeignKey(rh.OrganismeBstg, related_name='+') | |
bd28238f | 206 | |
139686f2 NC |
207 | # Données antérieures de l'employé |
208 | statut_anterieur = models.ForeignKey( | |
209 | rh.Statut, related_name='+', null=True, blank=True, | |
210 | verbose_name='Statut précédent') | |
211 | classement_anterieur = models.ForeignKey( | |
212 | rh.Classement, related_name='+', null=True, blank=True, | |
213 | verbose_name='Classement précédent') | |
214 | salaire_anterieur = models.DecimalField( | |
215 | max_digits=12, decimal_places=2, null=True, default=None, | |
216 | blank=True, verbose_name='Salaire précédent') | |
217 | ||
218 | # Données du titulaire précédent | |
219 | employe_anterieur = models.ForeignKey( | |
220 | rh.Employe, related_name='+', null=True, blank=True, | |
221 | verbose_name='Employé précédent') | |
222 | statut_titulaire_anterieur = models.ForeignKey( | |
223 | rh.Statut, related_name='+', null=True, blank=True, | |
224 | verbose_name='Statut titulaire précédent') | |
225 | classement_titulaire_anterieur = models.ForeignKey( | |
226 | rh.Classement, related_name='+', null=True, blank=True, | |
227 | verbose_name='Classement titulaire précédent') | |
228 | salaire_titulaire_anterieur = models.DecimalField( | |
229 | max_digits=12, decimal_places=2, default=None, null=True, | |
230 | blank=True, verbose_name='Salaire titulaire précédent') | |
494ff2be | 231 | |
bd28238f NC |
232 | # Recrutement |
233 | remplacement = models.BooleanField() | |
bd28238f NC |
234 | statut_residence = models.CharField(max_length=10, |
235 | choices=STATUT_RESIDENCE_CHOICES) | |
236 | ||
237 | # Rémunération | |
494ff2be NC |
238 | classement = models.ForeignKey(rh.Classement, related_name='+', |
239 | verbose_name='Classement proposé') | |
240 | salaire = models.DecimalField(max_digits=12, decimal_places=2, | |
bd28238f | 241 | verbose_name='Salaire de base', |
494ff2be | 242 | null=True, default=None) |
5d680e84 | 243 | devise = models.ForeignKey(rh.Devise, related_name='+') |
7ad7408e NC |
244 | regime_travail = models.DecimalField(max_digits=12, decimal_places=2, |
245 | verbose_name="Régime de travail") | |
139686f2 | 246 | regime_travail_nb_heure_semaine = models.DecimalField(max_digits=12, |
7ad7408e | 247 | decimal_places=2, verbose_name="Nbr heures par semaine") |
bd28238f NC |
248 | |
249 | # Contrat | |
5d680e84 | 250 | type_contrat = models.ForeignKey(rh.TypeContrat, related_name='+') |
bd28238f NC |
251 | contrat_date_debut = models.DateField() |
252 | contrat_date_fin = models.DateField() | |
bd28238f NC |
253 | |
254 | # Comptes | |
255 | compte_compta = models.CharField(max_length=10, | |
256 | choices=COMPTE_COMPTA_CHOICES) | |
257 | compte_courriel = models.BooleanField() | |
258 | ||
259 | ||
260 | class Remuneration(models.Model): | |
5d680e84 | 261 | # Identification |
bd28238f NC |
262 | id = models.IntegerField(primary_key=True) |
263 | dossier = models.ForeignKey('Dossier', db_column='dossier') | |
264 | type = models.ForeignKey('TypeRemuneration', db_column='type') | |
5d680e84 NC |
265 | # TODO: what's that? |
266 | # type_revalorisation = models.ForeignKey('TypeRevalorisation', | |
267 | # db_column='type_revalorisation') | |
98d51b59 | 268 | montant = models.DecimalField(max_digits=12, decimal_places=2) # Annuel |
494ff2be | 269 | devise = models.ForeignKey(rh.Devise, to_field='code', |
5d680e84 | 270 | db_column='devise', related_name='+') |
494ff2be NC |
271 | date_effective = models.DateField(null=True, blank=True) |
272 | pourcentage = models.IntegerField(null=True, blank=True) | |
bd28238f | 273 | |
5d680e84 | 274 | # Méta |
bd28238f | 275 | date_creation = models.DateField(auto_now_add=True) |
494ff2be | 276 | user_creation = models.IntegerField(null=True, blank=True) |
139686f2 | 277 | desactivation = models.BooleanField(default=False, blank=True) |
494ff2be NC |
278 | date_desactivation = models.DateField(null=True, blank=True) |
279 | user_desactivation = models.IntegerField(null=True, blank=True) | |
139686f2 NC |
280 | annulation = models.BooleanField(default=False, blank=True) |
281 | date_annulation = models.DateField(null=True, blank=True) | |
282 | user_annulation = models.IntegerField(null=True, blank=True) | |
bd28238f NC |
283 | |
284 | ||
285 | class JustificationPoste(models.Model): | |
286 | pass | |
287 | ||
288 | ||
289 | class JustificationEmploye(models.Model): | |
290 | pass | |
291 | ||
292 | ||
293 | class DocumentPoste(models.Model): | |
294 | pass | |
295 | ||
296 | ||
297 | class DocumentEmploye(models.Model): | |
298 | pass | |
299 | ||
300 | ||
301 | class Validation(models.Model): | |
302 | # user | |
303 | date = models.DateField() | |
304 | ||
305 | # avis = ? (CHOICES?) | |
306 | ||
307 | ||
308 | class ValidationPoste(models.Model): | |
309 | poste = models.ForeignKey('Poste') | |
310 | ||
311 | ||
312 | class ValidationEmploye(models.Model): | |
313 | employe = models.ForeignKey('Employe') | |
314 | ||
315 | ||
316 | class TypeRemuneration(models.Model): | |
317 | ordre = models.IntegerField() | |
318 | groupe = models.ForeignKey('GroupeTypeRemuneration') | |
319 | ||
320 | ||
321 | class GroupeTypeRemuneration(models.Model): | |
322 | nom = models.CharField(max_length=255) | |
323 | ordre = models.IntegerField() |