Commit | Line | Data |
---|---|---|
4c53dda4 OL |
1 | # -*- encoding: utf-8 -*- |
2 | ||
3 | from django.core.management.base import BaseCommand, CommandError | |
a45e414b | 4 | from project.rh.models import Poste, Employe |
4c53dda4 OL |
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 | ||
bdc6d9ff OL |
20 | if p.actif is False: |
21 | vacant = None | |
22 | ||
4c53dda4 OL |
23 | if test != vacant: |
24 | p.vacant = vacant | |
25 | p.save() | |
26 | ||
a45e414b OL |
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 | ||
4c53dda4 OL |
40 | |
41 | class Command(BaseCommand): | |
42 | ||
43 | def handle(self, *args, **options): | |
a45e414b | 44 | |
31a784bf OL |
45 | if args[0] == "cron": |
46 | flag_vacant() | |
47 | flag_nb_postes() | |
48 | ||
4c53dda4 OL |
49 | if args[0] == "vacant": |
50 | flag_vacant() | |
51 | self.stdout.write("Flag vacant mis à jour\n") | |
a45e414b OL |
52 | |
53 | if args[0] == "nb_postes": | |
54 | flag_nb_postes() | |
55 | self.stdout.write("Flag nb_postes mis à jour\n") |