1 # -=- encoding: utf-8 -=-
4 from django
.db
import models
5 from datamaster_modeles
.models
import Pays
, Implantation
17 class Employe(models
.Model
):
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', related_name
='nationalite', db_column
='nationalite')
23 date_naissance
= models
.DateField(null
=True, blank
=True)
25 genre
= models
.CharField(max_length
=1, choices
=GENRE_CHOICES
, null
=True, blank
=True)
26 situation_famille
= models
.CharField(max_length
=1, choices
=SITUATION_CHOICES
, null
=True, blank
=True)
27 date_entree
= models
.DateField(null
=True, blank
=True) #devrait pas être là
29 tel_domicile
= models
.CharField(max_length
=255, null
=True, blank
=True)
30 tel_cellulaire
= models
.CharField(max_length
=255, null
=True, blank
=True)
31 adresse
= models
.CharField(max_length
=255, null
=True, blank
=True)
32 no_rue
= models
.CharField(max_length
=255, null
=True, blank
=True)
33 ville
= models
.CharField(max_length
=255, null
=True, blank
=True)
34 province
= models
.CharField(max_length
=255, null
=True, blank
=True)
35 code_postal
= models
.CharField(max_length
=255, null
=True, blank
=True)
36 pays
= models
.ForeignKey('datamaster_modeles.Pays', to_field
='code', null
=True, blank
=True, related_name
='pays', db_column
='pays')
38 date_creation
= models
.DateField(auto_now_add
=True)
39 date_maj
= models
.DateField(auto_now
=True)
40 commentaire
= models
.TextField(null
=True, blank
=True)
42 def __unicode__(self
):
43 return u
'%s %s' % (self
.prenom
, self
.nom
)
46 TYPE_DOSSIER_CHOICES
= (
51 class DossierManager(models
.Manager
):
53 Chargement de tous les objets FK existants sur chaque QuerySet.
55 def get_query_set(self
):
70 return super(DossierManager
, self
).get_query_set().select_related(*fkeys
).all()
72 class Dossier(models
.Model
):
74 id = models
.IntegerField(primary_key
=True)
75 code
= models
.CharField(max_length
=10, unique
=True)
76 employe
= models
.ForeignKey('Employe', db_column
='employe')
78 poste1
= models
.ForeignKey('Poste', db_column
='poste1', related_name
='poste1')
79 implantation1
= models
.ForeignKey('datamaster_modeles.Implantation', db_column
='implantation1', related_name
='implantation1', blank
=True, null
=True)
80 complement1
= models
.TextField(null
=True, blank
=True)
81 responsable_implantation1
= models
.IntegerField()
82 poste2
= models
.ForeignKey('Poste', db_column
='poste2', related_name
='poste2', blank
=True, null
=True)
83 implantation2
= models
.ForeignKey('datamaster_modeles.Implantation', db_column
='implantation2', related_name
='implantation2', null
=True, blank
=True)
84 complement2
= models
.TextField(null
=True, blank
=True)
85 responsable_implantation2
= models
.IntegerField()
87 service
= models
.ForeignKey('Service', db_column
='service', blank
=True, null
=True)
88 responsable
= models
.ForeignKey('Employe', db_column
='responsable', related_name
='responsable', blank
=True, null
=True)
89 remplacement_de
= models
.ForeignKey('Employe', db_column
='remplacement_de', related_name
='remplacement_de', blank
=True, null
=True)
90 type = models
.CharField(max_length
=1, choices
=TYPE_DOSSIER_CHOICES
)
91 statut
= models
.ForeignKey('Statut', db_column
='statut', blank
=True, null
=True)
92 organisme_bstg
= models
.ForeignKey('OrganismeBstg', db_column
='organisme_bstg', blank
=True, null
=True)
94 classement
= models
.ForeignKey('Classement', db_column
='classement', blank
=True, null
=True)
95 regime_travail
= models
.IntegerField()
97 mandat_date_debut
= models
.DateField()
98 mandat_date_fin
= models
.DateField(null
=True, blank
=True)
100 contrat_date_debut
= models
.DateField()
101 contrat_date_fin
= models
.DateField()
102 type_contrat
= models
.ForeignKey('TypeContrat', db_column
='type_contrat', blank
=True, null
=True)
104 date_creation
= models
.DateField(auto_now_add
=True)
105 date_maj
= models
.DateField(auto_now
=True)
106 commentaire
= models
.TextField(null
=True, blank
=True)
109 objects
= DossierManager()
111 def __unicode__(self
):
112 return u
'%s : %s %s' % (self
.employe
, self
.poste1
, self
.complement1
)
114 LIEN_PARENTE_CHOICES
= (
115 ('Conjoint', 'Conjoint'),
116 ('Conjointe', 'Conjointe'),
121 class AyantDroit(models
.Model
):
123 id = models
.IntegerField(primary_key
=True)
124 nom
= models
.CharField(max_length
=255)
125 prenom
= models
.CharField(max_length
=255)
127 employe
= models
.ForeignKey('Employe', db_column
='employe', related_name
='employe')
128 lien_parente
= models
.CharField(max_length
=10, choices
=LIEN_PARENTE_CHOICES
, null
=True, blank
=True)
130 commentaire
= models
.TextField(null
=True, blank
=True)
131 actif
= models
.BooleanField()
134 class Remuneration(models
.Model
):
136 id = models
.IntegerField(primary_key
=True)
137 dossier
= models
.ForeignKey('Dossier', db_column
='dossier')
138 type = models
.ForeignKey('TypeRemuneration', db_column
='type')
139 type_revalorisation
= models
.ForeignKey('TypeRevalorisation', db_column
='type_revalorisation', null
=True, blank
=True)
140 montant
= models
.FloatField(null
=True, blank
=True)
141 devise
= models
.ForeignKey('Devise', to_field
='code', db_column
='devise', null
=True, blank
=True)
142 date_effective
= models
.DateField(null
=True, blank
=True)
143 pourcentage
= models
.IntegerField(null
=True, blank
=True)
145 date_creation
= models
.DateField(auto_now_add
=True)
146 user_creation
= models
.IntegerField(null
=True, blank
=True) #User ou employé
147 desactivation
= models
.NullBooleanField(null
=True, blank
=True) #
148 date_desactivation
= models
.DateField(null
=True, blank
=True)
149 user_desactivation
= models
.IntegerField(null
=True, blank
=True) #User ou employé
150 annulation
= models
.NullBooleanField(null
=True, blank
=True)
151 date_annulation
= models
.DateField(null
=True, blank
=True)
152 user_annulation
= models
.IntegerField(null
=True, blank
=True) #User ou employé
154 class FamilleEmploi(models
.Model
):
156 id = models
.IntegerField(primary_key
=True)
157 nom
= models
.CharField(max_length
=255)
159 actif
= models
.BooleanField()
161 class TypePoste(models
.Model
):
163 id = models
.IntegerField(primary_key
=True)
164 nom
= models
.CharField(max_length
=255)
165 nom_feminin
= models
.CharField(max_length
=255)
166 description
= models
.CharField(max_length
=255)
167 is_responsable
= models
.BooleanField()
168 famille_emploi
= models
.ForeignKey('FamilleEmploi', db_column
='famille_emploi')
170 date_modification
= models
.DateField(auto_now
=True)
171 actif
= models
.BooleanField()
173 def __unicode__(self
):
174 return u
'%s' % self
.nom
180 TYPE_PAIEMENT_CHOICES
= (
181 ('Régulier', 'Régulier'),
182 ('Ponctuel', 'Ponctuel'),
185 NATURE_REMUNERATION_CHOICES
= (
186 ('Accessoire', 'Accessoire'),
187 ('Charges', 'Charges'),
188 ('Indemnité', 'Indemnité'),
190 ('Traitement', 'Traitement'),
193 class TypeRemuneration(models
.Model
):
195 id = models
.IntegerField(primary_key
=True)
196 nom
= models
.CharField(max_length
=255)
197 type_paiement
= models
.CharField(max_length
=30, choices
=TYPE_PAIEMENT_CHOICES
)
198 nature_remuneration
= models
.CharField(max_length
=30, choices
=NATURE_REMUNERATION_CHOICES
)
200 actif
= models
.BooleanField()
202 def __unicode__(self
):
203 return u
'%s' % self
.nom
206 class TypeRevalorisation(models
.Model
):
208 id = models
.IntegerField(primary_key
=True)
209 nom
= models
.CharField(max_length
=255)
211 actif
= models
.BooleanField()
213 PROPORTION_CHOICES
= (
218 class PosteManager(models
.Manager
):
220 Chargement de tous les objets FK existants sur chaque QuerySet.
222 def get_query_set(self
):
227 return super(PosteManager
, self
).get_query_set().select_related(*fkeys
).all()
229 class Poste(models
.Model
):
231 id = models
.IntegerField(primary_key
=True)
232 implantation
= models
.ForeignKey('datamaster_modeles.Implantation',
233 db_column
='implantation', related_name
='+')
234 type_poste
= models
.ForeignKey('TypePoste', db_column
='type_poste')
235 proportion
= models
.CharField(max_length
=10, choices
=PROPORTION_CHOICES
)
236 #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%)
238 date_modification
= models
.DateField(auto_now
=True)
239 actif
= models
.BooleanField()
242 objects
= PosteManager()
244 def __unicode__(self
):
245 return u
'%s - %s [%s]' % (self
.implantation
, self
.type_poste
.nom
, self
.id)
248 class Service(models
.Model
):
250 id = models
.IntegerField(primary_key
=True)
251 nom
= models
.CharField(max_length
=255)
253 actif
= models
.BooleanField()
255 def __unicode__(self
):
256 return u
'%s' % self
.nom
262 TYPE_ORGANISME_CHOICES
= (
263 ('MAD', 'Mise à disposition'),
264 ('DET', 'Détachement'),
267 class OrganismeBstg(models
.Model
):
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
)
273 actif
= models
.BooleanField()
275 def __unicode__(self
):
276 return u
'%s (%s)' % (self
.nom
, self
.type)
279 ordering
= ['type', 'nom']
282 CONTRAT_CATEGORIE_CHOICES
= (
286 class Statut(models
.Model
):
288 id = models
.IntegerField(primary_key
=True)
289 code
= models
.CharField(max_length
=25, unique
=True)
290 nom
= models
.CharField(max_length
=255)
291 type_contrat_categorie
= models
.CharField(max_length
=10, choices
=CONTRAT_CATEGORIE_CHOICES
)
292 #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie
294 actif
= models
.BooleanField()
296 def __unicode__(self
):
297 return u
'%s : %s' % (self
.code
, self
.nom
)
299 TYPE_CLASSEMENT_CHOICES
= (
303 class Classement(models
.Model
):
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()
311 commentaire
= models
.TextField(null
=True, blank
=True)
312 date_modification
= models
.DateField(auto_now
=True)
313 actif
= models
.BooleanField()
315 def __unicode__(self
):
316 return u
'%s.%s.%s (%s)' % (self
.type, self
.echelon
, self
.degre
,
319 ordering
= ['type','echelon','degre','coefficient']
321 class TauxChange(models
.Model
):
323 id = models
.IntegerField(primary_key
=True)
324 devise
= models
.ForeignKey('Devise', db_column
='devise')
325 annee
= models
.IntegerField()
326 taux
= models
.FloatField()
328 implantation
= models
.ForeignKey('datamaster_modeles.Implantation', db_column
='implantation')
330 class ValeurPointManager(models
.Manager
):
332 Manager qui travaille uniquement sur les valeurs du point de l'année en cours.
334 mois
= datetime
.datetime
.now().month
335 annee_courante
= datetime
.datetime
.now().year
337 # Pour le mois de janvier et décembre on mets les 2 années pour faire la transition
339 filtre_annee
= (annee_courante
-1, annee_courante
)
341 filtre_annee
= (annee_courante
, annee_courante
+1)
343 filtre_annee
= (annee_courante
,)
345 def get_query_set(self
):
346 return super(ValeurPointManager
, self
).get_query_set().select_related('implantation').filter(annee__in
=self
.filtre_annee
)
349 class ValeurPoint(models
.Model
):
351 id = models
.IntegerField(primary_key
=True)
352 valeur
= models
.FloatField()
353 implantation
= models
.ForeignKey('datamaster_modeles.Implantation', db_column
='implantation')
355 annee
= models
.IntegerField()
357 # Stockage de tous les taux de change pour optimiser la recherche de la devise associée
358 annee_courante
= datetime
.datetime
.now().year
359 tauxchange
= TauxChange
.objects
.select_related('devise').filter(annee
=annee_courante
)
361 def get_tauxchange_courant(self
):
363 Recherche le taux courant associé à la valeur d'un point.
364 Tous les taux de l'année courante sont chargés, pour optimiser un affichage en liste.
365 (On pourrait probablement améliorer le manager pour lui greffer le taux courant sous forme de JOIN)
367 for tauxchange
in self
.tauxchange
:
368 if tauxchange
.implantation_id
== self
.implantation_id
:
372 def __unicode__(self
):
373 tx
= self
.get_tauxchange_courant()
375 devise_code
= tx
.devise
.code
378 return u
'%s %s (%s-%s)' % (self
.valeur
, devise_code
, self
.implantation_id
, self
.annee
)
381 ordering
= ['valeur']
383 objects
= models
.Manager()
384 actuelles
= ValeurPointManager()
387 class Devise(models
.Model
):
388 id = models
.IntegerField(primary_key
=True)
389 code
= models
.CharField(max_length
=10, unique
=True)
390 nom
= models
.CharField(max_length
=255)
392 def __unicode__(self
):
393 return u
'%s - %s' % (self
.code
, self
.nom
)
396 class TypeContrat(models
.Model
):
398 id = models
.IntegerField(primary_key
=True)
399 nom
= models
.CharField(max_length
=255)
400 nom_long
= models
.CharField(max_length
=255) #description
401 categorie
= models
.CharField(max_length
=10, choices
=CONTRAT_CATEGORIE_CHOICES
)
403 actif
= models
.BooleanField()
405 def __unicode__(self
):
406 return u
'%s' % (self
.nom
)