Commit | Line | Data |
---|---|---|
a3121a38 AJ |
1 | # -=- encoding: utf-8 -=- |
2 | ||
6301bd59 | 3 | import datetime |
a3121a38 AJ |
4 | from django.db import models |
5 | from datamaster_modeles.models import Pays, Implantation | |
6 | ||
7 | GENRE_CHOICES = ( | |
139686f2 NC |
8 | ('m', 'Homme'), |
9 | ('f', 'Femme'), | |
a3121a38 AJ |
10 | ) |
11 | SITUATION_CHOICES = ( | |
12 | ('C', 'Célibataire'), | |
13 | ('F', 'Fiancé'), | |
14 | ('M', 'Marié'), | |
15 | ) | |
16 | ||
17 | class Employe(models.Model): | |
18 | #Identification | |
19 | id = models.IntegerField(primary_key=True) | |
20 | nom = models.CharField(max_length=255) | |
21 | prenom = models.CharField(max_length=255) | |
22 | nationalite = models.ForeignKey('datamaster_modeles.Pays', to_field='code', related_name='nationalite', db_column='nationalite') | |
23 | date_naissance = models.DateField(null=True, blank=True) | |
24 | #Infos personnelles | |
25 | genre = models.CharField(max_length=1, choices=GENRE_CHOICES, null=True, blank=True) | |
26 | situation_famille = models.CharField(max_length=1, choices=SITUATION_CHOICES, null=True, blank=True) | |
27 | date_entree = models.DateField(null=True, blank=True) #devrait pas être là | |
28 | #Coordonnées | |
29 | tel_domicile = models.CharField(max_length=255, null=True, blank=True) | |
30 | tel_cellulaire = models.CharField(max_length=255, null=True, blank=True) | |
31 | adresse = models.CharField(max_length=255, null=True, blank=True) | |
32 | no_rue = models.CharField(max_length=255, null=True, blank=True) | |
33 | ville = models.CharField(max_length=255, null=True, blank=True) | |
34 | province = models.CharField(max_length=255, null=True, blank=True) | |
35 | code_postal = models.CharField(max_length=255, null=True, blank=True) | |
36 | pays = models.ForeignKey('datamaster_modeles.Pays', to_field='code', null=True, blank=True, related_name='pays', db_column='pays') | |
37 | #Métas | |
38 | date_creation = models.DateField(auto_now_add=True) | |
39 | date_maj = models.DateField(auto_now=True) | |
40 | commentaire = models.TextField(null=True, blank=True) | |
139686f2 NC |
41 | |
42 | def __unicode__(self): | |
43 | return u'%s %s' % (self.prenom, self.nom) | |
44 | ||
45 | ||
a3121a38 AJ |
46 | TYPE_DOSSIER_CHOICES = ( |
47 | ('2', 'Local'), | |
48 | ('1', 'Expatrié'), | |
49 | ) | |
50 | ||
1c7d67ce OL |
51 | class DossierManager(models.Manager): |
52 | """ | |
53 | Chargement de tous les objets FK existants sur chaque QuerySet. | |
54 | """ | |
55 | def get_query_set(self): | |
56 | fkeys = ( | |
57 | 'employe', | |
58 | 'poste1', | |
59 | 'implantation1', | |
60 | 'poste2', | |
61 | 'implantation2', | |
62 | 'service', | |
63 | 'responsable', | |
64 | 'remplacement_de', | |
65 | 'statut', | |
66 | 'organisme_bstg', | |
67 | 'classement', | |
68 | 'type_contrat', | |
69 | ) | |
70 | return super(DossierManager, self).get_query_set().select_related(*fkeys).all() | |
71 | ||
a3121a38 AJ |
72 | class Dossier(models.Model): |
73 | #Identification | |
74 | id = models.IntegerField(primary_key=True) | |
75 | code = models.CharField(max_length=10, unique=True) | |
76 | employe = models.ForeignKey('Employe', db_column='employe') | |
77 | #Postes | |
78 | poste1 = models.ForeignKey('Poste', db_column='poste1', related_name='poste1') | |
f48decfd | 79 | implantation1 = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation1', related_name='implantation1', blank=True, null=True) |
a3121a38 AJ |
80 | complement1 = models.TextField(null=True, blank=True) |
81 | responsable_implantation1 = models.IntegerField() | |
82 | poste2 = models.ForeignKey('Poste', db_column='poste2', related_name='poste2', blank=True, null=True) | |
f48decfd | 83 | implantation2 = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation2', related_name='implantation2', null=True, blank=True) |
a3121a38 AJ |
84 | complement2 = models.TextField(null=True, blank=True) |
85 | responsable_implantation2 = models.IntegerField() | |
86 | #Relations | |
f48decfd NC |
87 | service = models.ForeignKey('Service', db_column='service', blank=True, null=True) |
88 | responsable = models.ForeignKey('Employe', db_column='responsable', related_name='responsable', blank=True, null=True) | |
89 | remplacement_de = models.ForeignKey('Employe', db_column='remplacement_de', related_name='remplacement_de', blank=True, null=True) | |
a3121a38 | 90 | type = models.CharField(max_length=1, choices=TYPE_DOSSIER_CHOICES) |
f48decfd NC |
91 | statut = models.ForeignKey('Statut', db_column='statut', blank=True, null=True) |
92 | organisme_bstg = models.ForeignKey('OrganismeBstg', db_column='organisme_bstg', blank=True, null=True) | |
a3121a38 | 93 | #Rémunération |
f48decfd | 94 | classement = models.ForeignKey('Classement', db_column='classement', blank=True, null=True) |
a3121a38 AJ |
95 | regime_travail = models.IntegerField() |
96 | #Mandat | |
97 | mandat_date_debut = models.DateField() | |
f48decfd | 98 | mandat_date_fin = models.DateField(null=True, blank=True) |
a3121a38 AJ |
99 | #Contrat |
100 | contrat_date_debut = models.DateField() | |
101 | contrat_date_fin = models.DateField() | |
f48decfd | 102 | type_contrat = models.ForeignKey('TypeContrat', db_column='type_contrat', blank=True, null=True) |
a3121a38 AJ |
103 | #Meta |
104 | date_creation = models.DateField(auto_now_add=True) | |
105 | date_maj = models.DateField(auto_now=True) | |
106 | commentaire = models.TextField(null=True, blank=True) | |
107 | ||
1c7d67ce OL |
108 | # Managers |
109 | objects = DossierManager() | |
0f23302a | 110 | |
111 | def __unicode__(self): | |
112 | return u'%s : %s %s' % (self.employe, self.poste1, self.complement1) | |
1c7d67ce | 113 | |
a3121a38 AJ |
114 | LIEN_PARENTE_CHOICES = ( |
115 | ('Conjoint', 'Conjoint'), | |
116 | ('Conjointe', 'Conjointe'), | |
117 | ('Fille', 'Fille'), | |
118 | ('Fils', 'Fils'), | |
119 | ) | |
120 | ||
121 | class AyantDroit(models.Model): | |
122 | #Identification | |
123 | id = models.IntegerField(primary_key=True) | |
124 | nom = models.CharField(max_length=255) | |
125 | prenom = models.CharField(max_length=255) | |
126 | #Relation | |
127 | employe = models.ForeignKey('Employe', db_column='employe', related_name='employe') | |
128 | lien_parente = models.CharField(max_length=10, choices=LIEN_PARENTE_CHOICES, null=True, blank=True) | |
129 | #Méta | |
130 | commentaire = models.TextField(null=True, blank=True) | |
131 | actif = models.BooleanField() | |
132 | ||
133 | ||
134 | class Remuneration(models.Model): | |
135 | #Identification | |
136 | id = models.IntegerField(primary_key=True) | |
137 | dossier = models.ForeignKey('Dossier', db_column='dossier') | |
138 | type = models.ForeignKey('TypeRemuneration', db_column='type') | |
139686f2 NC |
139 | type_revalorisation = models.ForeignKey('TypeRevalorisation', db_column='type_revalorisation', null=True, blank=True) |
140 | montant = models.FloatField(null=True, blank=True) | |
141 | devise = models.ForeignKey('Devise', to_field='code', db_column='devise', null=True, blank=True) | |
142 | date_effective = models.DateField(null=True, blank=True) | |
143 | pourcentage = models.IntegerField(null=True, blank=True) | |
a3121a38 AJ |
144 | #Méta |
145 | date_creation = models.DateField(auto_now_add=True) | |
139686f2 NC |
146 | user_creation = models.IntegerField(null=True, blank=True) #User ou employé |
147 | desactivation = models.NullBooleanField(null=True, blank=True) # | |
148 | date_desactivation = models.DateField(null=True, blank=True) | |
149 | user_desactivation = models.IntegerField(null=True, blank=True) #User ou employé | |
150 | annulation = models.NullBooleanField(null=True, blank=True) | |
151 | date_annulation = models.DateField(null=True, blank=True) | |
152 | user_annulation = models.IntegerField(null=True, blank=True) #User ou employé | |
a3121a38 AJ |
153 | |
154 | class FamilleEmploi(models.Model): | |
155 | #Identification | |
156 | id = models.IntegerField(primary_key=True) | |
157 | nom = models.CharField(max_length=255) | |
158 | #Méta | |
159 | actif = models.BooleanField() | |
160 | ||
161 | class TypePoste(models.Model): | |
162 | #Identification | |
163 | id = models.IntegerField(primary_key=True) | |
164 | nom = models.CharField(max_length=255) | |
165 | nom_feminin = models.CharField(max_length=255) | |
166 | description = models.CharField(max_length=255) | |
167 | is_responsable = models.BooleanField() | |
168 | famille_emploi = models.ForeignKey('FamilleEmploi', db_column='famille_emploi') | |
169 | #Méta | |
170 | date_modification = models.DateField(auto_now=True) | |
171 | actif = models.BooleanField() | |
172 | ||
5d680e84 NC |
173 | def __unicode__(self): |
174 | return u'%s' % self.nom | |
6d704629 | 175 | |
176 | class Meta: | |
177 | ordering = ['nom'] | |
5d680e84 NC |
178 | |
179 | ||
a3121a38 AJ |
180 | TYPE_PAIEMENT_CHOICES = ( |
181 | ('Régulier', 'Régulier'), | |
182 | ('Ponctuel', 'Ponctuel'), | |
183 | ) | |
184 | ||
185 | NATURE_REMUNERATION_CHOICES = ( | |
186 | ('Accessoire', 'Accessoire'), | |
187 | ('Charges', 'Charges'), | |
188 | ('Indemnité', 'Indemnité'), | |
189 | ('RAS', 'RAS'), | |
190 | ('Traitement', 'Traitement'), | |
191 | ) | |
192 | ||
193 | class TypeRemuneration(models.Model): | |
194 | #Identification | |
195 | id = models.IntegerField(primary_key=True) | |
196 | nom = models.CharField(max_length=255) | |
197 | type_paiement = models.CharField(max_length=30, choices=TYPE_PAIEMENT_CHOICES) | |
198 | nature_remuneration = models.CharField(max_length=30, choices=NATURE_REMUNERATION_CHOICES) | |
199 | #Méta | |
200 | actif = models.BooleanField() | |
cb1d62b5 NC |
201 | |
202 | def __unicode__(self): | |
203 | return u'%s' % self.nom | |
204 | ||
205 | ||
a3121a38 AJ |
206 | class TypeRevalorisation(models.Model): |
207 | #Identification | |
208 | id = models.IntegerField(primary_key=True) | |
209 | nom = models.CharField(max_length=255) | |
210 | #Méta | |
211 | actif = models.BooleanField() | |
212 | ||
213 | PROPORTION_CHOICES = ( | |
214 | ('0.5', '0.5'), | |
215 | ('1', '1'), | |
216 | ) | |
217 | ||
1c7d67ce OL |
218 | class PosteManager(models.Manager): |
219 | """ | |
220 | Chargement de tous les objets FK existants sur chaque QuerySet. | |
221 | """ | |
222 | def get_query_set(self): | |
223 | fkeys = ( | |
224 | 'implantation', | |
225 | 'type_poste', | |
226 | ) | |
227 | return super(PosteManager, self).get_query_set().select_related(*fkeys).all() | |
228 | ||
a3121a38 AJ |
229 | class Poste(models.Model): |
230 | #Identification | |
231 | id = models.IntegerField(primary_key=True) | |
5d680e84 NC |
232 | implantation = models.ForeignKey('datamaster_modeles.Implantation', |
233 | db_column='implantation', related_name='+') | |
a3121a38 AJ |
234 | type_poste = models.ForeignKey('TypePoste', db_column='type_poste') |
235 | proportion = models.CharField(max_length=10, choices=PROPORTION_CHOICES) | |
236 | #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%) | |
237 | #Méta | |
238 | date_modification = models.DateField(auto_now=True) | |
239 | actif = models.BooleanField() | |
240 | ||
1c7d67ce OL |
241 | # Managers |
242 | objects = PosteManager() | |
243 | ||
5d680e84 | 244 | def __unicode__(self): |
6d704629 | 245 | return u'%s - %s [%s]' % (self.implantation, self.type_poste.nom, self.id) |
5d680e84 NC |
246 | |
247 | ||
a3121a38 AJ |
248 | class Service(models.Model): |
249 | #Identification | |
250 | id = models.IntegerField(primary_key=True) | |
251 | nom = models.CharField(max_length=255) | |
252 | #Méta | |
253 | actif = models.BooleanField() | |
254 | ||
5d680e84 NC |
255 | def __unicode__(self): |
256 | return u'%s' % self.nom | |
6d704629 | 257 | |
258 | class Meta: | |
259 | ordering = ['nom'] | |
5d680e84 NC |
260 | |
261 | ||
a3121a38 AJ |
262 | TYPE_ORGANISME_CHOICES = ( |
263 | ('MAD', 'Mise à disposition'), | |
264 | ('DET', 'Détachement'), | |
265 | ) | |
266 | ||
267 | class OrganismeBstg(models.Model): | |
268 | #Identification | |
269 | id = models.IntegerField(primary_key=True) | |
270 | nom = models.CharField(max_length=255) | |
271 | type = models.CharField(max_length=10, choices=TYPE_ORGANISME_CHOICES) | |
272 | #Méta | |
273 | actif = models.BooleanField() | |
274 | ||
139686f2 NC |
275 | def __unicode__(self): |
276 | return u'%s (%s)' % (self.nom, self.type) | |
277 | ||
0f23302a | 278 | class Meta: |
279 | ordering = ['type', 'nom'] | |
280 | ||
139686f2 | 281 | |
a3121a38 AJ |
282 | CONTRAT_CATEGORIE_CHOICES= ( |
283 | ('A', 'A'), | |
284 | ('C', 'C'), | |
285 | ) | |
286 | class Statut(models.Model): | |
287 | #Identification | |
288 | id = models.IntegerField(primary_key=True) | |
289 | code = models.CharField(max_length=25, unique=True) | |
290 | nom = models.CharField(max_length=255) | |
291 | type_contrat_categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES) | |
292 | #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie | |
293 | #Méta | |
294 | actif = models.BooleanField() | |
295 | ||
139686f2 | 296 | def __unicode__(self): |
0f23302a | 297 | return u'%s : %s' % (self.code, self.nom) |
139686f2 | 298 | |
a3121a38 AJ |
299 | TYPE_CLASSEMENT_CHOICES = ( |
300 | ('S', 'S'), | |
301 | ('T', 'T'), | |
302 | ) | |
303 | class Classement(models.Model): | |
304 | #Identification | |
305 | id = models.IntegerField(primary_key=True) | |
306 | type = models.CharField(max_length=10, choices=TYPE_CLASSEMENT_CHOICES) | |
307 | echelon = models.IntegerField() | |
308 | degre = models.IntegerField() | |
309 | coefficient = models.FloatField() | |
310 | #Méta | |
311 | commentaire = models.TextField(null=True, blank=True) | |
312 | date_modification = models.DateField(auto_now=True) | |
313 | actif = models.BooleanField() | |
314 | ||
5d680e84 NC |
315 | def __unicode__(self): |
316 | return u'%s.%s.%s (%s)' % (self.type, self.echelon, self.degre, | |
317 | self.coefficient) | |
e57fb3d8 | 318 | class Meta: |
319 | ordering = ['type','echelon','degre','coefficient'] | |
5d680e84 | 320 | |
6301bd59 OL |
321 | class TauxChange(models.Model): |
322 | #Identification | |
323 | id = models.IntegerField(primary_key=True) | |
324 | devise = models.ForeignKey('Devise', db_column='devise') | |
325 | annee = models.IntegerField() | |
326 | taux = models.FloatField() | |
327 | #Relations | |
328 | implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation') | |
329 | ||
330 | class ValeurPointManager(models.Manager): | |
331 | """ | |
332 | Manager qui travaille uniquement sur les valeurs du point de l'année en cours. | |
333 | """ | |
334 | mois = datetime.datetime.now().month | |
335 | annee_courante = datetime.datetime.now().year | |
336 | ||
337 | # Pour le mois de janvier et décembre on mets les 2 années pour faire la transition | |
338 | if mois == 1: | |
339 | filtre_annee = (annee_courante-1, annee_courante) | |
340 | elif mois == 12: | |
341 | filtre_annee = (annee_courante, annee_courante+1) | |
342 | else: | |
343 | filtre_annee = (annee_courante,) | |
344 | ||
345 | def get_query_set(self): | |
346 | return super(ValeurPointManager, self).get_query_set().select_related('implantation').filter(annee__in=self.filtre_annee) | |
347 | ||
5d680e84 | 348 | |
a3121a38 AJ |
349 | class ValeurPoint(models.Model): |
350 | #Identification | |
351 | id = models.IntegerField(primary_key=True) | |
352 | valeur = models.FloatField() | |
353 | implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation') | |
354 | #Méta | |
355 | annee = models.IntegerField() | |
6301bd59 OL |
356 | |
357 | # Stockage de tous les taux de change pour optimiser la recherche de la devise associée | |
358 | annee_courante = datetime.datetime.now().year | |
359 | tauxchange = TauxChange.objects.select_related('devise').filter(annee=annee_courante) | |
360 | ||
361 | def get_tauxchange_courant(self): | |
362 | """ | |
363 | Recherche le taux courant associé à la valeur d'un point. | |
364 | Tous les taux de l'année courante sont chargés, pour optimiser un affichage en liste. | |
365 | (On pourrait probablement améliorer le manager pour lui greffer le taux courant sous forme de JOIN) | |
366 | """ | |
367 | for tauxchange in self.tauxchange: | |
368 | if tauxchange.implantation_id == self.implantation_id: | |
369 | return tauxchange | |
370 | return None | |
a3121a38 | 371 | |
5d680e84 | 372 | def __unicode__(self): |
17353922 OL |
373 | tx = self.get_tauxchange_courant() |
374 | if tx: | |
375 | devise_code = tx.devise.code | |
376 | else: | |
377 | devise_code = "??" | |
da3ca955 | 378 | return u'%s %s (%s-%s)' % (self.valeur, devise_code, self.implantation_id, self.annee) |
6d704629 | 379 | |
380 | class Meta: | |
381 | ordering = ['valeur'] | |
5d680e84 | 382 | |
4dd75e7b | 383 | objects = models.Manager() |
6301bd59 | 384 | actuelles = ValeurPointManager() |
a3121a38 | 385 | |
5d680e84 | 386 | |
a3121a38 AJ |
387 | class Devise(models.Model): |
388 | id = models.IntegerField(primary_key=True) | |
389 | code = models.CharField(max_length=10, unique=True) | |
390 | nom = models.CharField(max_length=255) | |
391 | ||
5d680e84 NC |
392 | def __unicode__(self): |
393 | return u'%s - %s' % (self.code, self.nom) | |
394 | ||
395 | ||
a3121a38 AJ |
396 | class TypeContrat(models.Model): |
397 | #Identification | |
398 | id = models.IntegerField(primary_key=True) | |
399 | nom = models.CharField(max_length=255) | |
400 | nom_long = models.CharField(max_length=255) #description | |
401 | categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES) | |
402 | #Méta | |
403 | actif = models.BooleanField() | |
404 | ||
139686f2 | 405 | def __unicode__(self): |
0f23302a | 406 | return u'%s' % (self.nom) |