démarrage mise en form du formulaire
[auf_rh_dae.git] / project / dae / models.py
1 # -=- encoding: utf-8 -=-
2 from django.db import models
3
4 import datamaster_modeles.models as ref
5 import project.rh_v1.models as rh
6
7
8 STATUT_RESIDENCE_CHOICES = (
9 ('local', 'Local'),
10 ('expat', 'Expatrié'),
11 )
12
13 POSTE_APPEL_CHOICES = (
14 ('interne', 'Interne'),
15 ('externe', 'Externe'),
16 )
17
18 POSTE_STATUT_CHOICES = (
19 ('MAD', 'Mise à disposition'),
20 ('DET', 'Détachement'),
21 )
22
23
24
25 class PosteManager(models.Manager):
26 """
27 Chargement de tous les objets FK existants sur chaque QuerySet.
28 """
29 def get_query_set(self):
30 fkeys = (
31 'id_rh',
32 'responsable',
33 'implantation',
34 'type_poste',
35 'service',
36 'classement_min',
37 'classement_max',
38 'valeur_point_min',
39 'valeur_point_max',
40 )
41 return super(PosteManager, self).get_query_set().select_related(*fkeys).all()
42
43
44 class Poste(models.Model):
45 # Modèle existant
46 id_rh = models.ForeignKey(rh.Poste, null=True, related_name='+',
47 editable=False)
48 nom = models.CharField(verbose_name="Titre du poste", max_length=255)
49 implantation = models.ForeignKey(ref.Implantation)
50 type_poste = models.ForeignKey(rh.TypePoste, null=True, related_name='+')
51 service = models.ForeignKey(rh.Service, verbose_name=u"Direction/Service/Pôle support", related_name='+')
52 responsable = models.ForeignKey(rh.Poste, related_name='+')
53 regime_travail = models.DecimalField(max_digits=12, decimal_places=2,
54 default=100)
55 regime_travail_nb_heure_semaine = models.DecimalField(max_digits=12,
56 decimal_places=2,
57 default=40)
58
59 # Recrutement
60 statut_residence = models.CharField(max_length=10, default='MAD', verbose_name="Recrutement",
61 choices=STATUT_RESIDENCE_CHOICES)
62 # TODO null?
63 mise_a_disposition = models.BooleanField()
64 appel = models.CharField(max_length=10, default='interne', verbose_name="Appel à candidature",
65 choices=POSTE_APPEL_CHOICES)
66
67 # Rémunération
68 classement_min = models.ForeignKey(rh.Classement, related_name='+')
69 classement_max = models.ForeignKey(rh.Classement, related_name='+')
70 valeur_point_min = models.ForeignKey(rh.ValeurPoint, related_name='+')
71 valeur_point_max = models.ForeignKey(rh.ValeurPoint, related_name='+')
72 salaire_min = models.DecimalField(max_digits=12, decimal_places=2,
73 default=0)
74 salaire_max = models.DecimalField(max_digits=12, decimal_places=2,
75 default=0)
76 indemn_min = models.DecimalField(max_digits=12, decimal_places=2,
77 default=0)
78 indemn_max = models.DecimalField(max_digits=12, decimal_places=2,
79 default=0)
80 autre_min = models.DecimalField(max_digits=12, decimal_places=2,
81 default=0)
82 autre_max = models.DecimalField(max_digits=12, decimal_places=2,
83 default=0)
84
85 # Comparatifs de rémunération
86 devise_comparaison = models.ForeignKey(rh.Devise, related_name='+',
87 null=True, blank=True)
88 comp_locale_min = models.DecimalField(max_digits=12, decimal_places=2,
89 null=True, blank=True)
90 comp_locale_max = models.DecimalField(max_digits=12, decimal_places=2,
91 null=True, blank=True)
92 comp_universite_min = models.DecimalField(max_digits=12, decimal_places=2,
93 null=True, blank=True)
94 comp_universite_max = models.DecimalField(max_digits=12, decimal_places=2,
95 null=True, blank=True)
96 comp_fonctionpub_min = models.DecimalField(max_digits=12, decimal_places=2,
97 null=True, blank=True)
98 comp_fonctionpub_max = models.DecimalField(max_digits=12, decimal_places=2,
99 null=True, blank=True)
100 comp_ong_min = models.DecimalField(max_digits=12, decimal_places=2,
101 null=True, blank=True)
102 comp_ong_max = models.DecimalField(max_digits=12, decimal_places=2,
103 null=True, blank=True)
104 comp_autre_min = models.DecimalField(max_digits=12, decimal_places=2,
105 null=True, blank=True)
106 comp_autre_max = models.DecimalField(max_digits=12, decimal_places=2,
107 null=True, blank=True)
108
109 # Méta
110 date_creation = models.DateTimeField(auto_now_add=True)
111 date_modification = models.DateTimeField(auto_now=True)
112 date_debut = models.DateField(verbose_name="Date de début", help_text="format: aaaa-mm-jj")
113 date_fin = models.DateField(null=True, verbose_name="Date de fin", help_text="format: aaaa-mm-jj")
114 actif = models.BooleanField(default=True)
115
116 # Managers
117 objects = PosteManager()
118
119 def __unicode__(self):
120 return u'%s - %s (%s)' % (self.implantation, self.type_poste.nom,
121 self.nom)
122
123 def DISABLED_save(self, *args, **kwargs):
124 # calculate nb_mois = nb of months between date_debut and date_fin
125 from datetime import date
126 if not self.salaire_min:
127 self.salaire_min = self.classement_min * self.valeur_point_min
128 if not self.salaire_max:
129 self.salaire_max = self.classement_max * self.valeur_point_min
130 if not self.valeur_point_min:
131 self.valeur_point_min = \
132 rh.ValeurPoint.objects.filter(implantation=self.implantation)
133 if not self.valeur_point_max:
134 self.valeur_point_max = \
135 rh.ValeurPoint.objects.filter(implantation=self.implantation)
136 super(Subject, self).save(*args, **kwargs)
137
138
139 POSTE_FINANCEMENT_CHOICES = (
140 ('A', 'A - Frais de personnel'),
141 ('B', 'B - Projet(s)-Titre(s)'),
142 ('C', 'C - Autre')
143 )
144
145
146 class PosteFinancement(models.Model):
147 montant = models.DecimalField(max_digits=12, decimal_places=2)
148 poste = models.ForeignKey('Poste', related_name='financements')
149 type = models.CharField(max_length=1, choices=POSTE_FINANCEMENT_CHOICES)
150 pourcentage = models.DecimalField(max_digits=12, decimal_places=2)
151 commentaire = models.TextField()
152
153
154 GENRE_CHOICES = (
155 ('M', 'Homme'),
156 ('F', 'Femme'),
157 )
158
159
160 class Employe(models.Model):
161 id = models.IntegerField(primary_key=True)
162
163 # Modèle existant
164 id_rh = models.ForeignKey(rh.Employe, null=True, related_name='+')
165 nom = models.CharField(max_length=255)
166 prenom = models.CharField(max_length=255)
167 genre = models.CharField(max_length=1,
168 choices=GENRE_CHOICES,
169 null=True,
170 blank=True)
171
172
173 COMPTE_COMPTA_CHOICES = (
174 ('coda', 'coda'),
175 ('scs', 'scs'),
176 ('aucun', 'aucun'),
177 )
178
179
180 class Dossier(models.Model):
181 statut_anterieur = models.ForeignKey(rh.Statut, related_name='+')
182
183 # Modèle existant
184 poste = models.ForeignKey('Poste')
185 statut = models.ForeignKey(rh.Statut, related_name='+')
186 organisme_bstg = models.ForeignKey(rh.OrganismeBstg, related_name='+')
187
188 # Recrutement
189 remplacement = models.BooleanField()
190 mobilite_interne = models.BooleanField()
191 statut_residence = models.CharField(max_length=10,
192 choices=STATUT_RESIDENCE_CHOICES)
193
194 # Rémunération
195 classement = models.ForeignKey(rh.Classement,
196 verbose_name='Classement proposé',
197 related_name='+')
198 salaire = models.DecimalField(max_digits=12,
199 decimal_places=2,
200 verbose_name='Salaire de base',
201 null=True,
202 default=None)
203 devise = models.ForeignKey(rh.Devise, related_name='+')
204 regime_travail = models.DecimalField(max_digits=12, verbose_name="Régime de travail", decimal_places=2)
205 regime_travail_nb_heure_semaine = \
206 models.DecimalField(max_digits=12, verbose_name="Nbr heures par semaine", decimal_places=2)
207
208 # Contrat
209 type_contrat = models.ForeignKey(rh.TypeContrat, related_name='+')
210 contrat_date_debut = models.DateField()
211 contrat_date_fin = models.DateField()
212 contrat_nb_mois = models.IntegerField()
213
214 # Comptes
215 compte_compta = models.CharField(max_length=10,
216 choices=COMPTE_COMPTA_CHOICES)
217 compte_courriel = models.BooleanField()
218
219
220 class Remuneration(models.Model):
221 # Identification
222 id = models.IntegerField(primary_key=True)
223 dossier = models.ForeignKey('Dossier', db_column='dossier')
224 type = models.ForeignKey('TypeRemuneration', db_column='type')
225 # TODO: what's that?
226 # type_revalorisation = models.ForeignKey('TypeRevalorisation',
227 # db_column='type_revalorisation')
228 montant = models.DecimalField(max_digits=12, decimal_places=2)
229 devise = models.ForeignKey(rh.Devise,
230 to_field='code',
231 db_column='devise', related_name='+')
232 date_effective = models.DateField()
233 pourcentage = models.IntegerField()
234
235 # Méta
236 date_creation = models.DateField(auto_now_add=True)
237 user_creation = models.IntegerField()
238 desactivation = models.BooleanField()
239 date_desactivation = models.DateField()
240 user_desactivation = models.IntegerField()
241 annule = models.BooleanField()
242 date_annule = models.DateField()
243 user_annule = models.IntegerField()
244
245
246 class JustificationPoste(models.Model):
247 pass
248
249
250 class JustificationEmploye(models.Model):
251 pass
252
253
254 class DocumentPoste(models.Model):
255 pass
256
257
258 class DocumentEmploye(models.Model):
259 pass
260
261
262 class Validation(models.Model):
263 # user
264 date = models.DateField()
265
266 # avis = ? (CHOICES?)
267
268
269 class ValidationPoste(models.Model):
270 poste = models.ForeignKey('Poste')
271
272
273 class ValidationEmploye(models.Model):
274 employe = models.ForeignKey('Employe')
275
276
277 class TypeRemuneration(models.Model):
278 ordre = models.IntegerField()
279 groupe = models.ForeignKey('GroupeTypeRemuneration')
280
281
282 class GroupeTypeRemuneration(models.Model):
283 nom = models.CharField(max_length=255)
284 ordre = models.IntegerField()