rh.models ~= rh_v1.models (+ PEP 8)
[auf_rh_dae.git] / project / rh / models.py
1 # -=- encoding: utf-8 -=-
2
3 import datetime
4 from django.db import models
5 from datamaster_modeles.models import Pays, Implantation
6
7 GENRE_CHOICES = (
8 ('M', 'Homme'),
9 ('F', 'Femme'),
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',
23 related_name='employes_nationalite',
24 db_column='nationalite')
25 date_naissance = models.DateField(null=True, blank=True)
26 # Infos personnelles
27 genre = models.CharField(max_length=1, null=True, blank=True,
28 choices=GENRE_CHOICES)
29 situation_famille = models.CharField(max_length=1, null=True, blank=True,
30 choices=SITUATION_CHOICES)
31 date_entree = models.DateField(null=True, blank=True) #devrait pas être là
32 # Coordonnées
33 tel_domicile = models.CharField(max_length=255, null=True, blank=True)
34 tel_cellulaire = models.CharField(max_length=255, null=True, blank=True)
35 adresse = models.CharField(max_length=255, null=True, blank=True)
36 no_rue = models.CharField(max_length=255, null=True, blank=True)
37 ville = models.CharField(max_length=255, null=True, blank=True)
38 province = models.CharField(max_length=255, null=True, blank=True)
39 code_postal = models.CharField(max_length=255, null=True, blank=True)
40 pays = models.ForeignKey('datamaster_modeles.Pays', to_field='code',
41 null=True, blank=True,
42 related_name='employes', db_column='pays')
43 # Métas
44 date_creation = models.DateField(auto_now_add=True)
45 date_maj = models.DateField(auto_now=True)
46 commentaire = models.TextField(null=True, blank=True)
47
48 def __unicode__(self):
49 return u'%s %s' % (self.prenom, self.nom)
50
51
52 TYPE_DOSSIER_CHOICES = (
53 ('2', 'Local'),
54 ('1', 'Expatrié'),
55 )
56
57 class Dossier(models.Model):
58 # Identification
59 id = models.IntegerField(primary_key=True)
60 code = models.CharField(max_length=10, unique=True)
61 employe = models.ForeignKey('Employe', db_column='employe')
62 # Postes
63 poste1 = models.ForeignKey('Poste', db_column='poste1',
64 related_name='dossiers_poste1')
65 implantation1 = models.ForeignKey('datamaster_modeles.Implantation',
66 db_column='implantation1',
67 related_name='dossiers_implantation1',
68 blank=True, null=True)
69 complement1 = models.TextField(null=True, blank=True)
70 responsable_implantation1 = models.IntegerField()
71 poste2 = models.ForeignKey('Poste', db_column='poste2',
72 related_name='dossiers_poste2',
73 blank=True, null=True)
74 implantation2 = models.ForeignKey('datamaster_modeles.Implantation',
75 db_column='implantation2',
76 related_name='dossiers_implantation2',
77 null=True, blank=True)
78 complement2 = models.TextField(null=True, blank=True)
79 responsable_implantation2 = models.IntegerField()
80 # Relations
81 service = models.ForeignKey('Service', db_column='service',
82 blank=True, null=True)
83 responsable = models.ForeignKey('Employe', db_column='responsable',
84 related_name='responsable_de',
85 blank=True, null=True)
86 remplacement_de = models.ForeignKey('Employe', db_column='remplacement_de',
87 related_name='replaced_by',
88 blank=True, null=True)
89 type = models.CharField(max_length=1, choices=TYPE_DOSSIER_CHOICES)
90 statut = models.ForeignKey('Statut', db_column='statut',
91 blank=True, null=True)
92 organisme_bstg = models.ForeignKey('OrganismeBstg',
93 db_column='organisme_bstg',
94 blank=True, null=True)
95 # Rémunération
96 classement = models.ForeignKey('Classement', db_column='classement',
97 blank=True, null=True)
98 regime_travail = models.IntegerField()
99 # Mandat
100 mandat_date_debut = models.DateField()
101 mandat_date_fin = models.DateField(null=True, blank=True)
102 # Contrat
103 contrat_date_debut = models.DateField()
104 contrat_date_fin = models.DateField()
105 type_contrat = models.ForeignKey('TypeContrat', db_column='type_contrat',
106 blank=True, null=True)
107 # Meta
108 date_creation = models.DateField(auto_now_add=True)
109 date_maj = models.DateField(auto_now=True)
110 commentaire = models.TextField(null=True, blank=True)
111
112 def __unicode__(self):
113 return u'%s : %s %s' % (self.employe, self.poste1, self.complement1)
114
115 LIEN_PARENTE_CHOICES = (
116 ('Conjoint', 'Conjoint'),
117 ('Conjointe', 'Conjointe'),
118 ('Fille', 'Fille'),
119 ('Fils', 'Fils'),
120 )
121
122 class AyantDroit(models.Model):
123 # Identification
124 id = models.IntegerField(primary_key=True)
125 nom = models.CharField(max_length=255)
126 prenom = models.CharField(max_length=255)
127 # Relation
128 employe = models.ForeignKey('Employe', db_column='employe',
129 related_name='ayants_droit')
130 lien_parente = models.CharField(max_length=10, null=True, blank=True,
131 choices=LIEN_PARENTE_CHOICES)
132 # Méta
133 commentaire = models.TextField(null=True, blank=True)
134 actif = models.BooleanField()
135
136
137 class Remuneration(models.Model):
138 # Identification
139 id = models.IntegerField(primary_key=True)
140 dossier = models.ForeignKey('Dossier', db_column='dossier')
141 type = models.ForeignKey('TypeRemuneration', db_column='type')
142 type_revalorisation = models.ForeignKey('TypeRevalorisation',
143 db_column='type_revalorisation',
144 null=True, blank=True)
145 montant = models.FloatField(null=True, blank=True)
146 devise = models.ForeignKey('Devise', to_field='code', db_column='devise',
147 null=True, blank=True)
148 date_effective = models.DateField(null=True, blank=True)
149 pourcentage = models.IntegerField(null=True, blank=True)
150 # Méta
151 date_creation = models.DateField(auto_now_add=True)
152 user_creation = models.IntegerField(null=True, blank=True) #User ou employé
153 desactivation = models.BooleanField(null=True, blank=True) #
154 date_desactivation = models.DateField(null=True, blank=True)
155 user_desactivation = models.IntegerField(null=True, blank=True) #User ou employé
156 annulation = models.BooleanField(null=True, blank=True)
157 date_annulation = models.DateField(null=True, blank=True)
158 user_annulation = models.IntegerField(null=True, blank=True) #User ou employé
159
160 def __unicode__(self):
161 try:
162 devise = self.devise.code
163 except:
164 devise = "???"
165 return "%s %s" % (self.montant, devise)
166
167 class FamilleEmploi(models.Model):
168 # Identification
169 id = models.IntegerField(primary_key=True)
170 nom = models.CharField(max_length=255)
171 # Méta
172 actif = models.BooleanField()
173
174 class TypePoste(models.Model):
175 # Identification
176 id = models.IntegerField(primary_key=True)
177 nom = models.CharField(max_length=255)
178 nom_feminin = models.CharField(max_length=255)
179 description = models.CharField(max_length=255)
180 is_responsable = models.BooleanField()
181 famille_emploi = models.ForeignKey('FamilleEmploi',
182 db_column='famille_emploi')
183 # Méta
184 date_modification = models.DateField(auto_now=True)
185 actif = models.BooleanField()
186
187 def __unicode__(self):
188 return u'%s' % self.nom
189
190
191 TYPE_PAIEMENT_CHOICES = (
192 ('Régulier', 'Régulier'),
193 ('Ponctuel', 'Ponctuel'),
194 )
195
196 NATURE_REMUNERATION_CHOICES = (
197 ('Accessoire', 'Accessoire'),
198 ('Charges', 'Charges'),
199 ('Indemnité', 'Indemnité'),
200 ('RAS', 'RAS'),
201 ('Traitement', 'Traitement'),
202 )
203
204 class TypeRemuneration(models.Model):
205 # Identification
206 id = models.IntegerField(primary_key=True)
207 nom = models.CharField(max_length=255)
208 type_paiement = models.CharField(max_length=30,
209 choices=TYPE_PAIEMENT_CHOICES)
210 nature_remuneration = models.CharField(max_length=30,
211 choices=NATURE_REMUNERATION_CHOICES)
212 # Méta
213 actif = models.BooleanField()
214
215 def __unicode__(self):
216 return u'%s' % self.nom
217
218 class TypeRevalorisation(models.Model):
219 # Identification
220 id = models.IntegerField(primary_key=True)
221 nom = models.CharField(max_length=255)
222 # Méta
223 actif = models.BooleanField()
224
225 PROPORTION_CHOICES = (
226 ('0.5', '0.5'),
227 ('1', '1'),
228 )
229
230 class Poste(models.Model):
231 # Identification
232 id = models.IntegerField(primary_key=True)
233 implantation = models.ForeignKey('datamaster_modeles.Implantation',
234 db_column='implantation', related_name='postes')
235 type_poste = models.ForeignKey('TypePoste', db_column='type_poste')
236 proportion = models.CharField(max_length=10, choices=PROPORTION_CHOICES)
237 #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%)
238 # Méta
239 date_modification = models.DateField(auto_now=True)
240 actif = models.BooleanField()
241
242
243 def __unicode__(self):
244 return u'%s - %s [%s]' % (self.implantation, self.type_poste.nom,
245 self.id)
246
247
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
255 def __unicode__(self):
256 return u'%s' % self.nom
257
258 class Meta:
259 ordering = ['nom']
260
261
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
275 def __unicode__(self):
276 return u'%s (%s)' % (self.nom, self.type)
277
278 class Meta:
279 ordering = ['type', 'nom']
280
281 CONTRAT_CATEGORIE_CHOICES= (
282 ('A', 'A'),
283 ('C', 'C'),
284 )
285 class Statut(models.Model):
286 # Identification
287 id = models.IntegerField(primary_key=True)
288 code = models.CharField(max_length=25, unique=True)
289 nom = models.CharField(max_length=255)
290 type_contrat_categorie = models.CharField(max_length=10,
291 choices=CONTRAT_CATEGORIE_CHOICES)
292 #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie
293 # Méta
294 actif = models.BooleanField()
295
296 def __unicode__(self):
297 return u'%s : %s' % (self.code, self.nom)
298
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
315 def __unicode__(self):
316 return u'%s.%s.%s (%s)' % (self.type, self.echelon, self.degre,
317 self.coefficient)
318 class Meta:
319 ordering = ['type','echelon','degre','coefficient']
320
321
322 class TauxChange(models.Model):
323 # Identification
324 id = models.IntegerField(primary_key=True)
325 devise = models.ForeignKey('Devise', to_field='code', db_column='devise')
326 annee = models.IntegerField()
327 taux = models.FloatField()
328 # Relations
329 implantation = models.ForeignKey('datamaster_modeles.Implantation',
330 db_column='implantation',
331 related_name='taux_change')
332
333
334 class ValeurPoint(models.Model):
335 # Identification
336 id = models.IntegerField(primary_key=True)
337 valeur = models.FloatField()
338 implantation = models.ForeignKey('datamaster_modeles.Implantation',
339 db_column='implantation',
340 related_name='valeurs_point')
341 # Méta
342 annee = models.IntegerField()
343
344 # Stockage de tous les taux de change pour optimiser la recherche de la devise associée
345 annee_courante = datetime.datetime.now().year
346 tauxchange = TauxChange.objects.select_related('devise').filter(annee=annee_courante)
347
348 def __unicode__(self):
349 tx = self.get_tauxchange_courant()
350 if tx:
351 devise_code = tx.devise.code
352 else:
353 devise_code = "??"
354 return u'%s %s (%s-%s)' % (self.valeur, devise_code, self.implantation_id, self.annee)
355
356 class Meta:
357 ordering = ['valeur']
358
359
360 class Devise(models.Model):
361 id = models.IntegerField(primary_key=True)
362 code = models.CharField(max_length=10, unique=True)
363 nom = models.CharField(max_length=255)
364
365 def __unicode__(self):
366 return u'%s - %s' % (self.code, self.nom)
367
368
369 class TypeContrat(models.Model):
370 # Identification
371 id = models.IntegerField(primary_key=True)
372 nom = models.CharField(max_length=255)
373 nom_long = models.CharField(max_length=255) #description
374 categorie = models.CharField(max_length=10,
375 choices=CONTRAT_CATEGORIE_CHOICES)
376 # Méta
377 actif = models.BooleanField()
378
379 def __unicode__(self):
380 return u'%s' % (self.nom)