Commit | Line | Data |
---|---|---|
a3121a38 AJ |
1 | # -=- encoding: utf-8 -=- |
2 | ||
3 | from django.db import models | |
4 | from datamaster_modeles.models import Pays, Implantation | |
5 | ||
6 | GENRE_CHOICES = ( | |
139686f2 NC |
7 | ('m', 'Homme'), |
8 | ('f', 'Femme'), | |
a3121a38 AJ |
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) | |
139686f2 NC |
40 | |
41 | def __unicode__(self): | |
42 | return u'%s %s' % (self.prenom, self.nom) | |
43 | ||
44 | ||
a3121a38 AJ |
45 | TYPE_DOSSIER_CHOICES = ( |
46 | ('2', 'Local'), | |
47 | ('1', 'Expatrié'), | |
48 | ) | |
49 | ||
1c7d67ce OL |
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 | ||
a3121a38 AJ |
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') | |
f48decfd | 78 | implantation1 = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation1', related_name='implantation1', blank=True, null=True) |
a3121a38 AJ |
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) | |
f48decfd | 82 | implantation2 = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation2', related_name='implantation2', null=True, blank=True) |
a3121a38 AJ |
83 | complement2 = models.TextField(null=True, blank=True) |
84 | responsable_implantation2 = models.IntegerField() | |
85 | #Relations | |
f48decfd NC |
86 | service = models.ForeignKey('Service', db_column='service', blank=True, null=True) |
87 | responsable = models.ForeignKey('Employe', db_column='responsable', related_name='responsable', blank=True, null=True) | |
88 | remplacement_de = models.ForeignKey('Employe', db_column='remplacement_de', related_name='remplacement_de', blank=True, null=True) | |
a3121a38 | 89 | type = models.CharField(max_length=1, choices=TYPE_DOSSIER_CHOICES) |
f48decfd NC |
90 | statut = models.ForeignKey('Statut', db_column='statut', blank=True, null=True) |
91 | organisme_bstg = models.ForeignKey('OrganismeBstg', db_column='organisme_bstg', blank=True, null=True) | |
a3121a38 | 92 | #Rémunération |
f48decfd | 93 | classement = models.ForeignKey('Classement', db_column='classement', blank=True, null=True) |
a3121a38 AJ |
94 | regime_travail = models.IntegerField() |
95 | #Mandat | |
96 | mandat_date_debut = models.DateField() | |
f48decfd | 97 | mandat_date_fin = models.DateField(null=True, blank=True) |
a3121a38 AJ |
98 | #Contrat |
99 | contrat_date_debut = models.DateField() | |
100 | contrat_date_fin = models.DateField() | |
f48decfd | 101 | type_contrat = models.ForeignKey('TypeContrat', db_column='type_contrat', blank=True, null=True) |
a3121a38 AJ |
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 | ||
1c7d67ce OL |
107 | # Managers |
108 | objects = DossierManager() | |
0f23302a | 109 | |
110 | def __unicode__(self): | |
111 | return u'%s : %s %s' % (self.employe, self.poste1, self.complement1) | |
1c7d67ce | 112 | |
a3121a38 AJ |
113 | LIEN_PARENTE_CHOICES = ( |
114 | ('Conjoint', 'Conjoint'), | |
115 | ('Conjointe', 'Conjointe'), | |
116 | ('Fille', 'Fille'), | |
117 | ('Fils', 'Fils'), | |
118 | ) | |
119 | ||
120 | class AyantDroit(models.Model): | |
121 | #Identification | |
122 | id = models.IntegerField(primary_key=True) | |
123 | nom = models.CharField(max_length=255) | |
124 | prenom = models.CharField(max_length=255) | |
125 | #Relation | |
126 | employe = models.ForeignKey('Employe', db_column='employe', related_name='employe') | |
127 | lien_parente = models.CharField(max_length=10, choices=LIEN_PARENTE_CHOICES, null=True, blank=True) | |
128 | #Méta | |
129 | commentaire = models.TextField(null=True, blank=True) | |
130 | actif = models.BooleanField() | |
131 | ||
132 | ||
133 | class Remuneration(models.Model): | |
134 | #Identification | |
135 | id = models.IntegerField(primary_key=True) | |
136 | dossier = models.ForeignKey('Dossier', db_column='dossier') | |
137 | type = models.ForeignKey('TypeRemuneration', db_column='type') | |
139686f2 NC |
138 | type_revalorisation = models.ForeignKey('TypeRevalorisation', db_column='type_revalorisation', null=True, blank=True) |
139 | montant = models.FloatField(null=True, blank=True) | |
140 | devise = models.ForeignKey('Devise', to_field='code', db_column='devise', null=True, blank=True) | |
141 | date_effective = models.DateField(null=True, blank=True) | |
142 | pourcentage = models.IntegerField(null=True, blank=True) | |
a3121a38 AJ |
143 | #Méta |
144 | date_creation = models.DateField(auto_now_add=True) | |
139686f2 NC |
145 | user_creation = models.IntegerField(null=True, blank=True) #User ou employé |
146 | desactivation = models.NullBooleanField(null=True, blank=True) # | |
147 | date_desactivation = models.DateField(null=True, blank=True) | |
148 | user_desactivation = models.IntegerField(null=True, blank=True) #User ou employé | |
149 | annulation = models.NullBooleanField(null=True, blank=True) | |
150 | date_annulation = models.DateField(null=True, blank=True) | |
151 | user_annulation = models.IntegerField(null=True, blank=True) #User ou employé | |
a3121a38 AJ |
152 | |
153 | class FamilleEmploi(models.Model): | |
154 | #Identification | |
155 | id = models.IntegerField(primary_key=True) | |
156 | nom = models.CharField(max_length=255) | |
157 | #Méta | |
158 | actif = models.BooleanField() | |
159 | ||
160 | class TypePoste(models.Model): | |
161 | #Identification | |
162 | id = models.IntegerField(primary_key=True) | |
163 | nom = models.CharField(max_length=255) | |
164 | nom_feminin = models.CharField(max_length=255) | |
165 | description = models.CharField(max_length=255) | |
166 | is_responsable = models.BooleanField() | |
167 | famille_emploi = models.ForeignKey('FamilleEmploi', db_column='famille_emploi') | |
168 | #Méta | |
169 | date_modification = models.DateField(auto_now=True) | |
170 | actif = models.BooleanField() | |
171 | ||
5d680e84 NC |
172 | def __unicode__(self): |
173 | return u'%s' % self.nom | |
6d704629 | 174 | |
175 | class Meta: | |
176 | ordering = ['nom'] | |
5d680e84 NC |
177 | |
178 | ||
a3121a38 AJ |
179 | TYPE_PAIEMENT_CHOICES = ( |
180 | ('Régulier', 'Régulier'), | |
181 | ('Ponctuel', 'Ponctuel'), | |
182 | ) | |
183 | ||
184 | NATURE_REMUNERATION_CHOICES = ( | |
185 | ('Accessoire', 'Accessoire'), | |
186 | ('Charges', 'Charges'), | |
187 | ('Indemnité', 'Indemnité'), | |
188 | ('RAS', 'RAS'), | |
189 | ('Traitement', 'Traitement'), | |
190 | ) | |
191 | ||
192 | class TypeRemuneration(models.Model): | |
193 | #Identification | |
194 | id = models.IntegerField(primary_key=True) | |
195 | nom = models.CharField(max_length=255) | |
196 | type_paiement = models.CharField(max_length=30, choices=TYPE_PAIEMENT_CHOICES) | |
197 | nature_remuneration = models.CharField(max_length=30, choices=NATURE_REMUNERATION_CHOICES) | |
198 | #Méta | |
199 | actif = models.BooleanField() | |
200 | ||
201 | class TypeRevalorisation(models.Model): | |
202 | #Identification | |
203 | id = models.IntegerField(primary_key=True) | |
204 | nom = models.CharField(max_length=255) | |
205 | #Méta | |
206 | actif = models.BooleanField() | |
207 | ||
208 | PROPORTION_CHOICES = ( | |
209 | ('0.5', '0.5'), | |
210 | ('1', '1'), | |
211 | ) | |
212 | ||
1c7d67ce OL |
213 | class PosteManager(models.Manager): |
214 | """ | |
215 | Chargement de tous les objets FK existants sur chaque QuerySet. | |
216 | """ | |
217 | def get_query_set(self): | |
218 | fkeys = ( | |
219 | 'implantation', | |
220 | 'type_poste', | |
221 | ) | |
222 | return super(PosteManager, self).get_query_set().select_related(*fkeys).all() | |
223 | ||
a3121a38 AJ |
224 | class Poste(models.Model): |
225 | #Identification | |
226 | id = models.IntegerField(primary_key=True) | |
5d680e84 NC |
227 | implantation = models.ForeignKey('datamaster_modeles.Implantation', |
228 | db_column='implantation', related_name='+') | |
a3121a38 AJ |
229 | type_poste = models.ForeignKey('TypePoste', db_column='type_poste') |
230 | proportion = models.CharField(max_length=10, choices=PROPORTION_CHOICES) | |
231 | #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%) | |
232 | #Méta | |
233 | date_modification = models.DateField(auto_now=True) | |
234 | actif = models.BooleanField() | |
235 | ||
1c7d67ce OL |
236 | # Managers |
237 | objects = PosteManager() | |
238 | ||
5d680e84 | 239 | def __unicode__(self): |
6d704629 | 240 | return u'%s - %s [%s]' % (self.implantation, self.type_poste.nom, self.id) |
5d680e84 NC |
241 | |
242 | ||
a3121a38 AJ |
243 | class Service(models.Model): |
244 | #Identification | |
245 | id = models.IntegerField(primary_key=True) | |
246 | nom = models.CharField(max_length=255) | |
247 | #Méta | |
248 | actif = models.BooleanField() | |
249 | ||
5d680e84 NC |
250 | def __unicode__(self): |
251 | return u'%s' % self.nom | |
6d704629 | 252 | |
253 | class Meta: | |
254 | ordering = ['nom'] | |
5d680e84 NC |
255 | |
256 | ||
a3121a38 AJ |
257 | TYPE_ORGANISME_CHOICES = ( |
258 | ('MAD', 'Mise à disposition'), | |
259 | ('DET', 'Détachement'), | |
260 | ) | |
261 | ||
262 | class OrganismeBstg(models.Model): | |
263 | #Identification | |
264 | id = models.IntegerField(primary_key=True) | |
265 | nom = models.CharField(max_length=255) | |
266 | type = models.CharField(max_length=10, choices=TYPE_ORGANISME_CHOICES) | |
267 | #Méta | |
268 | actif = models.BooleanField() | |
269 | ||
139686f2 NC |
270 | def __unicode__(self): |
271 | return u'%s (%s)' % (self.nom, self.type) | |
272 | ||
0f23302a | 273 | class Meta: |
274 | ordering = ['type', 'nom'] | |
275 | ||
139686f2 | 276 | |
a3121a38 AJ |
277 | CONTRAT_CATEGORIE_CHOICES= ( |
278 | ('A', 'A'), | |
279 | ('C', 'C'), | |
280 | ) | |
281 | class Statut(models.Model): | |
282 | #Identification | |
283 | id = models.IntegerField(primary_key=True) | |
284 | code = models.CharField(max_length=25, unique=True) | |
285 | nom = models.CharField(max_length=255) | |
286 | type_contrat_categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES) | |
287 | #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie | |
288 | #Méta | |
289 | actif = models.BooleanField() | |
290 | ||
139686f2 | 291 | def __unicode__(self): |
0f23302a | 292 | return u'%s : %s' % (self.code, self.nom) |
139686f2 | 293 | |
a3121a38 AJ |
294 | TYPE_CLASSEMENT_CHOICES = ( |
295 | ('S', 'S'), | |
296 | ('T', 'T'), | |
297 | ) | |
298 | class Classement(models.Model): | |
299 | #Identification | |
300 | id = models.IntegerField(primary_key=True) | |
301 | type = models.CharField(max_length=10, choices=TYPE_CLASSEMENT_CHOICES) | |
302 | echelon = models.IntegerField() | |
303 | degre = models.IntegerField() | |
304 | coefficient = models.FloatField() | |
305 | #Méta | |
306 | commentaire = models.TextField(null=True, blank=True) | |
307 | date_modification = models.DateField(auto_now=True) | |
308 | actif = models.BooleanField() | |
309 | ||
5d680e84 NC |
310 | def __unicode__(self): |
311 | return u'%s.%s.%s (%s)' % (self.type, self.echelon, self.degre, | |
312 | self.coefficient) | |
313 | ||
314 | ||
a3121a38 AJ |
315 | class ValeurPoint(models.Model): |
316 | #Identification | |
317 | id = models.IntegerField(primary_key=True) | |
318 | valeur = models.FloatField() | |
319 | implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation') | |
320 | #Méta | |
321 | annee = models.IntegerField() | |
0f23302a | 322 | |
323 | def get_devise_code(self): | |
324 | code = '' | |
325 | try: | |
326 | taux = TauxChange.objects.get(implantation=self.implantation, annee=self.annee) | |
327 | code = taux.devise.code | |
328 | except TauxChange.DoesNotExist: | |
329 | pass | |
330 | return code | |
a3121a38 | 331 | |
5d680e84 NC |
332 | def __unicode__(self): |
333 | return u'%s (%s-%s)' % (self.valeur, self.implantation_id, self.annee) | |
6d704629 | 334 | |
335 | class Meta: | |
336 | ordering = ['valeur'] | |
5d680e84 NC |
337 | |
338 | ||
a3121a38 AJ |
339 | class TauxChange(models.Model): |
340 | #Identification | |
341 | id = models.IntegerField(primary_key=True) | |
139686f2 | 342 | devise = models.ForeignKey('Devise', db_column='devise') |
a3121a38 AJ |
343 | annee = models.IntegerField() |
344 | taux = models.FloatField() | |
345 | #Relations | |
346 | implantation = models.ForeignKey('datamaster_modeles.Implantation', db_column='implantation') | |
347 | ||
5d680e84 | 348 | |
a3121a38 AJ |
349 | class Devise(models.Model): |
350 | id = models.IntegerField(primary_key=True) | |
351 | code = models.CharField(max_length=10, unique=True) | |
352 | nom = models.CharField(max_length=255) | |
353 | ||
5d680e84 NC |
354 | def __unicode__(self): |
355 | return u'%s - %s' % (self.code, self.nom) | |
356 | ||
357 | ||
a3121a38 AJ |
358 | class TypeContrat(models.Model): |
359 | #Identification | |
360 | id = models.IntegerField(primary_key=True) | |
361 | nom = models.CharField(max_length=255) | |
362 | nom_long = models.CharField(max_length=255) #description | |
363 | categorie = models.CharField(max_length=10, choices=CONTRAT_CATEGORIE_CHOICES) | |
364 | #Méta | |
365 | actif = models.BooleanField() | |
366 | ||
139686f2 | 367 | def __unicode__(self): |
0f23302a | 368 | return u'%s' % (self.nom) |