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 class TypeRevalorisation(models
.Model
):
204 id = models
.IntegerField(primary_key
=True)
205 nom
= models
.CharField(max_length
=255)
207 actif
= models
.BooleanField()
209 PROPORTION_CHOICES
= (
214 class PosteManager(models
.Manager
):
216 Chargement de tous les objets FK existants sur chaque QuerySet.
218 def get_query_set(self
):
223 return super(PosteManager
, self
).get_query_set().select_related(*fkeys
).all()
225 class Poste(models
.Model
):
227 id = models
.IntegerField(primary_key
=True)
228 implantation
= models
.ForeignKey('datamaster_modeles.Implantation',
229 db_column
='implantation', related_name
='+')
230 type_poste
= models
.ForeignKey('TypePoste', db_column
='type_poste')
231 proportion
= models
.CharField(max_length
=10, choices
=PROPORTION_CHOICES
)
232 #(sert à quoi?) renommer "regime_travail" ou autre? convertir data en % (data * 100; ex: 1 = 100%)
234 date_modification
= models
.DateField(auto_now
=True)
235 actif
= models
.BooleanField()
238 objects
= PosteManager()
240 def __unicode__(self
):
241 return u
'%s - %s [%s]' % (self
.implantation
, self
.type_poste
.nom
, self
.id)
244 class Service(models
.Model
):
246 id = models
.IntegerField(primary_key
=True)
247 nom
= models
.CharField(max_length
=255)
249 actif
= models
.BooleanField()
251 def __unicode__(self
):
252 return u
'%s' % self
.nom
258 TYPE_ORGANISME_CHOICES
= (
259 ('MAD', 'Mise à disposition'),
260 ('DET', 'Détachement'),
263 class OrganismeBstg(models
.Model
):
265 id = models
.IntegerField(primary_key
=True)
266 nom
= models
.CharField(max_length
=255)
267 type = models
.CharField(max_length
=10, choices
=TYPE_ORGANISME_CHOICES
)
269 actif
= models
.BooleanField()
271 def __unicode__(self
):
272 return u
'%s (%s)' % (self
.nom
, self
.type)
275 ordering
= ['type', 'nom']
278 CONTRAT_CATEGORIE_CHOICES
= (
282 class Statut(models
.Model
):
284 id = models
.IntegerField(primary_key
=True)
285 code
= models
.CharField(max_length
=25, unique
=True)
286 nom
= models
.CharField(max_length
=255)
287 type_contrat_categorie
= models
.CharField(max_length
=10, choices
=CONTRAT_CATEGORIE_CHOICES
)
288 #CHOICES A, C (veut dire quoi?) voir TypeContrat.categorie
290 actif
= models
.BooleanField()
292 def __unicode__(self
):
293 return u
'%s : %s' % (self
.code
, self
.nom
)
295 TYPE_CLASSEMENT_CHOICES
= (
299 class Classement(models
.Model
):
301 id = models
.IntegerField(primary_key
=True)
302 type = models
.CharField(max_length
=10, choices
=TYPE_CLASSEMENT_CHOICES
)
303 echelon
= models
.IntegerField()
304 degre
= models
.IntegerField()
305 coefficient
= models
.FloatField()
307 commentaire
= models
.TextField(null
=True, blank
=True)
308 date_modification
= models
.DateField(auto_now
=True)
309 actif
= models
.BooleanField()
311 def __unicode__(self
):
312 return u
'%s.%s.%s (%s)' % (self
.type, self
.echelon
, self
.degre
,
315 class TauxChange(models
.Model
):
317 id = models
.IntegerField(primary_key
=True)
318 devise
= models
.ForeignKey('Devise', db_column
='devise')
319 annee
= models
.IntegerField()
320 taux
= models
.FloatField()
322 implantation
= models
.ForeignKey('datamaster_modeles.Implantation', db_column
='implantation')
324 class ValeurPointManager(models
.Manager
):
326 Manager qui travaille uniquement sur les valeurs du point de l'année en cours.
328 mois
= datetime
.datetime
.now().month
329 annee_courante
= datetime
.datetime
.now().year
331 # Pour le mois de janvier et décembre on mets les 2 années pour faire la transition
333 filtre_annee
= (annee_courante
-1, annee_courante
)
335 filtre_annee
= (annee_courante
, annee_courante
+1)
337 filtre_annee
= (annee_courante
,)
339 def get_query_set(self
):
340 return super(ValeurPointManager
, self
).get_query_set().select_related('implantation').filter(annee__in
=self
.filtre_annee
)
343 class ValeurPoint(models
.Model
):
345 id = models
.IntegerField(primary_key
=True)
346 valeur
= models
.FloatField()
347 implantation
= models
.ForeignKey('datamaster_modeles.Implantation', db_column
='implantation')
349 annee
= models
.IntegerField()
351 # Stockage de tous les taux de change pour optimiser la recherche de la devise associée
352 annee_courante
= datetime
.datetime
.now().year
353 tauxchange
= TauxChange
.objects
.select_related('devise').filter(annee
=annee_courante
)
355 def get_tauxchange_courant(self
):
357 Recherche le taux courant associé à la valeur d'un point.
358 Tous les taux de l'année courante sont chargés, pour optimiser un affichage en liste.
359 (On pourrait probablement améliorer le manager pour lui greffer le taux courant sous forme de JOIN)
361 for tauxchange
in self
.tauxchange
:
362 if tauxchange
.implantation_id
== self
.implantation_id
:
366 def __unicode__(self
):
367 return u
'%s (%s-%s) %s' % (self
.valeur
, self
.implantation_id
, self
.annee
, self
.get_tauxchange_courant().devise
.code
)
370 ordering
= ['valeur']
372 actuelles
= ValeurPointManager()
375 class Devise(models
.Model
):
376 id = models
.IntegerField(primary_key
=True)
377 code
= models
.CharField(max_length
=10, unique
=True)
378 nom
= models
.CharField(max_length
=255)
380 def __unicode__(self
):
381 return u
'%s - %s' % (self
.code
, self
.nom
)
384 class TypeContrat(models
.Model
):
386 id = models
.IntegerField(primary_key
=True)
387 nom
= models
.CharField(max_length
=255)
388 nom_long
= models
.CharField(max_length
=255) #description
389 categorie
= models
.CharField(max_length
=10, choices
=CONTRAT_CATEGORIE_CHOICES
)
391 actif
= models
.BooleanField()
393 def __unicode__(self
):
394 return u
'%s' % (self
.nom
)