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() | |
201 | ||
202 | class TypeRevalorisation(models.Model): | |
203 | #Identification | |
204 | id = models.IntegerField(primary_key=True) | |
205 | nom = models.CharField(max_length=255) | |
206 | #Méta | |
207 | actif = models.BooleanField() | |
208 | ||
209 | PROPORTION_CHOICES = ( | |
210 | ('0.5', '0.5'), | |
211 | ('1', '1'), | |
212 | ) | |
213 | ||
1c7d67ce OL |
214 | class PosteManager(models.Manager): |
215 | """ | |
216 | Chargement de tous les objets FK existants sur chaque QuerySet. | |
217 | """ | |
218 | def get_query_set(self): | |
219 | fkeys = ( | |
220 | 'implantation', | |
221 | 'type_poste', | |
222 | ) | |
223 | return super(PosteManager, self).get_query_set().select_related(*fkeys).all() | |
224 | ||
a3121a38 AJ |
225 | class Poste(models.Model): |
226 | #Identification | |
227 | id = models.IntegerField(primary_key=True) | |
5d680e84 NC |
228 | implantation = models.ForeignKey('datamaster_modeles.Implantation', |
229 | db_column='implantation', related_name='+') | |
a3121a38 AJ |
230 | type_poste = models.ForeignKey('TypePoste', db_column='type_poste') |
231 | proportion = models.CharField(max_length=10, choices=PROPORTION_CHOICES) | |
232 | #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%) | |
233 | #Méta | |
234 | date_modification = models.DateField(auto_now=True) | |
235 | actif = models.BooleanField() | |
236 | ||
1c7d67ce OL |
237 | # Managers |
238 | objects = PosteManager() | |
239 | ||
5d680e84 | 240 | def __unicode__(self): |
6d704629 | 241 | return u'%s - %s [%s]' % (self.implantation, self.type_poste.nom, self.id) |
5d680e84 NC |
242 | |
243 | ||
a3121a38 AJ |
244 | class Service(models.Model): |
245 | #Identification | |
246 | id = models.IntegerField(primary_key=True) | |
247 | nom = models.CharField(max_length=255) | |
248 | #Méta | |
249 | actif = models.BooleanField() | |
250 | ||
5d680e84 NC |
251 | def __unicode__(self): |
252 | return u'%s' % self.nom | |
6d704629 | 253 | |
254 | class Meta: | |
255 | ordering = ['nom'] | |
5d680e84 NC |
256 | |
257 | ||
a3121a38 AJ |
258 | TYPE_ORGANISME_CHOICES = ( |
259 | ('MAD', 'Mise à disposition'), | |
260 | ('DET', 'Détachement'), | |
261 | ) | |
262 | ||
263 | class OrganismeBstg(models.Model): | |
264 | #Identification | |
265 | id = models.IntegerField(primary_key=True) | |
266 | nom = models.CharField(max_length=255) | |
267 | type = models.CharField(max_length=10, choices=TYPE_ORGANISME_CHOICES) | |
268 | #Méta | |
269 | actif = models.BooleanField() | |
270 | ||
139686f2 NC |
271 | def __unicode__(self): |
272 | return u'%s (%s)' % (self.nom, self.type) | |
273 | ||
0f23302a | 274 | class Meta: |
275 | ordering = ['type', 'nom'] | |
276 | ||
139686f2 | 277 | |
a3121a38 AJ |
278 | CONTRAT_CATEGORIE_CHOICES= ( |
279 | ('A', 'A'), | |
280 | ('C', 'C'), | |
281 | ) | |
282 | class Statut(models.Model): | |
283 | #Identification | |
284 | id = models.IntegerField(primary_key=True) | |
285 | code = models.CharField(max_length=25, unique=True) | |
286 | nom = models.CharField(max_length=255) | |
287 | type_contrat_categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES) | |
288 | #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie | |
289 | #Méta | |
290 | actif = models.BooleanField() | |
291 | ||
139686f2 | 292 | def __unicode__(self): |
0f23302a | 293 | return u'%s : %s' % (self.code, self.nom) |
139686f2 | 294 | |
a3121a38 AJ |
295 | TYPE_CLASSEMENT_CHOICES = ( |
296 | ('S', 'S'), | |
297 | ('T', 'T'), | |
298 | ) | |
299 | class Classement(models.Model): | |
300 | #Identification | |
301 | id = models.IntegerField(primary_key=True) | |
302 | type = models.CharField(max_length=10, choices=TYPE_CLASSEMENT_CHOICES) | |
303 | echelon = models.IntegerField() | |
304 | degre = models.IntegerField() | |
305 | coefficient = models.FloatField() | |
306 | #Méta | |
307 | commentaire = models.TextField(null=True, blank=True) | |
308 | date_modification = models.DateField(auto_now=True) | |
309 | actif = models.BooleanField() | |
310 | ||
5d680e84 NC |
311 | def __unicode__(self): |
312 | return u'%s.%s.%s (%s)' % (self.type, self.echelon, self.degre, | |
313 | self.coefficient) | |
314 | ||
6301bd59 OL |
315 | class TauxChange(models.Model): |
316 | #Identification | |
317 | id = models.IntegerField(primary_key=True) | |
318 | devise = models.ForeignKey('Devise', db_column='devise') | |
319 | annee = models.IntegerField() | |
320 | taux = models.FloatField() | |
321 | #Relations | |
322 | implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation') | |
323 | ||
324 | class ValeurPointManager(models.Manager): | |
325 | """ | |
326 | Manager qui travaille uniquement sur les valeurs du point de l'année en cours. | |
327 | """ | |
328 | mois = datetime.datetime.now().month | |
329 | annee_courante = datetime.datetime.now().year | |
330 | ||
331 | # Pour le mois de janvier et décembre on mets les 2 années pour faire la transition | |
332 | if mois == 1: | |
333 | filtre_annee = (annee_courante-1, annee_courante) | |
334 | elif mois == 12: | |
335 | filtre_annee = (annee_courante, annee_courante+1) | |
336 | else: | |
337 | filtre_annee = (annee_courante,) | |
338 | ||
339 | def get_query_set(self): | |
340 | return super(ValeurPointManager, self).get_query_set().select_related('implantation').filter(annee__in=self.filtre_annee) | |
341 | ||
5d680e84 | 342 | |
a3121a38 AJ |
343 | class ValeurPoint(models.Model): |
344 | #Identification | |
345 | id = models.IntegerField(primary_key=True) | |
346 | valeur = models.FloatField() | |
347 | implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation') | |
348 | #Méta | |
349 | annee = models.IntegerField() | |
6301bd59 OL |
350 | |
351 | # Stockage de tous les taux de change pour optimiser la recherche de la devise associée | |
352 | annee_courante = datetime.datetime.now().year | |
353 | tauxchange = TauxChange.objects.select_related('devise').filter(annee=annee_courante) | |
354 | ||
355 | def get_tauxchange_courant(self): | |
356 | """ | |
357 | Recherche le taux courant associé à la valeur d'un point. | |
358 | Tous les taux de l'année courante sont chargés, pour optimiser un affichage en liste. | |
359 | (On pourrait probablement améliorer le manager pour lui greffer le taux courant sous forme de JOIN) | |
360 | """ | |
361 | for tauxchange in self.tauxchange: | |
362 | if tauxchange.implantation_id == self.implantation_id: | |
363 | return tauxchange | |
364 | return None | |
a3121a38 | 365 | |
5d680e84 | 366 | def __unicode__(self): |
17353922 OL |
367 | tx = self.get_tauxchange_courant() |
368 | if tx: | |
369 | devise_code = tx.devise.code | |
370 | else: | |
371 | devise_code = "??" | |
372 | return u'%s (%s-%s) %s' % (self.valeur, self.implantation_id, self.annee, devise_code) | |
6d704629 | 373 | |
374 | class Meta: | |
375 | ordering = ['valeur'] | |
5d680e84 | 376 | |
4dd75e7b | 377 | objects = models.Manager() |
6301bd59 | 378 | actuelles = ValeurPointManager() |
a3121a38 | 379 | |
5d680e84 | 380 | |
a3121a38 AJ |
381 | class Devise(models.Model): |
382 | id = models.IntegerField(primary_key=True) | |
383 | code = models.CharField(max_length=10, unique=True) | |
384 | nom = models.CharField(max_length=255) | |
385 | ||
5d680e84 NC |
386 | def __unicode__(self): |
387 | return u'%s - %s' % (self.code, self.nom) | |
388 | ||
389 | ||
a3121a38 AJ |
390 | class TypeContrat(models.Model): |
391 | #Identification | |
392 | id = models.IntegerField(primary_key=True) | |
393 | nom = models.CharField(max_length=255) | |
394 | nom_long = models.CharField(max_length=255) #description | |
395 | categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES) | |
396 | #Méta | |
397 | actif = models.BooleanField() | |
398 | ||
139686f2 | 399 | def __unicode__(self): |
0f23302a | 400 | return u'%s' % (self.nom) |