ajout des managers pour optimiser la génération du form
[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 TYPE_DOSSIER_CHOICES = (
42 ('2', 'Local'),
43 ('1', 'Expatrié'),
44 )
45
46 class DossierManager(models.Manager):
47 """
48 Chargement de tous les objets FK existants sur chaque QuerySet.
49 """
50 def get_query_set(self):
51 fkeys = (
52 'employe',
53 'poste1',
54 'implantation1',
55 'poste2',
56 'implantation2',
57 'service',
58 'responsable',
59 'remplacement_de',
60 'statut',
61 'organisme_bstg',
62 'classement',
63 'type_contrat',
64 )
65 return super(DossierManager, self).get_query_set().select_related(*fkeys).all()
66
67 class Dossier(models.Model):
68 #Identification
69 id = models.IntegerField(primary_key=True)
70 code = models.CharField(max_length=10, unique=True)
71 employe = models.ForeignKey('Employe', db_column='employe')
72 #Postes
73 poste1 = models.ForeignKey('Poste', db_column='poste1', related_name='poste1')
74 implantation1 = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation1', related_name='implantation1')
75 complement1 = models.TextField(null=True, blank=True)
76 responsable_implantation1 = models.IntegerField()
77 poste2 = models.ForeignKey('Poste', db_column='poste2', related_name='poste2', blank=True, null=True)
78 implantation2 = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation2', related_name='implantation2')
79 complement2 = models.TextField(null=True, blank=True)
80 responsable_implantation2 = models.IntegerField()
81 #Relations
82 service = models.ForeignKey('Service', db_column='service')
83 responsable = models.ForeignKey('Employe', db_column='responsable', related_name='responsable')
84 remplacement_de = models.ForeignKey('Employe', db_column='remplacement_de', related_name='remplacement_de')
85 type = models.CharField(max_length=1, choices=TYPE_DOSSIER_CHOICES)
86 statut = models.ForeignKey('Statut', db_column='statut')
87 organisme_bstg = models.ForeignKey('OrganismeBstg', db_column='organisme_bstg')
88 #Rémunération
89 classement = models.ForeignKey('Classement', db_column='classement')
90 regime_travail = models.IntegerField()
91 #Mandat
92 mandat_date_debut = models.DateField()
93 mandat_date_fin = models.DateField()
94 #Contrat
95 contrat_date_debut = models.DateField()
96 contrat_date_fin = models.DateField()
97 type_contrat = models.ForeignKey('TypeContrat', db_column='type_contrat')
98 #Meta
99 date_creation = models.DateField(auto_now_add=True)
100 date_maj = models.DateField(auto_now=True)
101 commentaire = models.TextField(null=True, blank=True)
102
103 # Managers
104 objects = DossierManager()
105
106 LIEN_PARENTE_CHOICES = (
107 ('Conjoint', 'Conjoint'),
108 ('Conjointe', 'Conjointe'),
109 ('Fille', 'Fille'),
110 ('Fils', 'Fils'),
111 )
112
113 class AyantDroit(models.Model):
114 #Identification
115 id = models.IntegerField(primary_key=True)
116 nom = models.CharField(max_length=255)
117 prenom = models.CharField(max_length=255)
118 #Relation
119 employe = models.ForeignKey('Employe', db_column='employe', related_name='employe')
120 lien_parente = models.CharField(max_length=10, choices=LIEN_PARENTE_CHOICES, null=True, blank=True)
121 #Méta
122 commentaire = models.TextField(null=True, blank=True)
123 actif = models.BooleanField()
124
125
126 class Remuneration(models.Model):
127 #Identification
128 id = models.IntegerField(primary_key=True)
129 dossier = models.ForeignKey('Dossier', db_column='dossier')
130 type = models.ForeignKey('TypeRemuneration', db_column='type')
131 type_revalorisation = models.ForeignKey('TypeRevalorisation', db_column='type_revalorisation')
132 montant = models.FloatField()
133 devise = models.ForeignKey('Devise', to_field='code', db_column='devise')
134 date_effective = models.DateField()
135 pourcentage = models.IntegerField()
136 #Méta
137 date_creation = models.DateField(auto_now_add=True)
138 user_creation = models.IntegerField() #User ou employé
139 desactivation = models.BooleanField() #
140 date_desactivation = models.DateField()
141 user_desactivation = models.IntegerField() #User ou employé
142 annule = models.BooleanField()
143 date_annule = models.DateField()
144 user_annule = models.IntegerField() #User ou employé
145
146 class FamilleEmploi(models.Model):
147 #Identification
148 id = models.IntegerField(primary_key=True)
149 nom = models.CharField(max_length=255)
150 #Méta
151 actif = models.BooleanField()
152
153 class TypePoste(models.Model):
154 #Identification
155 id = models.IntegerField(primary_key=True)
156 nom = models.CharField(max_length=255)
157 nom_feminin = models.CharField(max_length=255)
158 description = models.CharField(max_length=255)
159 is_responsable = models.BooleanField()
160 famille_emploi = models.ForeignKey('FamilleEmploi', db_column='famille_emploi')
161 #Méta
162 date_modification = models.DateField(auto_now=True)
163 actif = models.BooleanField()
164
165 def __unicode__(self):
166 return u'%s' % self.nom
167
168
169 TYPE_PAIEMENT_CHOICES = (
170 ('Régulier', 'Régulier'),
171 ('Ponctuel', 'Ponctuel'),
172 )
173
174 NATURE_REMUNERATION_CHOICES = (
175 ('Accessoire', 'Accessoire'),
176 ('Charges', 'Charges'),
177 ('Indemnité', 'Indemnité'),
178 ('RAS', 'RAS'),
179 ('Traitement', 'Traitement'),
180 )
181
182 class TypeRemuneration(models.Model):
183 #Identification
184 id = models.IntegerField(primary_key=True)
185 nom = models.CharField(max_length=255)
186 type_paiement = models.CharField(max_length=30, choices=TYPE_PAIEMENT_CHOICES)
187 nature_remuneration = models.CharField(max_length=30, choices=NATURE_REMUNERATION_CHOICES)
188 #Méta
189 actif = models.BooleanField()
190
191 class TypeRevalorisation(models.Model):
192 #Identification
193 id = models.IntegerField(primary_key=True)
194 nom = models.CharField(max_length=255)
195 #Méta
196 actif = models.BooleanField()
197
198 PROPORTION_CHOICES = (
199 ('0.5', '0.5'),
200 ('1', '1'),
201 )
202
203 class PosteManager(models.Manager):
204 """
205 Chargement de tous les objets FK existants sur chaque QuerySet.
206 """
207 def get_query_set(self):
208 fkeys = (
209 'implantation',
210 'type_poste',
211 )
212 return super(PosteManager, self).get_query_set().select_related(*fkeys).all()
213
214 class Poste(models.Model):
215 #Identification
216 id = models.IntegerField(primary_key=True)
217 implantation = models.ForeignKey('datamaster_modeles.Implantation',
218 db_column='implantation', related_name='+')
219 type_poste = models.ForeignKey('TypePoste', db_column='type_poste')
220 proportion = models.CharField(max_length=10, choices=PROPORTION_CHOICES)
221 #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%)
222 #Méta
223 date_modification = models.DateField(auto_now=True)
224 actif = models.BooleanField()
225
226 # Managers
227 objects = PosteManager()
228
229 def __unicode__(self):
230 return u'%s - %s' % (self.implantation, self.type_poste.nom)
231
232
233 class Service(models.Model):
234 #Identification
235 id = models.IntegerField(primary_key=True)
236 nom = models.CharField(max_length=255)
237 #Méta
238 actif = models.BooleanField()
239
240 def __unicode__(self):
241 return u'%s' % self.nom
242
243
244 TYPE_ORGANISME_CHOICES = (
245 ('MAD', 'Mise à disposition'),
246 ('DET', 'Détachement'),
247 )
248
249 class OrganismeBstg(models.Model):
250 #Identification
251 id = models.IntegerField(primary_key=True)
252 nom = models.CharField(max_length=255)
253 type = models.CharField(max_length=10, choices=TYPE_ORGANISME_CHOICES)
254 #Méta
255 actif = models.BooleanField()
256
257 CONTRAT_CATEGORIE_CHOICES= (
258 ('A', 'A'),
259 ('C', 'C'),
260 )
261 class Statut(models.Model):
262 #Identification
263 id = models.IntegerField(primary_key=True)
264 code = models.CharField(max_length=25, unique=True)
265 nom = models.CharField(max_length=255)
266 type_contrat_categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES)
267 #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie
268 #Méta
269 actif = models.BooleanField()
270
271 TYPE_CLASSEMENT_CHOICES = (
272 ('S', 'S'),
273 ('T', 'T'),
274 )
275 class Classement(models.Model):
276 #Identification
277 id = models.IntegerField(primary_key=True)
278 type = models.CharField(max_length=10, choices=TYPE_CLASSEMENT_CHOICES)
279 echelon = models.IntegerField()
280 degre = models.IntegerField()
281 coefficient = models.FloatField()
282 #Méta
283 commentaire = models.TextField(null=True, blank=True)
284 date_modification = models.DateField(auto_now=True)
285 actif = models.BooleanField()
286
287 def __unicode__(self):
288 return u'%s.%s.%s (%s)' % (self.type, self.echelon, self.degre,
289 self.coefficient)
290
291
292 class ValeurPoint(models.Model):
293 #Identification
294 id = models.IntegerField(primary_key=True)
295 valeur = models.FloatField()
296 implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation')
297 #Méta
298 annee = models.IntegerField()
299
300 def __unicode__(self):
301 return u'%s (%s-%s)' % (self.valeur, self.implantation_id, self.annee)
302
303
304 class TauxChange(models.Model):
305 #Identification
306 id = models.IntegerField(primary_key=True)
307 devise = models.ForeignKey('Devise', to_field='code', db_column='devise')
308 annee = models.IntegerField()
309 taux = models.FloatField()
310 #Relations
311 implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation')
312
313
314 class Devise(models.Model):
315 id = models.IntegerField(primary_key=True)
316 code = models.CharField(max_length=10, unique=True)
317 nom = models.CharField(max_length=255)
318
319 def __unicode__(self):
320 return u'%s - %s' % (self.code, self.nom)
321
322
323 class TypeContrat(models.Model):
324 #Identification
325 id = models.IntegerField(primary_key=True)
326 nom = models.CharField(max_length=255)
327 nom_long = models.CharField(max_length=255) #description
328 categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES)
329 #Méta
330 actif = models.BooleanField()
331