1 # -=- encoding: utf-8 -=-
4 from datetime
import date
5 from decimal
import Decimal
8 from auf
.django
.emploi
.models
import \
9 GENRE_CHOICES
, SITUATION_CHOICES
# devrait plutot être dans references
10 from auf
.django
.references
import models
as ref
11 from django
.contrib
.auth
.models
import User
12 from django
.core
.files
.storage
import FileSystemStorage
13 from django
.core
.exceptions
import MultipleObjectsReturned
14 from django
.db
import models
15 from django
.db
.models
import Q
16 from django
.db
.models
.signals
import post_save
, pre_save
17 from django
.conf
import settings
19 from project
.rh
.change_list
import \
20 RechercheTemporelle
, KEY_STATUT
, STATUT_ACTIF
, STATUT_INACTIF
, \
22 from project
import groups
23 from project
.rh
.managers
import (
27 DossierComparaisonManager
,
28 PosteComparaisonManager
,
35 TWOPLACES
= Decimal('0.01')
37 from project
.rh
.validators
import validate_date_passee
39 # import pour relocaliser le modèle selon la convention (models.py pour
41 from project
.rh
.historique
import ModificationTraite
44 HELP_TEXT_DATE
= "format: jj-mm-aaaa"
45 REGIME_TRAVAIL_DEFAULT
= Decimal('100.00')
46 REGIME_TRAVAIL_NB_HEURE_SEMAINE_DEFAULT
= Decimal('35.00')
47 REGIME_TRAVAIL_NB_HEURE_SEMAINE_HELP_TEXT
= \
48 "Saisir le nombre d'heure de travail à temps complet (100%), " \
49 "sans tenir compte du régime de travail"
52 storage_prive
= FileSystemStorage(settings
.PRIVE_MEDIA_ROOT
,
53 base_url
=settings
.PRIVE_MEDIA_URL
)
56 class RemunIntegrityException(Exception):
59 def poste_piece_dispatch(instance
, filename
):
60 path
= "%s/poste/%s/%s" % (
61 instance
._meta
.app_label
, instance
.poste_id
, filename
66 def dossier_piece_dispatch(instance
, filename
):
67 path
= "%s/dossier/%s/%s" % (
68 instance
._meta
.app_label
, instance
.dossier_id
, filename
73 def employe_piece_dispatch(instance
, filename
):
74 path
= "%s/employe/%s/%s" % (
75 instance
._meta
.app_label
, instance
.employe_id
, filename
80 def contrat_dispatch(instance
, filename
):
81 path
= "%s/contrat/%s/%s" % (
82 instance
._meta
.app_label
, instance
.dossier_id
, filename
87 class DateActiviteMixin(models
.Model
):
89 Mixin pour mettre à jour l'activité d'un modèle
93 date_creation
= models
.DateTimeField(auto_now_add
=True,
94 null
=True, blank
=True,
95 verbose_name
=u
"Date de création",)
96 date_modification
= models
.DateTimeField(auto_now
=True,
97 null
=True, blank
=True,
98 verbose_name
=u
"Date de modification",)
101 class Archivable(models
.Model
):
102 archive
= models
.BooleanField(u
'archivé', default
=False)
104 objects
= ArchivableManager()
105 avec_archives
= models
.Manager()
111 class DevisableMixin(object):
113 def get_annee_pour_taux_devise(self
):
114 return datetime
.datetime
.now().year
116 def taux_devise(self
, devise
=None):
122 if devise
.code
== "EUR":
125 annee
= self
.get_annee_pour_taux_devise()
126 taux
= TauxChange
.objects
.filter(devise
=devise
, annee__lte
=annee
) \
130 def montant_euros_float(self
):
132 taux
= self
.taux_devise()
137 return float(self
.montant
) * float(taux
)
139 def montant_euros(self
):
140 return int(round(self
.montant_euros_float(), 2))
143 class Commentaire(models
.Model
):
144 texte
= models
.TextField()
145 owner
= models
.ForeignKey(
146 'auth.User', db_column
='owner', related_name
='+',
147 verbose_name
=u
"Commentaire de"
149 date_creation
= models
.DateTimeField(
150 u
'date', auto_now_add
=True, blank
=True, null
=True
155 ordering
= ['-date_creation']
157 def __unicode__(self
):
158 return u
'%s' % (self
.texte
)
163 POSTE_APPEL_CHOICES
= (
164 ('interne', 'Interne'),
165 ('externe', 'Externe'),
169 class Poste_( DateActiviteMixin
, models
.Model
,):
171 Un Poste est un emploi (job) à combler dans une implantation.
172 Un Poste peut être comblé par un Employe, auquel cas un Dossier est créé.
173 Si on veut recruter 2 jardiniers, 2 Postes distincts existent.
176 objects
= PosteManager()
179 nom
= models
.CharField(u
"Titre du poste", max_length
=255)
180 nom_feminin
= models
.CharField(
181 u
"Titre du poste (au féminin)", max_length
=255, null
=True
183 implantation
= models
.ForeignKey(
185 help_text
=u
"Taper le nom de l'implantation ou sa région",
186 db_column
='implantation', related_name
='+'
188 type_poste
= models
.ForeignKey(
189 'TypePoste', db_column
='type_poste',
190 help_text
=u
"Taper le nom du type de poste", related_name
='+',
191 null
=True, verbose_name
=u
"type de poste"
193 service
= models
.ForeignKey(
194 'Service', db_column
='service', related_name
='%(app_label)s_postes',
195 verbose_name
=u
"direction/service/pôle support", null
=True
197 responsable
= models
.ForeignKey(
198 'Poste', db_column
='responsable',
199 related_name
='+', null
=True,
200 help_text
=u
"Taper le nom du poste ou du type de poste",
201 verbose_name
=u
"Poste du responsable"
205 regime_travail
= models
.DecimalField(
206 u
"temps de travail", max_digits
=12, decimal_places
=2,
207 default
=REGIME_TRAVAIL_DEFAULT
, null
=True,
208 help_text
="% du temps complet"
210 regime_travail_nb_heure_semaine
= models
.DecimalField(
211 u
"nb. heures par semaine", max_digits
=12, decimal_places
=2,
212 null
=True, default
=REGIME_TRAVAIL_NB_HEURE_SEMAINE_DEFAULT
,
213 help_text
=REGIME_TRAVAIL_NB_HEURE_SEMAINE_HELP_TEXT
217 local
= models
.NullBooleanField(
218 u
"local", default
=True, null
=True, blank
=True
220 expatrie
= models
.NullBooleanField(
221 u
"expatrié", default
=False, null
=True, blank
=True
223 mise_a_disposition
= models
.NullBooleanField(
224 u
"mise à disposition", null
=True, default
=False
226 appel
= models
.CharField(
227 u
"Appel à candidature", max_length
=10, null
=True,
228 choices
=POSTE_APPEL_CHOICES
, default
='interne'
232 classement_min
= models
.ForeignKey(
233 'Classement', db_column
='classement_min', related_name
='+',
234 null
=True, blank
=True
236 classement_max
= models
.ForeignKey(
237 'Classement', db_column
='classement_max', related_name
='+',
238 null
=True, blank
=True
240 valeur_point_min
= models
.ForeignKey(
242 help_text
=u
"Taper le code ou le nom de l'implantation",
243 db_column
='valeur_point_min', related_name
='+', null
=True,
246 valeur_point_max
= models
.ForeignKey(
248 help_text
=u
"Taper le code ou le nom de l'implantation",
249 db_column
='valeur_point_max', related_name
='+', null
=True,
252 devise_min
= models
.ForeignKey(
253 'Devise', db_column
='devise_min', null
=True, related_name
='+'
255 devise_max
= models
.ForeignKey(
256 'Devise', db_column
='devise_max', null
=True, related_name
='+'
258 salaire_min
= models
.DecimalField(
259 max_digits
=12, decimal_places
=2, default
=0,
261 salaire_max
= models
.DecimalField(
262 max_digits
=12, decimal_places
=2, default
=0,
264 indemn_min
= models
.DecimalField(
265 max_digits
=12, decimal_places
=2, default
=0,
267 indemn_max
= models
.DecimalField(
268 max_digits
=12, decimal_places
=2, default
=0,
270 autre_min
= models
.DecimalField(
271 max_digits
=12, decimal_places
=2, default
=0,
273 autre_max
= models
.DecimalField(
274 max_digits
=12, decimal_places
=2, default
=0,
277 # Comparatifs de rémunération
278 devise_comparaison
= models
.ForeignKey(
279 'Devise', null
=True, blank
=True, db_column
='devise_comparaison',
282 comp_locale_min
= models
.DecimalField(
283 max_digits
=12, decimal_places
=2, null
=True, blank
=True
285 comp_locale_max
= models
.DecimalField(
286 max_digits
=12, decimal_places
=2, null
=True, blank
=True
288 comp_universite_min
= models
.DecimalField(
289 max_digits
=12, decimal_places
=2, null
=True, blank
=True
291 comp_universite_max
= models
.DecimalField(
292 max_digits
=12, decimal_places
=2, null
=True, blank
=True
294 comp_fonctionpub_min
= models
.DecimalField(
295 max_digits
=12, decimal_places
=2, null
=True, blank
=True
297 comp_fonctionpub_max
= models
.DecimalField(
298 max_digits
=12, decimal_places
=2, null
=True, blank
=True
300 comp_ong_min
= models
.DecimalField(
301 max_digits
=12, decimal_places
=2, null
=True, blank
=True
303 comp_ong_max
= models
.DecimalField(
304 max_digits
=12, decimal_places
=2, null
=True, blank
=True
306 comp_autre_min
= models
.DecimalField(
307 max_digits
=12, decimal_places
=2, null
=True, blank
=True
309 comp_autre_max
= models
.DecimalField(
310 max_digits
=12, decimal_places
=2, null
=True, blank
=True
314 justification
= models
.TextField(null
=True, blank
=True)
317 date_debut
= models
.DateField(
318 u
"date de début", help_text
=HELP_TEXT_DATE
, null
=True, blank
=True,
321 date_fin
= models
.DateField(
322 u
"date de fin", help_text
=HELP_TEXT_DATE
, null
=True, blank
=True,
328 ordering
= ['implantation__nom', 'nom']
329 verbose_name
= u
"Poste"
330 verbose_name_plural
= u
"Postes"
333 def __unicode__(self
):
334 representation
= u
'%s - %s [%s]' % (
335 self
.implantation
, self
.nom
, self
.id
337 return representation
339 prefix_implantation
= "implantation__zone_administrative"
341 def get_zones_administratives(self
):
342 return [self
.implantation
.zone_administrative
]
344 def get_devise(self
):
345 vp
= ValeurPoint
.objects
.filter(
346 implantation
=self
.implantation
, devise__archive
=False
351 return Devise
.objects
.get(code
='EUR')
355 __doc__
= Poste_
.__doc__
357 # meta dématérialisation : pour permettre le filtrage
358 vacant
= models
.NullBooleanField(u
"vacant", null
=True, blank
=True)
362 if self
.occupe_par():
366 def occupe_par(self
):
368 Retourne la liste d'employé occupant ce poste.
369 Généralement, retourne une liste d'un élément.
370 Si poste inoccupé, retourne liste vide.
371 UTILISE pour mettre a jour le flag vacant
375 for d
in self
.rh_dossiers
.exclude(date_fin__lt
=date
.today())
378 reversion
.register(Poste
, format
='xml', follow
=[
379 'rh_financements', 'rh_pieces', 'rh_comparaisons_internes',
384 POSTE_FINANCEMENT_CHOICES
= (
385 ('A', 'A - Frais de personnel'),
386 ('B', 'B - Projet(s)-Titre(s)'),
391 class PosteFinancement_(models
.Model
):
393 Pour un Poste, structure d'informations décrivant comment on prévoit
396 type = models
.CharField(max_length
=1, choices
=POSTE_FINANCEMENT_CHOICES
)
397 pourcentage
= models
.DecimalField(
398 max_digits
=12, decimal_places
=2,
399 help_text
="ex.: 33.33 % (décimale avec point)"
401 commentaire
= models
.TextField(
402 help_text
="Spécifiez la source de financement."
409 def __unicode__(self
):
410 return u
'%s : %s %%' % (self
.type, self
.pourcentage
)
413 return u
"%s" % dict(POSTE_FINANCEMENT_CHOICES
)[self
.type]
416 class PosteFinancement(PosteFinancement_
):
417 poste
= models
.ForeignKey(
418 Poste
, db_column
='poste', related_name
='rh_financements'
421 reversion
.register(PosteFinancement
, format
='xml')
424 class PostePiece_(models
.Model
):
426 Documents relatifs au Poste.
427 Ex.: Description de poste
429 nom
= models
.CharField(u
"Nom", max_length
=255)
430 fichier
= models
.FileField(
431 u
"Fichier", upload_to
=poste_piece_dispatch
, storage
=storage_prive
,
439 def __unicode__(self
):
440 return u
'%s' % (self
.nom
)
443 class PostePiece(PostePiece_
):
444 poste
= models
.ForeignKey(
445 Poste
, db_column
='poste', related_name
='rh_pieces'
448 reversion
.register(PostePiece
, format
='xml')
451 class PosteComparaison_(models
.Model
, DevisableMixin
):
453 De la même manière qu'un dossier, un poste peut-être comparé à un autre
456 objects
= PosteComparaisonManager()
458 implantation
= models
.ForeignKey(
459 ref
.Implantation
, null
=True, blank
=True, related_name
="+"
461 nom
= models
.CharField(u
"Poste", max_length
=255, null
=True, blank
=True)
462 montant
= models
.IntegerField(null
=True)
463 devise
= models
.ForeignKey(
464 "Devise", related_name
='+', null
=True, blank
=True
470 def __unicode__(self
):
474 class PosteComparaison(PosteComparaison_
):
475 poste
= models
.ForeignKey(
476 Poste
, related_name
='rh_comparaisons_internes'
479 reversion
.register(PosteComparaison
, format
='xml')
482 class PosteCommentaire(Commentaire
):
483 poste
= models
.ForeignKey(
484 Poste
, db_column
='poste', related_name
='commentaires'
487 reversion
.register(PosteCommentaire
, format
='xml')
491 class Employe(models
.Model
):
493 Personne occupant ou ayant occupé un Poste. Un Employe aura autant de
494 Dossiers qu'il occupe ou a occupé de Postes.
496 Cette classe aurait pu avantageusement s'appeler Personne car la notion
497 d'employé n'a pas de sens si aucun Dossier n'existe pour une personne.
500 objects
= EmployeManager()
503 nom
= models
.CharField(max_length
=255)
504 prenom
= models
.CharField(u
"prénom", max_length
=255)
505 nom_affichage
= models
.CharField(
506 u
"nom d'affichage", max_length
=255, null
=True, blank
=True
508 nationalite
= models
.ForeignKey(
509 ref
.Pays
, to_field
='code', db_column
='nationalite',
510 related_name
='employes_nationalite', verbose_name
=u
"nationalité",
511 blank
=True, null
=True
513 date_naissance
= models
.DateField(
514 u
"date de naissance", help_text
=HELP_TEXT_DATE
,
515 validators
=[validate_date_passee
], null
=True, blank
=True
517 genre
= models
.CharField(max_length
=1, choices
=GENRE_CHOICES
)
520 situation_famille
= models
.CharField(
521 u
"situation familiale", max_length
=1, choices
=SITUATION_CHOICES
,
522 null
=True, blank
=True
524 date_entree
= models
.DateField(
525 u
"date d'entrée à l'AUF", help_text
=HELP_TEXT_DATE
, null
=True,
530 tel_domicile
= models
.CharField(
531 u
"tél. domicile", max_length
=255, null
=True, blank
=True
533 tel_cellulaire
= models
.CharField(
534 u
"tél. cellulaire", max_length
=255, null
=True, blank
=True
536 adresse
= models
.CharField(max_length
=255, null
=True, blank
=True)
537 ville
= models
.CharField(max_length
=255, null
=True, blank
=True)
538 province
= models
.CharField(max_length
=255, null
=True, blank
=True)
539 code_postal
= models
.CharField(max_length
=255, null
=True, blank
=True)
540 pays
= models
.ForeignKey(
541 ref
.Pays
, to_field
='code', db_column
='pays',
542 related_name
='employes', null
=True, blank
=True
544 courriel_perso
= models
.EmailField(
545 u
'adresse courriel personnelle', blank
=True
548 # meta dématérialisation : pour permettre le filtrage
549 nb_postes
= models
.IntegerField(u
"nombre de postes", null
=True, blank
=True)
552 ordering
= ['nom', 'prenom']
553 verbose_name
= u
"Employé"
554 verbose_name_plural
= u
"Employés"
556 def __unicode__(self
):
557 return u
'%s %s [%s]' % (self
.nom
.upper(), self
.prenom
, self
.id)
559 def get_latest_dossier_ordered_by_date_fin_and_principal(self
):
560 res
= self
.rh_dossiers
.order_by(
561 '-principal', 'date_fin')
563 # Retourne en le premier du queryset si la date de fin est None
564 # Sinon, retourne le plus récent selon la date de fin.
569 if first
.date_fin
== None:
572 return res
.order_by('-principal', '-date_fin')[0]
576 if self
.genre
.upper() == u
'M':
578 elif self
.genre
.upper() == u
'F':
584 Retourne l'URL du service retournant la photo de l'Employe.
585 Équivalent reverse url 'rh_photo' avec id en param.
587 from django
.core
.urlresolvers
import reverse
588 return reverse('rh_photo', kwargs
={'id': self
.id})
590 def dossiers_passes(self
):
591 params
= {KEY_STATUT
: STATUT_INACTIF
, }
592 search
= RechercheTemporelle(params
, Dossier
)
593 search
.purge_params(params
)
594 q
= search
.get_q_temporel(self
.rh_dossiers
)
595 return self
.rh_dossiers
.filter(q
)
597 def dossiers_futurs(self
):
598 params
= {KEY_STATUT
: STATUT_FUTUR
, }
599 search
= RechercheTemporelle(params
, Dossier
)
600 search
.purge_params(params
)
601 q
= search
.get_q_temporel(self
.rh_dossiers
)
602 return self
.rh_dossiers
.filter(q
)
604 def dossiers_encours(self
):
605 params
= {KEY_STATUT
: STATUT_ACTIF
, }
606 search
= RechercheTemporelle(params
, Dossier
)
607 search
.purge_params(params
)
608 q
= search
.get_q_temporel(self
.rh_dossiers
)
609 return self
.rh_dossiers
.filter(q
)
611 def dossier_principal_pour_annee(self
):
612 return self
.dossier_principal(pour_annee
=True)
614 def dossier_principal(self
, pour_annee
=False):
616 Retourne le dossier principal (ou le plus ancien si il y en a
619 Si pour_annee == True, retourne le ou les dossiers principaux
620 pour l'annee en cours, sinon, le ou les dossiers principaux
621 pour la journee en cours.
623 TODO: (Refactoring possible): Utiliser meme logique dans
624 dae/templatetags/dae.py
630 year_start
= date(year
, 1, 1)
631 year_end
= date(year
, 12, 31)
634 dossier
= self
.rh_dossiers
.filter(
635 (Q(date_debut__lte
=year_end
, date_fin__isnull
=True) |
636 Q(date_debut__isnull
=True, date_fin__gte
=year_start
) |
637 Q(date_debut__lte
=year_end
, date_fin__gte
=year_start
) |
638 Q(date_debut__isnull
=True, date_fin__isnull
=True)) &
639 Q(principal
=True)).order_by('date_debut')[0]
640 except IndexError, Dossier
.DoesNotExist
:
645 dossier
= self
.rh_dossiers
.filter(
646 (Q(date_debut__lte
=today
, date_fin__isnull
=True) |
647 Q(date_debut__isnull
=True, date_fin__gte
=today
) |
648 Q(date_debut__lte
=today
, date_fin__gte
=today
) |
649 Q(date_debut__isnull
=True, date_fin__isnull
=True)) &
650 Q(principal
=True)).order_by('date_debut')[0]
651 except IndexError, Dossier
.DoesNotExist
:
656 def postes_encours(self
):
657 postes_encours
= set()
658 for d
in self
.dossiers_encours():
659 postes_encours
.add(d
.poste
)
660 return postes_encours
662 def poste_principal(self
):
664 Retourne le Poste du premier Dossier créé parmi les Dossiers en cours.
666 si on ajout d'autre Dossiers, c'est pour des Postes secondaires.
668 # DEPRECATED : on a maintenant Dossier.principal
669 poste
= Poste
.objects
.none()
671 poste
= self
.dossiers_encours().order_by('date_debut')[0].poste
676 prefix_implantation
= \
677 "rh_dossiers__poste__implantation__zone_administrative"
679 def get_zones_administratives(self
):
681 d
.poste
.implantation
.zone_administrative
682 for d
in self
.dossiers
.all()
685 reversion
.register(Employe
, format
='xml', follow
=[
686 'pieces', 'commentaires', 'ayantdroits'
690 class EmployePiece(models
.Model
):
692 Documents relatifs à un employé.
695 employe
= models
.ForeignKey(
696 'Employe', db_column
='employe', related_name
="pieces",
697 verbose_name
=u
"employé"
699 nom
= models
.CharField(max_length
=255)
700 fichier
= models
.FileField(
701 u
"fichier", upload_to
=employe_piece_dispatch
, storage
=storage_prive
,
707 verbose_name
= u
"Employé pièce"
708 verbose_name_plural
= u
"Employé pièces"
710 def __unicode__(self
):
711 return u
'%s' % (self
.nom
)
713 reversion
.register(EmployePiece
, format
='xml')
716 class EmployeCommentaire(Commentaire
):
717 employe
= models
.ForeignKey(
718 'Employe', db_column
='employe', related_name
='commentaires'
722 verbose_name
= u
"Employé commentaire"
723 verbose_name_plural
= u
"Employé commentaires"
725 reversion
.register(EmployeCommentaire
, format
='xml')
728 LIEN_PARENTE_CHOICES
= (
729 ('Conjoint', 'Conjoint'),
730 ('Conjointe', 'Conjointe'),
736 class AyantDroit(models
.Model
):
738 Personne en relation avec un Employe.
741 nom
= models
.CharField(max_length
=255)
742 prenom
= models
.CharField(u
"prénom", max_length
=255)
743 nom_affichage
= models
.CharField(
744 u
"nom d'affichage", max_length
=255, null
=True, blank
=True
746 nationalite
= models
.ForeignKey(
747 ref
.Pays
, to_field
='code', db_column
='nationalite',
748 related_name
='ayantdroits_nationalite',
749 verbose_name
=u
"nationalité", null
=True, blank
=True
751 date_naissance
= models
.DateField(
752 u
"Date de naissance", help_text
=HELP_TEXT_DATE
,
753 validators
=[validate_date_passee
], null
=True, blank
=True
755 genre
= models
.CharField(max_length
=1, choices
=GENRE_CHOICES
)
758 employe
= models
.ForeignKey(
759 'Employe', db_column
='employe', related_name
='ayantdroits',
760 verbose_name
=u
"Employé"
762 lien_parente
= models
.CharField(
763 u
"lien de parenté", max_length
=10, choices
=LIEN_PARENTE_CHOICES
,
764 null
=True, blank
=True
769 verbose_name
= u
"Ayant droit"
770 verbose_name_plural
= u
"Ayants droit"
772 def __unicode__(self
):
773 return u
'%s %s' % (self
.nom
.upper(), self
.prenom
, )
775 prefix_implantation
= \
776 "employe__dossiers__poste__implantation__zone_administrative"
778 def get_zones_administratives(self
):
780 d
.poste
.implantation
.zone_administrative
781 for d
in self
.employe
.dossiers
.all()
784 reversion
.register(AyantDroit
, format
='xml', follow
=['commentaires'])
787 class AyantDroitCommentaire(Commentaire
):
788 ayant_droit
= models
.ForeignKey(
789 'AyantDroit', db_column
='ayant_droit', related_name
='commentaires'
792 reversion
.register(AyantDroitCommentaire
, format
='xml')
797 STATUT_RESIDENCE_CHOICES
= (
799 ('expat', 'Expatrié'),
802 COMPTE_COMPTA_CHOICES
= (
809 class Dossier_(DateActiviteMixin
, models
.Model
, DevisableMixin
,):
811 Le Dossier regroupe les informations relatives à l'occupation
812 d'un Poste par un Employe. Un seul Dossier existe par Poste occupé
815 Plusieurs Contrats peuvent être associés au Dossier.
816 Une structure de Remuneration est rattachée au Dossier. Un Poste pour
817 lequel aucun Dossier n'existe est un poste vacant.
820 objects
= DossierManager()
823 statut
= models
.ForeignKey('Statut', related_name
='+', null
=True)
824 organisme_bstg
= models
.ForeignKey(
825 'OrganismeBstg', db_column
='organisme_bstg', related_name
='+',
826 verbose_name
=u
"organisme",
828 u
"Si détaché (DET) ou mis à disposition (MAD), "
829 u
"préciser l'organisme."
830 ), null
=True, blank
=True
834 remplacement
= models
.BooleanField(default
=False)
835 remplacement_de
= models
.ForeignKey(
836 'self', related_name
='+', help_text
=u
"Taper le nom de l'employé",
837 null
=True, blank
=True
839 statut_residence
= models
.CharField(
840 u
"statut", max_length
=10, default
='local', null
=True,
841 choices
=STATUT_RESIDENCE_CHOICES
845 classement
= models
.ForeignKey(
846 'Classement', db_column
='classement', related_name
='+', null
=True,
849 regime_travail
= models
.DecimalField(
850 u
"régime de travail", max_digits
=12, null
=True, decimal_places
=2,
851 default
=REGIME_TRAVAIL_DEFAULT
, help_text
="% du temps complet"
853 regime_travail_nb_heure_semaine
= models
.DecimalField(
854 u
"nb. heures par semaine", max_digits
=12,
855 decimal_places
=2, null
=True,
856 default
=REGIME_TRAVAIL_NB_HEURE_SEMAINE_DEFAULT
,
857 help_text
=REGIME_TRAVAIL_NB_HEURE_SEMAINE_HELP_TEXT
860 # Occupation du Poste par cet Employe (anciennement "mandat")
861 date_debut
= models
.DateField(
862 u
"date de début d'occupation de poste", db_index
=True
864 date_fin
= models
.DateField(
865 u
"Date de fin d'occupation de poste", null
=True, blank
=True,
870 est_cadre
= models
.BooleanField(
876 compte_compta
= models
.CharField(max_length
=10, default
='aucun',
877 verbose_name
=u
'Compte comptabilité',
878 choices
=COMPTE_COMPTA_CHOICES
)
879 compte_courriel
= models
.BooleanField()
883 ordering
= ['employe__nom', ]
884 verbose_name
= u
"Dossier"
885 verbose_name_plural
= "Dossiers"
887 def salaire_theorique(self
):
888 annee
= date
.today().year
889 coeff
= self
.classement
.coefficient
890 implantation
= self
.poste
.implantation
891 point
= ValeurPoint
.objects
.get(implantation
=implantation
, annee
=annee
)
893 montant
= coeff
* point
.valeur
894 devise
= point
.devise
895 return {'montant': montant
, 'devise': devise
}
897 def __unicode__(self
):
898 poste
= self
.poste
.nom
899 if self
.employe
.genre
== 'F':
900 poste
= self
.poste
.nom_feminin
901 return u
'%s - %s' % (self
.employe
, poste
)
903 prefix_implantation
= "poste__implantation__zone_administrative"
905 def get_zones_administratives(self
):
906 return [self
.poste
.implantation
.zone_administrative
]
908 def remunerations(self
):
909 key
= "%s_remunerations" % self
._meta
.app_label
910 remunerations
= getattr(self
, key
)
911 return remunerations
.all().order_by('-date_debut')
913 def remunerations_en_cours(self
):
914 q
= Q(date_fin__exact
=None) |
Q(date_fin__gt
=datetime
.date
.today())
915 return self
.remunerations().all().filter(q
).order_by('date_debut')
917 def get_salaire(self
):
919 return [r
for r
in self
.remunerations().order_by('-date_debut')
920 if r
.type_id
== 1][0]
924 def get_salaire_euros(self
):
925 tx
= self
.taux_devise()
926 return (float)(tx
) * (float)(self
.salaire
)
928 def get_remunerations_brutes(self
):
932 4 Indemnité d'expatriation
933 5 Indemnité pour frais
934 6 Indemnité de logement
935 7 Indemnité de fonction
936 8 Indemnité de responsabilité
937 9 Indemnité de transport
938 10 Indemnité compensatrice
939 11 Indemnité de subsistance
940 12 Indemnité différentielle
941 13 Prime d'installation
944 16 Indemnité de départ
945 18 Prime de 13ième mois
948 ids
= [1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19]
949 return [r
for r
in self
.remunerations_en_cours().all()
952 def get_charges_salariales(self
):
954 20 Charges salariales ?
957 return [r
for r
in self
.remunerations_en_cours().all()
960 def get_charges_patronales(self
):
962 17 Charges patronales
965 return [r
for r
in self
.remunerations_en_cours().all()
968 def get_remunerations_tierces(self
):
972 return [r
for r
in self
.remunerations_en_cours().all()
973 if r
.type_id
in (2,)]
977 def get_total_local_charges_salariales(self
):
978 devise
= self
.poste
.get_devise()
980 for r
in self
.get_charges_salariales():
981 if r
.devise
!= devise
:
983 total
+= float(r
.montant
)
986 def get_total_local_charges_patronales(self
):
987 devise
= self
.poste
.get_devise()
989 for r
in self
.get_charges_patronales():
990 if r
.devise
!= devise
:
992 total
+= float(r
.montant
)
995 def get_local_salaire_brut(self
):
997 somme des rémuérations brutes
999 devise
= self
.poste
.get_devise()
1001 for r
in self
.get_remunerations_brutes():
1002 if r
.devise
!= devise
:
1004 total
+= float(r
.montant
)
1007 def get_local_salaire_net(self
):
1009 salaire brut - charges salariales
1011 devise
= self
.poste
.get_devise()
1013 for r
in self
.get_charges_salariales():
1014 if r
.devise
!= devise
:
1016 total_charges
+= float(r
.montant
)
1017 return self
.get_local_salaire_brut() - total_charges
1019 def get_local_couts_auf(self
):
1021 salaire net + charges patronales
1023 devise
= self
.poste
.get_devise()
1025 for r
in self
.get_charges_patronales():
1026 if r
.devise
!= devise
:
1028 total_charges
+= float(r
.montant
)
1029 return self
.get_local_salaire_net() + total_charges
1031 def get_total_local_remunerations_tierces(self
):
1032 devise
= self
.poste
.get_devise()
1034 for r
in self
.get_remunerations_tierces():
1035 if r
.devise
!= devise
:
1037 total
+= float(r
.montant
)
1042 def get_total_charges_salariales(self
):
1044 for r
in self
.get_charges_salariales():
1045 total
+= r
.montant_euros()
1048 def get_total_charges_patronales(self
):
1050 for r
in self
.get_charges_patronales():
1051 total
+= r
.montant_euros()
1054 def get_salaire_brut(self
):
1056 somme des rémuérations brutes
1059 for r
in self
.get_remunerations_brutes():
1060 total
+= r
.montant_euros()
1063 def get_salaire_net(self
):
1065 salaire brut - charges salariales
1068 for r
in self
.get_charges_salariales():
1069 total_charges
+= r
.montant_euros()
1070 return self
.get_salaire_brut() - total_charges
1072 def get_couts_auf(self
):
1074 salaire net + charges patronales
1077 for r
in self
.get_charges_patronales():
1078 total_charges
+= r
.montant_euros()
1079 return self
.get_salaire_net() + total_charges
1081 def get_total_remunerations_tierces(self
):
1083 for r
in self
.get_remunerations_tierces():
1084 total
+= r
.montant_euros()
1087 def premier_contrat(self
):
1088 """contrat avec plus petite date de début"""
1090 contrat
= self
.rh_contrats
.exclude(date_debut
=None) \
1091 .order_by('date_debut')[0]
1092 except IndexError, Contrat
.DoesNotExist
:
1096 def dernier_contrat(self
):
1097 """contrat avec plus grande date de fin"""
1099 contrat
= self
.rh_contrats
.exclude(date_debut
=None) \
1100 .order_by('-date_debut')[0]
1101 except IndexError, Contrat
.DoesNotExist
:
1106 today
= date
.today()
1107 return (self
.date_debut
is None or self
.date_debut
<= today
) \
1108 and (self
.date_fin
is None or self
.date_fin
>= today
) \
1109 and not (self
.date_fin
is None and self
.date_debut
is None)
1112 class Dossier(Dossier_
):
1113 __doc__
= Dossier_
.__doc__
1114 poste
= models
.ForeignKey(
1115 Poste
, db_column
='poste', related_name
='rh_dossiers',
1116 help_text
=u
"Taper le nom du poste ou du type de poste",
1118 employe
= models
.ForeignKey(
1119 'Employe', db_column
='employe',
1120 help_text
=u
"Taper le nom de l'employé",
1121 related_name
='rh_dossiers', verbose_name
=u
"employé"
1123 principal
= models
.BooleanField(
1124 u
"dossier principal", default
=True,
1126 u
"Ce dossier est pour le principal poste occupé par l'employé"
1131 reversion
.register(Dossier
, format
='xml', follow
=[
1132 'rh_dossierpieces', 'rh_comparaisons', 'rh_remunerations',
1133 'rh_contrats', 'commentaires'
1137 class RHDossierClassementRecord(models
.Model
):
1138 classement
= models
.ForeignKey(
1140 related_name
='classement_records',
1142 dossier
= models
.ForeignKey(
1144 related_name
='classement_records',
1146 date_debut
= models
.DateField(
1148 help_text
=HELP_TEXT_DATE
,
1153 date_fin
= models
.DateField(
1155 help_text
=HELP_TEXT_DATE
,
1160 commentaire
= models
.CharField(
1167 def __unicode__(self
):
1168 return self
.classement
.__unicode__()
1171 verbose_name
= u
"Element d'historique de classement"
1172 verbose_name_plural
= u
"Historique de classement"
1175 def post_save_handler(cls
,
1182 today
= date
.today()
1183 previous_record
= None
1184 previous_classement
= None
1187 # Premièrement, pour les nouvelles instances:
1189 if not instance
.classement
:
1193 date_debut
=instance
.date_debut
,
1194 classement
=instance
.classement
,
1199 # Deuxièmement, pour les instances existantes:
1202 # 1. Est-ce que le classement a changé?
1203 # 2. Est-ce qu'une historique de classement existe déjà
1205 previous_record
= cls
.objects
.get(
1207 classement
=instance
.before_save
.classement
,
1210 except cls
.DoesNotExist
:
1211 if instance
.before_save
.classement
:
1212 # Il était censé avoir une historique de classement
1214 previous_record
= cls
.objects
.create(
1215 date_debut
=instance
.before_save
.date_debut
,
1216 classement
=instance
.before_save
.classement
,
1219 previous_classement
= instance
.before_save
.classement
1220 except MultipleObjectsReturned
:
1221 qs
= cls
.objects
.filter(
1223 classement
=instance
.before_save
.classement
,
1226 latest
= qs
.latest('date_debut')
1227 qs
.exclude(id=latest
.id).update(date_fin
=today
)
1228 previous_record
= latest
1229 previous_classement
= latest
.classement
1231 previous_classement
= previous_record
.classement
1234 instance
.classement
!=
1238 # Cas aucun changement:
1243 # Classement a changé
1245 previous_record
.date_fin
= today
1246 previous_record
.save()
1248 if instance
.classement
:
1251 classement
=instance
.classement
,
1256 class DossierPiece_(models
.Model
):
1258 Documents relatifs au Dossier (à l'occupation de ce poste par employé).
1259 Ex.: Lettre de motivation.
1261 nom
= models
.CharField(max_length
=255)
1262 fichier
= models
.FileField(
1263 upload_to
=dossier_piece_dispatch
, storage
=storage_prive
,
1271 def __unicode__(self
):
1272 return u
'%s' % (self
.nom
)
1275 class DossierPiece(DossierPiece_
):
1276 dossier
= models
.ForeignKey(
1277 Dossier
, db_column
='dossier', related_name
='rh_dossierpieces'
1280 reversion
.register(DossierPiece
, format
='xml')
1282 class DossierCommentaire(Commentaire
):
1283 dossier
= models
.ForeignKey(
1284 Dossier
, db_column
='dossier', related_name
='commentaires'
1287 reversion
.register(DossierCommentaire
, format
='xml')
1290 class DossierComparaison_(models
.Model
, DevisableMixin
):
1292 Photo d'une comparaison salariale au moment de l'embauche.
1294 objects
= DossierComparaisonManager()
1296 implantation
= models
.ForeignKey(
1297 ref
.Implantation
, related_name
="+", null
=True, blank
=True
1299 poste
= models
.CharField(max_length
=255, null
=True, blank
=True)
1300 personne
= models
.CharField(max_length
=255, null
=True, blank
=True)
1301 montant
= models
.IntegerField(null
=True)
1302 devise
= models
.ForeignKey(
1303 'Devise', related_name
='+', null
=True, blank
=True
1309 def __unicode__(self
):
1310 return "%s (%s)" % (self
.poste
, self
.personne
)
1313 class DossierComparaison(DossierComparaison_
):
1314 dossier
= models
.ForeignKey(
1315 Dossier
, related_name
='rh_comparaisons'
1318 reversion
.register(DossierComparaison
, format
='xml')
1323 class RemunerationMixin(models
.Model
):
1326 type = models
.ForeignKey(
1327 'TypeRemuneration', db_column
='type', related_name
='+',
1328 verbose_name
=u
"type de rémunération"
1330 type_revalorisation
= models
.ForeignKey(
1331 'TypeRevalorisation', db_column
='type_revalorisation',
1332 related_name
='+', verbose_name
=u
"type de revalorisation",
1333 null
=True, blank
=True
1335 montant
= models
.DecimalField(
1336 null
=True, blank
=True, max_digits
=12, decimal_places
=2
1337 ) # Annuel (12 mois, 52 semaines, 364 jours?)
1338 devise
= models
.ForeignKey('Devise', db_column
='devise', related_name
='+')
1340 # commentaire = precision
1341 commentaire
= models
.CharField(max_length
=255, null
=True, blank
=True)
1343 # date_debut = anciennement date_effectif
1344 date_debut
= models
.DateField(
1345 u
"date de début", null
=True, blank
=True, db_index
=True
1347 date_fin
= models
.DateField(
1348 u
"date de fin", null
=True, blank
=True, db_index
=True
1353 ordering
= ['type__nom', '-date_fin']
1355 def __unicode__(self
):
1356 return u
'%s %s (%s)' % (self
.montant
, self
.devise
.code
, self
.type.nom
)
1359 class Remuneration_(RemunerationMixin
, DevisableMixin
):
1361 Structure de rémunération (données budgétaires) en situation normale
1362 pour un Dossier. Si un Evenement existe, utiliser la structure de
1363 rémunération EvenementRemuneration de cet événement.
1365 objects
= RemunerationManager()
1368 def find_yearly_range(from_date
, to_date
, year
):
1369 today
= date
.today()
1370 year
= year
or date
.today().year
1371 year_start
= date(year
, 1, 1)
1372 year_end
= date(year
, 12, 31)
1374 def constrain_to_year(*dates
):
1376 S'assure que les dates soient dans le range year_start a
1379 return [min(max(year_start
, d
), year_end
)
1383 from_date
or year_start
, year_start
)
1385 to_date
or year_end
, year_end
)
1387 start_date
, end_date
= constrain_to_year(start_date
, end_date
)
1389 jours_annee
= (year_end
- year_start
).days
1390 jours_dates
= (end_date
- start_date
).days
1391 factor
= Decimal(str(jours_dates
)) / Decimal(str(jours_annee
))
1393 return start_date
, end_date
, factor
1396 def montant_ajuste_euros(self
, annee
=None):
1398 Le montant ajusté représente le montant annuel, ajusté sur la
1399 période de temps travaillée, multipliée par le ratio de temps
1400 travaillé (en rapport au temps plein).
1402 date_debut
, date_fin
, factor
= self
.find_yearly_range(
1408 montant_euros
= Decimal(str(self
.montant_euros_float()) or '0')
1410 if self
.type.nature_remuneration
!= u
'Accessoire':
1411 dossier
= getattr(self
, 'dossier', None)
1414 Dans le cas d'un DossierComparaisonRemuneration, il
1415 n'y a plus de reference au dossier.
1417 regime_travail
= REGIME_TRAVAIL_DEFAULT
1419 regime_travail
= self
.dossier
.regime_travail
1420 return (montant_euros
* factor
*
1421 regime_travail
/ 100)
1423 return montant_euros
1425 def montant_mois(self
):
1426 return round(self
.montant
/ 12, 2)
1428 def montant_avec_regime(self
):
1429 return round(self
.montant
* (self
.dossier
.regime_travail
/ 100), 2)
1431 def montant_euro_mois(self
):
1432 return round(self
.montant_euros() / 12, 2)
1434 def __unicode__(self
):
1436 devise
= self
.devise
.code
1439 return "%s %s" % (self
.montant
, devise
)
1443 verbose_name
= u
"Rémunération"
1444 verbose_name_plural
= u
"Rémunérations"
1447 class Remuneration(Remuneration_
):
1448 dossier
= models
.ForeignKey(
1449 Dossier
, db_column
='dossier', related_name
='rh_remunerations'
1452 reversion
.register(Remuneration
, format
='xml')
1457 class Contrat_(models
.Model
):
1459 Document juridique qui encadre la relation de travail d'un Employe
1460 pour un Poste particulier. Pour un Dossier (qui documente cette
1461 relation de travail) plusieurs contrats peuvent être associés.
1463 objects
= ContratManager()
1464 type_contrat
= models
.ForeignKey(
1465 'TypeContrat', db_column
='type_contrat',
1466 verbose_name
=u
'type de contrat', related_name
='+'
1468 date_debut
= models
.DateField(
1469 u
"date de début", db_index
=True
1471 date_fin
= models
.DateField(
1472 u
"date de fin", null
=True, blank
=True, db_index
=True
1474 fichier
= models
.FileField(
1475 upload_to
=contrat_dispatch
, storage
=storage_prive
, null
=True,
1476 blank
=True, max_length
=255
1481 ordering
= ['dossier__employe__nom']
1482 verbose_name
= u
"Contrat"
1483 verbose_name_plural
= u
"Contrats"
1485 def __unicode__(self
):
1486 return u
'%s - %s' % (self
.dossier
, self
.id)
1489 class Contrat(Contrat_
):
1490 dossier
= models
.ForeignKey(
1491 Dossier
, db_column
='dossier', related_name
='rh_contrats'
1494 reversion
.register(Contrat
, format
='xml')
1499 class CategorieEmploi(models
.Model
):
1501 Catégorie utilisée dans la gestion des Postes.
1502 Catégorie supérieure à TypePoste.
1504 nom
= models
.CharField(max_length
=255)
1508 verbose_name
= u
"catégorie d'emploi"
1509 verbose_name_plural
= u
"catégories d'emploi"
1511 def __unicode__(self
):
1514 reversion
.register(CategorieEmploi
, format
='xml')
1517 class FamilleProfessionnelle(models
.Model
):
1519 Famille professionnelle d'un poste.
1521 nom
= models
.CharField(max_length
=100)
1525 verbose_name
= u
'famille professionnelle'
1526 verbose_name_plural
= u
'familles professionnelles'
1528 def __unicode__(self
):
1531 reversion
.register(FamilleProfessionnelle
, format
='xml')
1534 class TypePoste(Archivable
):
1538 nom
= models
.CharField(max_length
=255)
1539 nom_feminin
= models
.CharField(u
"nom féminin", max_length
=255)
1540 is_responsable
= models
.BooleanField(
1541 u
"poste de responsabilité", default
=False
1543 categorie_emploi
= models
.ForeignKey(
1544 CategorieEmploi
, db_column
='categorie_emploi', related_name
='+',
1545 verbose_name
=u
"catégorie d'emploi"
1547 famille_professionnelle
= models
.ForeignKey(
1548 FamilleProfessionnelle
, related_name
='types_de_poste',
1549 verbose_name
=u
"famille professionnelle", blank
=True, null
=True
1554 verbose_name
= u
"Type de poste"
1555 verbose_name_plural
= u
"Types de poste"
1557 def __unicode__(self
):
1558 return u
'%s' % (self
.nom
)
1560 reversion
.register(TypePoste
, format
='xml')
1563 TYPE_PAIEMENT_CHOICES
= (
1564 (u
'Régulier', u
'Régulier'),
1565 (u
'Ponctuel', u
'Ponctuel'),
1568 NATURE_REMUNERATION_CHOICES
= (
1569 (u
'Traitement', u
'Traitement'),
1570 (u
'Indemnité', u
'Indemnités autres'),
1571 (u
'Charges', u
'Charges patronales'),
1572 (u
'Accessoire', u
'Accessoires'),
1573 (u
'RAS', u
'Rémunération autre source'),
1577 class TypeRemuneration(Archivable
):
1579 Catégorie de Remuneration.
1582 objects
= models
.Manager()
1583 sans_archives
= ArchivableManager()
1585 nom
= models
.CharField(max_length
=255)
1586 type_paiement
= models
.CharField(
1587 u
"type de paiement", max_length
=30, choices
=TYPE_PAIEMENT_CHOICES
1590 nature_remuneration
= models
.CharField(
1591 u
"nature de la rémunération", max_length
=30,
1592 choices
=NATURE_REMUNERATION_CHOICES
1597 verbose_name
= u
"Type de rémunération"
1598 verbose_name_plural
= u
"Types de rémunération"
1600 def __unicode__(self
):
1603 reversion
.register(TypeRemuneration
, format
='xml')
1606 class TypeRevalorisation(Archivable
):
1608 Justification du changement de la Remuneration.
1609 (Actuellement utilisé dans aucun traitement informatique.)
1611 nom
= models
.CharField(max_length
=255)
1615 verbose_name
= u
"Type de revalorisation"
1616 verbose_name_plural
= u
"Types de revalorisation"
1618 def __unicode__(self
):
1619 return u
'%s' % (self
.nom
)
1621 reversion
.register(TypeRevalorisation
, format
='xml')
1624 class Service(Archivable
):
1626 Unité administrative où les Postes sont rattachés.
1628 nom
= models
.CharField(max_length
=255)
1632 verbose_name
= u
"service"
1633 verbose_name_plural
= u
"services"
1635 def __unicode__(self
):
1638 reversion
.register(Service
, format
='xml')
1641 TYPE_ORGANISME_CHOICES
= (
1642 ('MAD', 'Mise à disposition'),
1643 ('DET', 'Détachement'),
1647 class OrganismeBstg(models
.Model
):
1649 Organisation d'où provient un Employe mis à disposition (MAD) de
1650 ou détaché (DET) à l'AUF à titre gratuit.
1652 (BSTG = bien et service à titre gratuit.)
1654 nom
= models
.CharField(max_length
=255)
1655 type = models
.CharField(max_length
=10, choices
=TYPE_ORGANISME_CHOICES
)
1656 pays
= models
.ForeignKey(ref
.Pays
, to_field
='code',
1658 related_name
='organismes_bstg',
1659 null
=True, blank
=True)
1662 ordering
= ['type', 'nom']
1663 verbose_name
= u
"Organisme BSTG"
1664 verbose_name_plural
= u
"Organismes BSTG"
1666 def __unicode__(self
):
1667 return u
'%s (%s)' % (self
.nom
, self
.get_type_display())
1669 reversion
.register(OrganismeBstg
, format
='xml')
1672 class Statut(Archivable
):
1674 Statut de l'Employe dans le cadre d'un Dossier particulier.
1677 code
= models
.CharField(
1678 max_length
=25, unique
=True,
1680 u
"Saisir un code court mais lisible pour ce statut : "
1681 u
"le code est utilisé pour associer les statuts aux autres "
1682 u
"données tout en demeurant plus lisible qu'un identifiant "
1686 nom
= models
.CharField(max_length
=255)
1690 verbose_name
= u
"Statut d'employé"
1691 verbose_name_plural
= u
"Statuts d'employé"
1693 def __unicode__(self
):
1694 return u
'%s : %s' % (self
.code
, self
.nom
)
1696 reversion
.register(Statut
, format
='xml')
1699 TYPE_CLASSEMENT_CHOICES
= (
1700 ('S', 'S -Soutien'),
1701 ('T', 'T - Technicien'),
1702 ('P', 'P - Professionel'),
1704 ('D', 'D - Direction'),
1705 ('SO', 'SO - Sans objet [expatriés]'),
1706 ('HG', 'HG - Hors grille [direction]'),
1710 class ClassementManager(models
.Manager
):
1712 Ordonner les spcéfiquement les classements.
1714 def get_query_set(self
):
1715 qs
= super(ClassementManager
, self
).get_query_set()
1716 qs
= qs
.extra(select
={
1717 'ponderation': 'FIND_IN_SET(type,"SO,HG,S,T,P,C,D")'
1719 qs
= qs
.extra(order_by
=('ponderation', 'echelon', 'degre', ))
1723 class ClassementArchivableManager(ClassementManager
,
1728 class Classement_(Archivable
):
1730 Éléments de classement de la
1731 "Grille générique de classement hiérarchique".
1733 Utile pour connaître, pour un Dossier, le salaire de base théorique lié au
1734 classement dans la grille. Le classement donne le coefficient utilisé dans:
1736 salaire de base = coefficient * valeur du point de l'Implantation du Poste
1738 objects
= ClassementManager()
1739 sans_archives
= ClassementArchivableManager()
1742 type = models
.CharField(max_length
=10, choices
=TYPE_CLASSEMENT_CHOICES
)
1743 echelon
= models
.IntegerField(u
"échelon", blank
=True, default
=0)
1744 degre
= models
.IntegerField(u
"degré", blank
=True, default
=0)
1745 coefficient
= models
.FloatField(u
"coefficient", blank
=True, null
=True)
1748 # annee # au lieu de date_debut et date_fin
1749 commentaire
= models
.TextField(null
=True, blank
=True)
1753 ordering
= ['type', 'echelon', 'degre', 'coefficient']
1754 verbose_name
= u
"Classement"
1755 verbose_name_plural
= u
"Classements"
1757 def __unicode__(self
):
1758 return u
'%s.%s.%s' % (self
.type, self
.echelon
, self
.degre
, )
1761 class Classement(Classement_
):
1762 __doc__
= Classement_
.__doc__
1764 reversion
.register(Classement
, format
='xml')
1767 class TauxChange_(models
.Model
):
1769 Taux de change de la devise vers l'euro (EUR)
1770 pour chaque année budgétaire.
1773 devise
= models
.ForeignKey('Devise', db_column
='devise')
1774 annee
= models
.IntegerField(u
"année")
1775 taux
= models
.FloatField(u
"taux vers l'euro")
1779 ordering
= ['-annee', 'devise__code']
1780 verbose_name
= u
"Taux de change"
1781 verbose_name_plural
= u
"Taux de change"
1782 unique_together
= ('devise', 'annee')
1784 def __unicode__(self
):
1785 return u
'%s : %s € (%s)' % (self
.devise
, self
.taux
, self
.annee
)
1788 class TauxChange(TauxChange_
):
1789 __doc__
= TauxChange_
.__doc__
1791 reversion
.register(TauxChange
, format
='xml')
1794 class ValeurPointManager(models
.Manager
):
1796 def get_query_set(self
):
1797 return super(ValeurPointManager
, self
).get_query_set() \
1798 .select_related('devise', 'implantation')
1801 class ValeurPoint_(models
.Model
):
1803 Utile pour connaître, pour un Dossier, le salaire de base théorique lié
1804 au classement dans la grille. La ValeurPoint s'obtient par l'implantation
1805 du Poste de ce Dossier : dossier.poste.implantation (pseudo code).
1807 salaire de base = coefficient * valeur du point de l'Implantation du Poste
1810 objects
= models
.Manager()
1811 actuelles
= ValeurPointManager()
1813 valeur
= models
.FloatField(null
=True)
1814 devise
= models
.ForeignKey('Devise', db_column
='devise', related_name
='+',)
1815 implantation
= models
.ForeignKey(ref
.Implantation
,
1816 db_column
='implantation',
1817 related_name
='%(app_label)s_valeur_point')
1819 annee
= models
.IntegerField()
1822 ordering
= ['-annee', 'implantation__nom']
1824 verbose_name
= u
"Valeur du point"
1825 verbose_name_plural
= u
"Valeurs du point"
1826 unique_together
= ('implantation', 'annee')
1828 def __unicode__(self
):
1829 return u
'%s %s %s [%s] %s' % (
1830 self
.devise
.code
, self
.annee
, self
.valeur
,
1831 self
.implantation
.nom_court
, self
.devise
.nom
1835 class ValeurPoint(ValeurPoint_
):
1836 __doc__
= ValeurPoint_
.__doc__
1838 reversion
.register(ValeurPoint
, format
='xml')
1841 class Devise(Archivable
):
1845 code
= models
.CharField(max_length
=10, unique
=True)
1846 nom
= models
.CharField(max_length
=255)
1850 verbose_name
= u
"devise"
1851 verbose_name_plural
= u
"devises"
1853 def __unicode__(self
):
1854 return u
'%s - %s' % (self
.code
, self
.nom
)
1856 reversion
.register(Devise
, format
='xml')
1859 class TypeContrat(Archivable
):
1863 nom
= models
.CharField(max_length
=255)
1864 nom_long
= models
.CharField(max_length
=255)
1868 verbose_name
= u
"Type de contrat"
1869 verbose_name_plural
= u
"Types de contrat"
1871 def __unicode__(self
):
1872 return u
'%s' % (self
.nom
)
1874 reversion
.register(TypeContrat
, format
='xml')
1879 class ResponsableImplantationProxy(ref
.Implantation
):
1887 verbose_name
= u
"Responsable d'implantation"
1888 verbose_name_plural
= u
"Responsables d'implantation"
1891 class ResponsableImplantation(models
.Model
):
1893 Le responsable d'une implantation.
1894 Anciennement géré sur le Dossier du responsable.
1896 employe
= models
.ForeignKey(
1897 'Employe', db_column
='employe', related_name
='+', null
=True,
1900 implantation
= models
.OneToOneField(
1901 "ResponsableImplantationProxy", db_column
='implantation',
1902 related_name
='responsable', unique
=True
1905 def __unicode__(self
):
1906 return u
'%s : %s' % (self
.implantation
, self
.employe
)
1909 ordering
= ['implantation__nom']
1910 verbose_name
= "Responsable d'implantation"
1911 verbose_name_plural
= "Responsables d'implantation"
1913 reversion
.register(ResponsableImplantation
, format
='xml')
1916 class UserProfile(models
.Model
):
1917 user
= models
.OneToOneField(User
, related_name
='profile')
1918 zones_administratives
= models
.ManyToManyField(
1919 ref
.ZoneAdministrative
,
1920 related_name
='profiles'
1923 verbose_name
= "Permissions sur zones administratives"
1924 verbose_name_plural
= "Permissions sur zones administratives"
1926 def __unicode__(self
):
1927 return self
.user
.__unicode__()
1929 reversion
.register(UserProfile
, format
='xml')
1933 TYPES_CHANGEMENT
= (
1940 class ChangementPersonnelNotifications(models
.Model
):
1942 verbose_name
= u
"Destinataire pour notices de mouvement de personnel"
1943 verbose_name_plural
= u
"Destinataires pour notices de mouvement de personnel"
1945 type = models
.CharField(
1947 choices
= TYPES_CHANGEMENT
,
1951 destinataires
= models
.ManyToManyField(
1953 related_name
='changement_notifications',
1956 def __unicode__(self
):
1958 self
.get_type_display(), ','.join(
1959 self
.destinataires
.all().values_list(
1960 'courriel', flat
=True))
1964 class ChangementPersonnel(models
.Model
):
1966 Une notice qui enregistre un changement de personnel, incluant:
1969 * Mouvement de personnel
1974 verbose_name
= u
"Mouvement de personnel"
1975 verbose_name_plural
= u
"Mouvements de personnel"
1977 def __unicode__(self
):
1978 return '%s: %s' % (self
.dossier
.__unicode__(),
1979 self
.get_type_display())
1982 def create_changement(cls
, dossier
, type):
1983 # If this employe has existing Changement, set them to invalid.
1984 cls
.objects
.filter(dossier__employe
=dossier
.employe
).update(valide
=False)
1996 def post_save_handler(cls
,
2003 # This defines the time limit used when checking in previous
2004 # files to see if an employee if new. Basically, if emloyee
2005 # left his position new_file.date_debut -
2006 # NEW_EMPLOYE_THRESHOLD +1 ago (compared to date_debut), then
2007 # if a new file is created for this employee, he will bec
2008 # onsidered "NEW" and a notice will be created to this effect.
2009 NEW_EMPLOYE_THRESHOLD
= datetime
.timedelta(7) # 7 days.
2011 other_dossier_qs
= instance
.employe
.rh_dossiers
.exclude(
2013 dd
= instance
.date_debut
2014 df
= instance
.date_fin
2015 today
= date
.today()
2017 # Here, verify differences between the instance, before and
2019 df_has_changed
= False
2023 df_has_changed
= True
2025 df_has_changed
= (df
!= instance
.before_save
.date_fin
and
2031 # Date de fin est None et c'est une nouvelle instance de
2033 if not df
and created
:
2034 # QS for finding other dossiers with a date_fin of None OR
2035 # with a date_fin >= to this dossier's date_debut
2036 exists_recent_file_qs
= other_dossier_qs
.filter(
2037 Q(date_fin__isnull
=True) |
2038 Q(date_fin__gte
=dd
- NEW_EMPLOYE_THRESHOLD
)
2041 # 1. If existe un Dossier récent
2042 if exists_recent_file_qs
.count() > 0:
2043 cls
.create_changement(
2047 # 2. Il n'existe un Dossier récent, et c'est une nouvelle
2048 # instance de Dossier:
2050 cls
.create_changement(
2055 elif not df
and not created
and cls
.objects
.filter(
2057 date_creation__gte
=today
- NEW_EMPLOYE_THRESHOLD
,
2060 cls
.create_changement(
2065 # Date de fin a été modifiée:
2067 # QS for other active files (date_fin == None), excludes
2069 exists_active_files_qs
= other_dossier_qs
.filter(
2070 Q(date_fin__isnull
=True))
2072 # 3. Date de fin a été modifiée et il n'existe aucun autre
2073 # dossier actifs: Depart
2074 if exists_active_files_qs
.count() == 0:
2075 cls
.create_changement(
2079 # 4. Dossier a une nouvelle date de fin par contre
2080 # d'autres dossiers actifs existent déjà: Mouvement
2082 cls
.create_changement(
2088 dossier
= models
.ForeignKey(
2090 related_name
='mouvements',
2093 valide
= models
.BooleanField(default
=True)
2094 date_creation
= models
.DateTimeField(
2096 communique
= models
.BooleanField(
2100 date_communication
= models
.DateTimeField(
2105 type = models
.CharField(
2107 choices
= TYPES_CHANGEMENT
,
2110 reversion
.register(ChangementPersonnel
, format
='xml')
2113 def dossier_pre_save_handler(sender
,
2117 # Store a copy of the model before save is called.
2118 if instance
.pk
is not None:
2119 instance
.before_save
= Dossier
.objects
.get(pk
=instance
.pk
)
2121 instance
.before_save
= None
2124 # Connect a pre_save handler that assigns a copy of the model as an
2125 # attribute in order to compare it in post_save.
2126 pre_save
.connect(dossier_pre_save_handler
, sender
=Dossier
)
2128 post_save
.connect(ChangementPersonnel
.post_save_handler
, sender
=Dossier
)
2129 post_save
.connect(RHDossierClassementRecord
.post_save_handler
, sender
=Dossier
)