[#2394] Récapitulatif de la rémunération en bas du dossier
authorPA Parent <paparent@paparent.me>
Wed, 23 Nov 2011 16:49:55 +0000 (11:49 -0500)
committerPA Parent <paparent@paparent.me>
Wed, 23 Nov 2011 16:49:55 +0000 (11:49 -0500)
project/rh/lib.py
project/rh/models.py
project/rh/templates/admin/rh/dossier/change_form.html [new file with mode: 0644]

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
 
index f3cfbc8..3cd607c 100644 (file)
@@ -1015,8 +1015,7 @@ class TauxChange_(AUFMetadata):
     pour chaque année budgétaire.
     """
     # Identification
-    devise = models.ForeignKey('Devise', db_column='devise',
-                            related_name='+')
+    devise = models.ForeignKey('Devise', db_column='devise')
     annee = models.IntegerField(verbose_name = u"Année")
     taux = models.FloatField(verbose_name = u"Taux vers l'euro")
 
diff --git a/project/rh/templates/admin/rh/dossier/change_form.html b/project/rh/templates/admin/rh/dossier/change_form.html
new file mode 100644 (file)
index 0000000..fc49f2a
--- /dev/null
@@ -0,0 +1,26 @@
+{% extends 'admin/change_form.html' %}
+
+{% block content %}
+{{ block.super }}
+
+<h2>Rémunération cette année</h2>
+<table>
+       <tr>
+               <th></th>
+               <th>Devise locale</th>
+               <th>Euro</th>
+       </tr>
+{% for t, m in remun.iteritems %}
+       <tr>
+               <td>{{ t }}</td>
+               <td>{{ m.0 }}</td>
+               <td>{{ m.1 }}</td>
+       </tr>
+{% endfor %}
+       <tr>
+               <td>Total</td>
+               <td>{{ remun_sum }}</td>
+               <td>{{ remun_sum_euro }}</td>
+</table>
+
+{% endblock %}