47e708df7e3f27a9dda3d43272b1ea21edf70385
[auf_rh_dae.git] / project / rh / management / commands / rh.py
1 # -*- encoding: utf-8 -*-
2
3 from django.core.management.base import BaseCommand, CommandError
4 from project.rh.models import Poste, Employe
5
6
7 def flag_vacant():
8 """
9 Mettre a jour le booleen de poste pour savoir si le poste
10 est vacant.
11 """
12 for p in Poste.objects.all():
13 test = p.vacant
14 employes = p.occupe_par()
15 if len(employes) > 0:
16 vacant = False
17 else:
18 vacant = True
19
20 if p.actif is False:
21 vacant = None
22
23 if test != vacant:
24 p.vacant = vacant
25 p.save()
26
27 def flag_nb_postes():
28 """
29 """
30 for e in Employe.objects.all():
31 total = 0
32 test = e.nb_postes
33 for d in e.rh_dossiers.all():
34 if d.date_fin is None:
35 total +=1
36 if test != total:
37 e.nb_postes = total
38 e.save()
39
40
41 class Command(BaseCommand):
42
43 def handle(self, *args, **options):
44
45 if args[0] == "vacant":
46 flag_vacant()
47 self.stdout.write("Flag vacant mis à jour\n")
48
49 if args[0] == "nb_postes":
50 flag_nb_postes()
51 self.stdout.write("Flag nb_postes mis à jour\n")