Fix for odette
[auf_rh_dae.git] / project / rh / lib.py
CommitLineData
1a7b9e36 1from collections import defaultdict
ed3cbb32 2import datetime
1a7b9e36 3
ed3cbb32 4from django.db.models import Q
1a7b9e36
DB
5from django.utils.encoding import smart_str
6
49c98347
PP
7
8def calc_remun(dossier):
9 thisyear = datetime.date.today().year
10 thisyearfilter = Q(date_debut__year=thisyear) | Q(date_fin__year=thisyear)
11
da6c523f 12 remunnow = dossier.rh_remunerations.filter(thisyearfilter)
49c98347
PP
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
e84c8ef1 21 sums_euro[nature] += r.montant_euros()
49c98347 22 remun_sum += r.montant
e84c8ef1 23 remun_sum_euro += r.montant_euros()
49c98347
PP
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
53ae644d 31
1a7b9e36
DB
32def 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']
53ae644d 40
1a7b9e36
DB
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