Total des remun trans-dossiers
authorPA Parent <paparent@paparent.me>
Wed, 30 Nov 2011 20:32:35 +0000 (15:32 -0500)
committerPA Parent <paparent@paparent.me>
Wed, 30 Nov 2011 20:32:35 +0000 (15:32 -0500)
project/rh/lib.py
project/rh/templates/admin/rh/employe/change_form.html [new file with mode: 0644]

index 0d4d8dc..9cb2e14 100644 (file)
@@ -357,6 +357,8 @@ class EmployeAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
         }),
         )
 
         }),
         )
 
+    add_form_template = 'admin/change_form.html'
+
     def save_formset(self, request, form, formset, change):
         instances = formset.save(commit=False)
         for instance in instances:
     def save_formset(self, request, form, formset, change):
         instances = formset.save(commit=False)
         for instance in instances:
@@ -364,6 +366,41 @@ class EmployeAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
                 instance.owner = request.user
             instance.save()
 
                 instance.owner = request.user
             instance.save()
 
+    def render_change_form(self, request, context, *args, **kwargs):
+        obj = kwargs.get('obj', None)
+
+        if not obj:
+            return super(EmployeAdmin, self).render_change_form(request, context, *args, **kwargs)
+
+        remun = {}
+        remun_sum = 0
+        remun_sum_euro = 0
+        dossiers = obj.dossiers.all()
+
+        for dossier in dossiers:
+            this_remun, this_remun_sum, this_remun_sum_euro = calc_remun(dossier)
+
+            for item in this_remun:
+                if item not in remun:
+                    remun[item] = this_remun[item]
+                else:
+                    remun[item][0] += this_remun[item][0]
+                    remun[item][1] += this_remun[item][1]
+
+            remun_sum += this_remun_sum
+            remun_sum_euro += this_remun_sum_euro
+
+        extra = {
+            'remun': remun,
+            'remun_sum': remun_sum,
+            'remun_sum_euro': remun_sum_euro,
+        }
+
+        context.update(extra)
+
+        return super(EmployeAdmin, self).render_change_form(request, context, *args, **kwargs)
+
+
 class EmployeCommentaireAdmin(admin.ModelAdmin):
     pass
 
 class EmployeCommentaireAdmin(admin.ModelAdmin):
     pass
 
diff --git a/project/rh/templates/admin/rh/employe/change_form.html b/project/rh/templates/admin/rh/employe/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 %}