[#3165] Remplacé les filtres et protection par région pour des filtres et protections...
[auf_rh_dae.git] / project / rh / lib.py
1 from collections import defaultdict
2 import datetime
3
4 from django.db.models import Q
5 from django.utils.encoding import smart_str
6
7
8 def calc_remun(dossier):
9 thisyear = datetime.date.today().year
10 thisyearfilter = Q(date_debut__year=thisyear) | Q(date_fin__year=thisyear)
11
12 remunnow = dossier.rh_remunerations.filter(thisyearfilter)
13
14 remun_sum = 0
15 remun_sum_euro = 0
16 sums = defaultdict(int)
17 sums_euro = defaultdict(int)
18 for r in remunnow:
19 nature = r.type.nature_remuneration
20 sums[nature] += r.montant
21 sums_euro[nature] += r.montant_euros()
22 remun_sum += r.montant
23 remun_sum_euro += r.montant_euros()
24
25 remun = {}
26 sums = dict(sums)
27 for n, s in sums.iteritems():
28 remun[n] = [sums[n], sums_euro[n]]
29
30 return remun, remun_sum, remun_sum_euro
31
32 def get_lookup_params(request):
33 lookup_params = dict(request.GET.items())
34
35 # order by, order type
36 if 'ot' in lookup_params:
37 del lookup_params['ot']
38 if 'o' in lookup_params:
39 del lookup_params['o']
40
41 # autres
42 for key, value in lookup_params.items():
43 if not isinstance(key, str):
44 # 'key' will be used as a keyword argument later, so Python
45 # requires it to be a string.
46 del lookup_params[key]
47 lookup_params[smart_str(key)] = value
48
49 return lookup_params