8cb8169c2411ecf579e6e58d148d6640f2d4ef98
[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 class Meta:
173 ordering = ['nom']
174
175
176 TYPE_PAIEMENT_CHOICES = (
177 ('Régulier', 'Régulier'),
178 ('Ponctuel', 'Ponctuel'),
179 )
180
181 NATURE_REMUNERATION_CHOICES = (
182 ('Accessoire', 'Accessoire'),
183 ('Charges', 'Charges'),
184 ('Indemnité', 'Indemnité'),
185 ('RAS', 'RAS'),
186 ('Traitement', 'Traitement'),
187 )
188
189 class TypeRemuneration(models.Model):
190 #Identification
191 id = models.IntegerField(primary_key=True)
192 nom = models.CharField(max_length=255)
193 type_paiement = models.CharField(max_length=30, choices=TYPE_PAIEMENT_CHOICES)
194 nature_remuneration = models.CharField(max_length=30, choices=NATURE_REMUNERATION_CHOICES)
195 #Méta
196 actif = models.BooleanField()
197
198 class TypeRevalorisation(models.Model):
199 #Identification
200 id = models.IntegerField(primary_key=True)
201 nom = models.CharField(max_length=255)
202 #Méta
203 actif = models.BooleanField()
204
205 PROPORTION_CHOICES = (
206 ('0.5', '0.5'),
207 ('1', '1'),
208 )
209
210 class PosteManager(models.Manager):
211 """
212 Chargement de tous les objets FK existants sur chaque QuerySet.
213 """
214 def get_query_set(self):
215 fkeys = (
216 'implantation',
217 'type_poste',
218 )
219 return super(PosteManager, self).get_query_set().select_related(*fkeys).all()
220
221 class Poste(models.Model):
222 #Identification
223 id = models.IntegerField(primary_key=True)
224 implantation = models.ForeignKey('datamaster_modeles.Implantation',
225 db_column='implantation', related_name='+')
226 type_poste = models.ForeignKey('TypePoste', db_column='type_poste')
227 proportion = models.CharField(max_length=10, choices=PROPORTION_CHOICES)
228 #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%)
229 #Méta
230 date_modification = models.DateField(auto_now=True)
231 actif = models.BooleanField()
232
233 # Managers
234 objects = PosteManager()
235
236 def __unicode__(self):
237 return u'%s - %s [%s]' % (self.implantation, self.type_poste.nom, self.id)
238
239
240 class Service(models.Model):
241 #Identification
242 id = models.IntegerField(primary_key=True)
243 nom = models.CharField(max_length=255)
244 #Méta
245 actif = models.BooleanField()
246
247 def __unicode__(self):
248 return u'%s' % self.nom
249
250 class Meta:
251 ordering = ['nom']
252
253
254 TYPE_ORGANISME_CHOICES = (
255 ('MAD', 'Mise à disposition'),
256 ('DET', 'Détachement'),
257 )
258
259 class OrganismeBstg(models.Model):
260 #Identification
261 id = models.IntegerField(primary_key=True)
262 nom = models.CharField(max_length=255)
263 type = models.CharField(max_length=10, choices=TYPE_ORGANISME_CHOICES)
264 #Méta
265 actif = models.BooleanField()
266
267 def __unicode__(self):
268 return u'%s (%s)' % (self.nom, self.type)
269
270
271 CONTRAT_CATEGORIE_CHOICES= (
272 ('A', 'A'),
273 ('C', 'C'),
274 )
275 class Statut(models.Model):
276 #Identification
277 id = models.IntegerField(primary_key=True)
278 code = models.CharField(max_length=25, unique=True)
279 nom = models.CharField(max_length=255)
280 type_contrat_categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES)
281 #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie
282 #Méta
283 actif = models.BooleanField()
284
285 def __unicode__(self):
286 return u'%s' % self.nom
287
288 TYPE_CLASSEMENT_CHOICES = (
289 ('S', 'S'),
290 ('T', 'T'),
291 )
292 class Classement(models.Model):
293 #Identification
294 id = models.IntegerField(primary_key=True)
295 type = models.CharField(max_length=10, choices=TYPE_CLASSEMENT_CHOICES)
296 echelon = models.IntegerField()
297 degre = models.IntegerField()
298 coefficient = models.FloatField()
299 #Méta
300 commentaire = models.TextField(null=True, blank=True)
301 date_modification = models.DateField(auto_now=True)
302 actif = models.BooleanField()
303
304 def __unicode__(self):
305 return u'%s.%s.%s (%s)' % (self.type, self.echelon, self.degre,
306 self.coefficient)
307
308
309 class ValeurPoint(models.Model):
310 #Identification
311 id = models.IntegerField(primary_key=True)
312 valeur = models.FloatField()
313 implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation')
314 #Méta
315 annee = models.IntegerField()
316
317 def __unicode__(self):
318 return u'%s (%s-%s)' % (self.valeur, self.implantation_id, self.annee)
319
320 class Meta:
321 ordering = ['valeur']
322
323
324 class TauxChange(models.Model):
325 #Identification
326 id = models.IntegerField(primary_key=True)
327 devise = models.ForeignKey('Devise', db_column='devise')
328 annee = models.IntegerField()
329 taux = models.FloatField()
330 #Relations
331 implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation')
332
333
334 class Devise(models.Model):
335 id = models.IntegerField(primary_key=True)
336 code = models.CharField(max_length=10, unique=True)
337 nom = models.CharField(max_length=255)
338
339 def __unicode__(self):
340 return u'%s - %s' % (self.code, self.nom)
341
342
343 class TypeContrat(models.Model):
344 #Identification
345 id = models.IntegerField(primary_key=True)
346 nom = models.CharField(max_length=255)
347 nom_long = models.CharField(max_length=255) #description
348 categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES)
349 #Méta
350 actif = models.BooleanField()
351
352 def __unicode__(self):
353 return u'%s - %s' % (self.categorie, self.nom)