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