[#2394] Récapitulatif de la rémunération en bas du dossier
[auf_rh_dae.git] / project / rh / lib.py
index e832a89..a2f0cad 100644 (file)
@@ -1,5 +1,8 @@
 # -*- encoding: utf-8 -*-
 
+from collections import defaultdict
+import datetime
+
 from django.db import models
 from django.contrib import admin
 from django.conf import settings
@@ -275,6 +278,41 @@ class DossierAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin,)
                 instance.owner = request.user
             instance.save()
 
+    def render_change_form(self, request, context, *args, **kwargs):
+        obj = kwargs['obj']
+
+        thisyear = datetime.date.today().year
+        thisyearfilter = Q(date_debut__year=thisyear) | Q(date_fin__year=thisyear)
+
+        remunnow = obj.rh_remuneration_remunerations.filter(thisyearfilter)
+
+        remun_sum = 0
+        remun_sum_euro = 0
+        sums = defaultdict(int)
+        sums_euro = defaultdict(int)
+        for r in remunnow:
+            nature = r.type.nature_remuneration
+            sums[nature] += r.montant
+            sums_euro[nature] += r.montant_euro()
+            remun_sum += r.montant
+            remun_sum_euro += r.montant_euro()
+
+        remun = {}
+        sums = dict(sums)
+        for n, s in sums.iteritems():
+            remun[n] = [sums[n], sums_euro[n]]
+
+        extra = {
+            'remun': remun,
+            'remun_sum': remun_sum,
+            'remun_sum_euro': remun_sum_euro,
+        }
+
+        context.update(extra)
+
+        return super(DossierAdmin, self).render_change_form(request, context, *args, **kwargs)
+
+
 class DossierPieceAdmin(admin.ModelAdmin):
     pass