Merge remote branch 'origin/dev' into dae
[auf_rh_dae.git] / project / rh_v1 / models.py
1 # -=- encoding: utf-8 -=-
2
3 from django.db import models
4 from datamaster_modeles.models import Pays, Implantation
5
6 GENRE_CHOICES = (
7 ('m', 'Homme'),
8 ('f', 'Femme'),
9 )
10 SITUATION_CHOICES = (
11 ('C', 'Célibataire'),
12 ('F', 'Fiancé'),
13 ('M', 'Marié'),
14 )
15
16 class Employe(models.Model):
17 #Identification
18 id = models.IntegerField(primary_key=True)
19 nom = models.CharField(max_length=255)
20 prenom = models.CharField(max_length=255)
21 nationalite = models.ForeignKey('datamaster_modeles.Pays', to_field='code', related_name='nationalite', db_column='nationalite')
22 date_naissance = models.DateField(null=True, blank=True)
23 #Infos personnelles
24 genre = models.CharField(max_length=1, choices=GENRE_CHOICES, null=True, blank=True)
25 situation_famille = models.CharField(max_length=1, choices=SITUATION_CHOICES, null=True, blank=True)
26 date_entree = models.DateField(null=True, blank=True) #devrait pas être là
27 #Coordonnées
28 tel_domicile = models.CharField(max_length=255, null=True, blank=True)
29 tel_cellulaire = models.CharField(max_length=255, null=True, blank=True)
30 adresse = models.CharField(max_length=255, null=True, blank=True)
31 no_rue = models.CharField(max_length=255, null=True, blank=True)
32 ville = models.CharField(max_length=255, null=True, blank=True)
33 province = models.CharField(max_length=255, null=True, blank=True)
34 code_postal = models.CharField(max_length=255, null=True, blank=True)
35 pays = models.ForeignKey('datamaster_modeles.Pays', to_field='code', null=True, blank=True, related_name='pays', db_column='pays')
36 #Métas
37 date_creation = models.DateField(auto_now_add=True)
38 date_maj = models.DateField(auto_now=True)
39 commentaire = models.TextField(null=True, blank=True)
40
41 def __unicode__(self):
42 return u'%s %s' % (self.prenom, self.nom)
43
44
45 TYPE_DOSSIER_CHOICES = (
46 ('2', 'Local'),
47 ('1', 'Expatrié'),
48 )
49
50 class DossierManager(models.Manager):
51 """
52 Chargement de tous les objets FK existants sur chaque QuerySet.
53 """
54 def get_query_set(self):
55 fkeys = (
56 'employe',
57 'poste1',
58 'implantation1',
59 'poste2',
60 'implantation2',
61 'service',
62 'responsable',
63 'remplacement_de',
64 'statut',
65 'organisme_bstg',
66 'classement',
67 'type_contrat',
68 )
69 return super(DossierManager, self).get_query_set().select_related(*fkeys).all()
70
71 class Dossier(models.Model):
72 #Identification
73 id = models.IntegerField(primary_key=True)
74 code = models.CharField(max_length=10, unique=True)
75 employe = models.ForeignKey('Employe', db_column='employe')
76 #Postes
77 poste1 = models.ForeignKey('Poste', db_column='poste1', related_name='poste1')
78 implantation1 = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation1', related_name='implantation1')
79 complement1 = models.TextField(null=True, blank=True)
80 responsable_implantation1 = models.IntegerField()
81 poste2 = models.ForeignKey('Poste', db_column='poste2', related_name='poste2', blank=True, null=True)
82 implantation2 = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation2', related_name='implantation2')
83 complement2 = models.TextField(null=True, blank=True)
84 responsable_implantation2 = models.IntegerField()
85 #Relations
86 service = models.ForeignKey('Service', db_column='service')
87 responsable = models.ForeignKey('Employe', db_column='responsable', related_name='responsable')
88 remplacement_de = models.ForeignKey('Employe', db_column='remplacement_de', related_name='remplacement_de')
89 type = models.CharField(max_length=1, choices=TYPE_DOSSIER_CHOICES)
90 statut = models.ForeignKey('Statut', db_column='statut')
91 organisme_bstg = models.ForeignKey('OrganismeBstg', db_column='organisme_bstg')
92 #Rémunération
93 classement = models.ForeignKey('Classement', db_column='classement')
94 regime_travail = models.IntegerField()
95 #Mandat
96 mandat_date_debut = models.DateField()
97 mandat_date_fin = models.DateField()
98 #Contrat
99 contrat_date_debut = models.DateField()
100 contrat_date_fin = models.DateField()
101 type_contrat = models.ForeignKey('TypeContrat', db_column='type_contrat')
102 #Meta
103 date_creation = models.DateField(auto_now_add=True)
104 date_maj = models.DateField(auto_now=True)
105 commentaire = models.TextField(null=True, blank=True)
106
107 # Managers
108 objects = DossierManager()
109
110 LIEN_PARENTE_CHOICES = (
111 ('Conjoint', 'Conjoint'),
112 ('Conjointe', 'Conjointe'),
113 ('Fille', 'Fille'),
114 ('Fils', 'Fils'),
115 )
116
117 class AyantDroit(models.Model):
118 #Identification
119 id = models.IntegerField(primary_key=True)
120 nom = models.CharField(max_length=255)
121 prenom = models.CharField(max_length=255)
122 #Relation
123 employe = models.ForeignKey('Employe', db_column='employe', related_name='employe')
124 lien_parente = models.CharField(max_length=10, choices=LIEN_PARENTE_CHOICES, null=True, blank=True)
125 #Méta
126 commentaire = models.TextField(null=True, blank=True)
127 actif = models.BooleanField()
128
129
130 class Remuneration(models.Model):
131 #Identification
132 id = models.IntegerField(primary_key=True)
133 dossier = models.ForeignKey('Dossier', db_column='dossier')
134 type = models.ForeignKey('TypeRemuneration', db_column='type')
135 type_revalorisation = models.ForeignKey('TypeRevalorisation', db_column='type_revalorisation', null=True, blank=True)
136 montant = models.FloatField(null=True, blank=True)
137 devise = models.ForeignKey('Devise', to_field='code', db_column='devise', null=True, blank=True)
138 date_effective = models.DateField(null=True, blank=True)
139 pourcentage = models.IntegerField(null=True, blank=True)
140 #Méta
141 date_creation = models.DateField(auto_now_add=True)
142 user_creation = models.IntegerField(null=True, blank=True) #User ou employé
143 desactivation = models.NullBooleanField(null=True, blank=True) #
144 date_desactivation = models.DateField(null=True, blank=True)
145 user_desactivation = models.IntegerField(null=True, blank=True) #User ou employé
146 annulation = models.NullBooleanField(null=True, blank=True)
147 date_annulation = models.DateField(null=True, blank=True)
148 user_annulation = models.IntegerField(null=True, blank=True) #User ou employé
149
150 class FamilleEmploi(models.Model):
151 #Identification
152 id = models.IntegerField(primary_key=True)
153 nom = models.CharField(max_length=255)
154 #Méta
155 actif = models.BooleanField()
156
157 class TypePoste(models.Model):
158 #Identification
159 id = models.IntegerField(primary_key=True)
160 nom = models.CharField(max_length=255)
161 nom_feminin = models.CharField(max_length=255)
162 description = models.CharField(max_length=255)
163 is_responsable = models.BooleanField()
164 famille_emploi = models.ForeignKey('FamilleEmploi', db_column='famille_emploi')
165 #Méta
166 date_modification = models.DateField(auto_now=True)
167 actif = models.BooleanField()
168
169 def __unicode__(self):
170 return u'%s' % self.nom
171
172
173 TYPE_PAIEMENT_CHOICES = (
174 ('Régulier', 'Régulier'),
175 ('Ponctuel', 'Ponctuel'),
176 )
177
178 NATURE_REMUNERATION_CHOICES = (
179 ('Accessoire', 'Accessoire'),
180 ('Charges', 'Charges'),
181 ('Indemnité', 'Indemnité'),
182 ('RAS', 'RAS'),
183 ('Traitement', 'Traitement'),
184 )
185
186 class TypeRemuneration(models.Model):
187 #Identification
188 id = models.IntegerField(primary_key=True)
189 nom = models.CharField(max_length=255)
190 type_paiement = models.CharField(max_length=30, choices=TYPE_PAIEMENT_CHOICES)
191 nature_remuneration = models.CharField(max_length=30, choices=NATURE_REMUNERATION_CHOICES)
192 #Méta
193 actif = models.BooleanField()
194
195 class TypeRevalorisation(models.Model):
196 #Identification
197 id = models.IntegerField(primary_key=True)
198 nom = models.CharField(max_length=255)
199 #Méta
200 actif = models.BooleanField()
201
202 PROPORTION_CHOICES = (
203 ('0.5', '0.5'),
204 ('1', '1'),
205 )
206
207 class PosteManager(models.Manager):
208 """
209 Chargement de tous les objets FK existants sur chaque QuerySet.
210 """
211 def get_query_set(self):
212 fkeys = (
213 'implantation',
214 'type_poste',
215 )
216 return super(PosteManager, self).get_query_set().select_related(*fkeys).all()
217
218 class Poste(models.Model):
219 #Identification
220 id = models.IntegerField(primary_key=True)
221 implantation = models.ForeignKey('datamaster_modeles.Implantation',
222 db_column='implantation', related_name='+')
223 type_poste = models.ForeignKey('TypePoste', db_column='type_poste')
224 proportion = models.CharField(max_length=10, choices=PROPORTION_CHOICES)
225 #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%)
226 #Méta
227 date_modification = models.DateField(auto_now=True)
228 actif = models.BooleanField()
229
230 # Managers
231 objects = PosteManager()
232
233 def __unicode__(self):
234 return u'%s - %s' % (self.implantation, self.type_poste.nom)
235
236
237 class Service(models.Model):
238 #Identification
239 id = models.IntegerField(primary_key=True)
240 nom = models.CharField(max_length=255)
241 #Méta
242 actif = models.BooleanField()
243
244 def __unicode__(self):
245 return u'%s' % self.nom
246
247
248 TYPE_ORGANISME_CHOICES = (
249 ('MAD', 'Mise à disposition'),
250 ('DET', 'Détachement'),
251 )
252
253 class OrganismeBstg(models.Model):
254 #Identification
255 id = models.IntegerField(primary_key=True)
256 nom = models.CharField(max_length=255)
257 type = models.CharField(max_length=10, choices=TYPE_ORGANISME_CHOICES)
258 #Méta
259 actif = models.BooleanField()
260
261 def __unicode__(self):
262 return u'%s (%s)' % (self.nom, self.type)
263
264
265 CONTRAT_CATEGORIE_CHOICES= (
266 ('A', 'A'),
267 ('C', 'C'),
268 )
269 class Statut(models.Model):
270 #Identification
271 id = models.IntegerField(primary_key=True)
272 code = models.CharField(max_length=25, unique=True)
273 nom = models.CharField(max_length=255)
274 type_contrat_categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES)
275 #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie
276 #Méta
277 actif = models.BooleanField()
278
279 def __unicode__(self):
280 return u'%s' % self.nom
281
282 TYPE_CLASSEMENT_CHOICES = (
283 ('S', 'S'),
284 ('T', 'T'),
285 )
286 class Classement(models.Model):
287 #Identification
288 id = models.IntegerField(primary_key=True)
289 type = models.CharField(max_length=10, choices=TYPE_CLASSEMENT_CHOICES)
290 echelon = models.IntegerField()
291 degre = models.IntegerField()
292 coefficient = models.FloatField()
293 #Méta
294 commentaire = models.TextField(null=True, blank=True)
295 date_modification = models.DateField(auto_now=True)
296 actif = models.BooleanField()
297
298 def __unicode__(self):
299 return u'%s.%s.%s (%s)' % (self.type, self.echelon, self.degre,
300 self.coefficient)
301
302
303 class ValeurPoint(models.Model):
304 #Identification
305 id = models.IntegerField(primary_key=True)
306 valeur = models.FloatField()
307 implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation')
308 #Méta
309 annee = models.IntegerField()
310
311 def __unicode__(self):
312 return u'%s (%s-%s)' % (self.valeur, self.implantation_id, self.annee)
313
314
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
325 class Devise(models.Model):
326 id = models.IntegerField(primary_key=True)
327 code = models.CharField(max_length=10, unique=True)
328 nom = models.CharField(max_length=255)
329
330 def __unicode__(self):
331 return u'%s - %s' % (self.code, self.nom)
332
333
334 class TypeContrat(models.Model):
335 #Identification
336 id = models.IntegerField(primary_key=True)
337 nom = models.CharField(max_length=255)
338 nom_long = models.CharField(max_length=255) #description
339 categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES)
340 #Méta
341 actif = models.BooleanField()
342
343 def __unicode__(self):
344 return u'%s - %s' % (self.categorie, self.nom)