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='+', | |
55 | verbose_name="Poste du responsable") | |
9a85768a | 56 | |
5d680e84 NC |
57 | regime_travail = models.DecimalField(max_digits=12, decimal_places=2, |
58 | default=100) | |
59 | regime_travail_nb_heure_semaine = models.DecimalField(max_digits=12, | |
60 | decimal_places=2, | |
61 | default=40) | |
bd28238f NC |
62 | |
63 | # Recrutement | |
98d51b59 NC |
64 | statut_residence = models.CharField(max_length=10, default='MAD', |
65 | verbose_name="Recrutement", | |
bd28238f | 66 | choices=STATUT_RESIDENCE_CHOICES) |
5d680e84 NC |
67 | # TODO null? |
68 | mise_a_disposition = models.BooleanField() | |
98d51b59 NC |
69 | appel = models.CharField(max_length=10, default='interne', |
70 | verbose_name="Appel à candidature", | |
5d680e84 | 71 | choices=POSTE_APPEL_CHOICES) |
bd28238f NC |
72 | |
73 | # Rémunération | |
5d680e84 NC |
74 | classement_min = models.ForeignKey(rh.Classement, related_name='+') |
75 | classement_max = models.ForeignKey(rh.Classement, related_name='+') | |
76 | valeur_point_min = models.ForeignKey(rh.ValeurPoint, related_name='+') | |
77 | valeur_point_max = models.ForeignKey(rh.ValeurPoint, related_name='+') | |
78 | salaire_min = models.DecimalField(max_digits=12, decimal_places=2, | |
79 | default=0) | |
80 | salaire_max = models.DecimalField(max_digits=12, decimal_places=2, | |
81 | default=0) | |
82 | indemn_min = models.DecimalField(max_digits=12, decimal_places=2, | |
83 | default=0) | |
84 | indemn_max = models.DecimalField(max_digits=12, decimal_places=2, | |
85 | default=0) | |
86 | autre_min = models.DecimalField(max_digits=12, decimal_places=2, | |
87 | default=0) | |
88 | autre_max = models.DecimalField(max_digits=12, decimal_places=2, | |
89 | default=0) | |
90 | ||
91 | # Comparatifs de rémunération | |
92 | devise_comparaison = models.ForeignKey(rh.Devise, related_name='+', | |
93 | null=True, blank=True) | |
94 | comp_locale_min = models.DecimalField(max_digits=12, decimal_places=2, | |
95 | null=True, blank=True) | |
96 | comp_locale_max = models.DecimalField(max_digits=12, decimal_places=2, | |
97 | null=True, blank=True) | |
98 | comp_universite_min = models.DecimalField(max_digits=12, decimal_places=2, | |
99 | null=True, blank=True) | |
100 | comp_universite_max = models.DecimalField(max_digits=12, decimal_places=2, | |
101 | null=True, blank=True) | |
102 | comp_fonctionpub_min = models.DecimalField(max_digits=12, decimal_places=2, | |
103 | null=True, blank=True) | |
104 | comp_fonctionpub_max = models.DecimalField(max_digits=12, decimal_places=2, | |
105 | null=True, blank=True) | |
106 | comp_ong_min = models.DecimalField(max_digits=12, decimal_places=2, | |
107 | null=True, blank=True) | |
108 | comp_ong_max = models.DecimalField(max_digits=12, decimal_places=2, | |
109 | null=True, blank=True) | |
110 | comp_autre_min = models.DecimalField(max_digits=12, decimal_places=2, | |
111 | null=True, blank=True) | |
112 | comp_autre_max = models.DecimalField(max_digits=12, decimal_places=2, | |
113 | null=True, blank=True) | |
bd28238f NC |
114 | |
115 | # Méta | |
5d680e84 NC |
116 | date_creation = models.DateTimeField(auto_now_add=True) |
117 | date_modification = models.DateTimeField(auto_now=True) | |
98d51b59 NC |
118 | date_debut = models.DateField(verbose_name="Date de début", |
119 | help_text="format: aaaa-mm-jj") | |
120 | date_fin = models.DateField(null=True, verbose_name="Date de fin", | |
121 | help_text="format: aaaa-mm-jj") | |
bd28238f NC |
122 | actif = models.BooleanField(default=True) |
123 | ||
1c7d67ce OL |
124 | # Managers |
125 | objects = PosteManager() | |
126 | ||
5d680e84 | 127 | def __unicode__(self): |
6d704629 | 128 | return u'%s - %s (%s) [dae-%s]' % (self.implantation, self.type_poste.nom, |
129 | self.nom, self.id) | |
5d680e84 NC |
130 | |
131 | def DISABLED_save(self, *args, **kwargs): | |
bd28238f NC |
132 | # calculate nb_mois = nb of months between date_debut and date_fin |
133 | from datetime import date | |
bd28238f NC |
134 | if not self.salaire_min: |
135 | self.salaire_min = self.classement_min * self.valeur_point_min | |
136 | if not self.salaire_max: | |
137 | self.salaire_max = self.classement_max * self.valeur_point_min | |
138 | if not self.valeur_point_min: | |
139 | self.valeur_point_min = \ | |
140 | rh.ValeurPoint.objects.filter(implantation=self.implantation) | |
141 | if not self.valeur_point_max: | |
142 | self.valeur_point_max = \ | |
143 | rh.ValeurPoint.objects.filter(implantation=self.implantation) | |
144 | super(Subject, self).save(*args, **kwargs) | |
145 | ||
146 | ||
5d680e84 NC |
147 | POSTE_FINANCEMENT_CHOICES = ( |
148 | ('A', 'A - Frais de personnel'), | |
149 | ('B', 'B - Projet(s)-Titre(s)'), | |
150 | ('C', 'C - Autre') | |
151 | ) | |
bd28238f NC |
152 | |
153 | ||
5d680e84 NC |
154 | class PosteFinancement(models.Model): |
155 | montant = models.DecimalField(max_digits=12, decimal_places=2) | |
156 | poste = models.ForeignKey('Poste', related_name='financements') | |
157 | type = models.CharField(max_length=1, choices=POSTE_FINANCEMENT_CHOICES) | |
158 | pourcentage = models.DecimalField(max_digits=12, decimal_places=2) | |
159 | commentaire = models.TextField() | |
bd28238f NC |
160 | |
161 | ||
162 | GENRE_CHOICES = ( | |
139686f2 NC |
163 | ('m', 'Homme'), |
164 | ('f', 'Femme'), | |
bd28238f NC |
165 | ) |
166 | ||
167 | ||
168 | class Employe(models.Model): | |
bd28238f NC |
169 | |
170 | # Modèle existant | |
5d680e84 | 171 | id_rh = models.ForeignKey(rh.Employe, null=True, related_name='+') |
bd28238f NC |
172 | nom = models.CharField(max_length=255) |
173 | prenom = models.CharField(max_length=255) | |
494ff2be NC |
174 | genre = models.CharField(max_length=1, choices=GENRE_CHOICES, |
175 | null=True, blank=True) | |
bd28238f | 176 | |
139686f2 NC |
177 | def __unicode__(self): |
178 | return u'%s %s' % (self.prenom, self.nom) | |
179 | ||
bd28238f NC |
180 | |
181 | COMPTE_COMPTA_CHOICES = ( | |
494ff2be NC |
182 | ('coda', 'CODA'), |
183 | ('scs', 'SCS'), | |
184 | ('aucun', 'Aucun'), | |
bd28238f NC |
185 | ) |
186 | ||
187 | ||
188 | class Dossier(models.Model): | |
bd28238f NC |
189 | |
190 | # Modèle existant | |
139686f2 NC |
191 | employe = models.ForeignKey('Employe', related_name='+', editable=False) |
192 | poste = models.ForeignKey('Poste', related_name='+', editable=False) | |
5d680e84 NC |
193 | statut = models.ForeignKey(rh.Statut, related_name='+') |
194 | organisme_bstg = models.ForeignKey(rh.OrganismeBstg, related_name='+') | |
bd28238f | 195 | |
139686f2 NC |
196 | # Données antérieures de l'employé |
197 | statut_anterieur = models.ForeignKey( | |
198 | rh.Statut, related_name='+', null=True, blank=True, | |
199 | verbose_name='Statut précédent') | |
200 | classement_anterieur = models.ForeignKey( | |
201 | rh.Classement, related_name='+', null=True, blank=True, | |
202 | verbose_name='Classement précédent') | |
203 | salaire_anterieur = models.DecimalField( | |
204 | max_digits=12, decimal_places=2, null=True, default=None, | |
205 | blank=True, verbose_name='Salaire précédent') | |
206 | ||
207 | # Données du titulaire précédent | |
208 | employe_anterieur = models.ForeignKey( | |
209 | rh.Employe, related_name='+', null=True, blank=True, | |
210 | verbose_name='Employé précédent') | |
211 | statut_titulaire_anterieur = models.ForeignKey( | |
212 | rh.Statut, related_name='+', null=True, blank=True, | |
213 | verbose_name='Statut titulaire précédent') | |
214 | classement_titulaire_anterieur = models.ForeignKey( | |
215 | rh.Classement, related_name='+', null=True, blank=True, | |
216 | verbose_name='Classement titulaire précédent') | |
217 | salaire_titulaire_anterieur = models.DecimalField( | |
218 | max_digits=12, decimal_places=2, default=None, null=True, | |
219 | blank=True, verbose_name='Salaire titulaire précédent') | |
494ff2be | 220 | |
bd28238f NC |
221 | # Recrutement |
222 | remplacement = models.BooleanField() | |
bd28238f NC |
223 | statut_residence = models.CharField(max_length=10, |
224 | choices=STATUT_RESIDENCE_CHOICES) | |
225 | ||
226 | # Rémunération | |
494ff2be NC |
227 | classement = models.ForeignKey(rh.Classement, related_name='+', |
228 | verbose_name='Classement proposé') | |
229 | salaire = models.DecimalField(max_digits=12, decimal_places=2, | |
bd28238f | 230 | verbose_name='Salaire de base', |
494ff2be | 231 | null=True, default=None) |
5d680e84 | 232 | devise = models.ForeignKey(rh.Devise, related_name='+') |
7ad7408e NC |
233 | regime_travail = models.DecimalField(max_digits=12, decimal_places=2, |
234 | verbose_name="Régime de travail") | |
139686f2 | 235 | regime_travail_nb_heure_semaine = models.DecimalField(max_digits=12, |
7ad7408e | 236 | decimal_places=2, verbose_name="Nbr heures par semaine") |
bd28238f NC |
237 | |
238 | # Contrat | |
5d680e84 | 239 | type_contrat = models.ForeignKey(rh.TypeContrat, related_name='+') |
bd28238f NC |
240 | contrat_date_debut = models.DateField() |
241 | contrat_date_fin = models.DateField() | |
bd28238f NC |
242 | |
243 | # Comptes | |
244 | compte_compta = models.CharField(max_length=10, | |
245 | choices=COMPTE_COMPTA_CHOICES) | |
246 | compte_courriel = models.BooleanField() | |
247 | ||
248 | ||
249 | class Remuneration(models.Model): | |
5d680e84 | 250 | # Identification |
bd28238f NC |
251 | id = models.IntegerField(primary_key=True) |
252 | dossier = models.ForeignKey('Dossier', db_column='dossier') | |
253 | type = models.ForeignKey('TypeRemuneration', db_column='type') | |
5d680e84 NC |
254 | # TODO: what's that? |
255 | # type_revalorisation = models.ForeignKey('TypeRevalorisation', | |
256 | # db_column='type_revalorisation') | |
98d51b59 | 257 | montant = models.DecimalField(max_digits=12, decimal_places=2) # Annuel |
494ff2be | 258 | devise = models.ForeignKey(rh.Devise, to_field='code', |
5d680e84 | 259 | db_column='devise', related_name='+') |
494ff2be NC |
260 | date_effective = models.DateField(null=True, blank=True) |
261 | pourcentage = models.IntegerField(null=True, blank=True) | |
bd28238f | 262 | |
5d680e84 | 263 | # Méta |
bd28238f | 264 | date_creation = models.DateField(auto_now_add=True) |
494ff2be | 265 | user_creation = models.IntegerField(null=True, blank=True) |
139686f2 | 266 | desactivation = models.BooleanField(default=False, blank=True) |
494ff2be NC |
267 | date_desactivation = models.DateField(null=True, blank=True) |
268 | user_desactivation = models.IntegerField(null=True, blank=True) | |
139686f2 NC |
269 | annulation = models.BooleanField(default=False, blank=True) |
270 | date_annulation = models.DateField(null=True, blank=True) | |
271 | user_annulation = models.IntegerField(null=True, blank=True) | |
bd28238f NC |
272 | |
273 | ||
274 | class JustificationPoste(models.Model): | |
275 | pass | |
276 | ||
277 | ||
278 | class JustificationEmploye(models.Model): | |
279 | pass | |
280 | ||
281 | ||
282 | class DocumentPoste(models.Model): | |
283 | pass | |
284 | ||
285 | ||
286 | class DocumentEmploye(models.Model): | |
287 | pass | |
288 | ||
289 | ||
290 | class Validation(models.Model): | |
291 | # user | |
292 | date = models.DateField() | |
293 | ||
294 | # avis = ? (CHOICES?) | |
295 | ||
296 | ||
297 | class ValidationPoste(models.Model): | |
298 | poste = models.ForeignKey('Poste') | |
299 | ||
300 | ||
301 | class ValidationEmploye(models.Model): | |
302 | employe = models.ForeignKey('Employe') | |
303 | ||
304 | ||
305 | class TypeRemuneration(models.Model): | |
306 | ordre = models.IntegerField() | |
307 | groupe = models.ForeignKey('GroupeTypeRemuneration') | |
308 | ||
309 | ||
310 | class GroupeTypeRemuneration(models.Model): | |
311 | nom = models.CharField(max_length=255) | |
312 | ordre = models.IntegerField() |