Total des remun trans-dossiers
[auf_rh_dae.git] / project / rh / lib.py
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:
@@ -364,6 +366,41 @@ class EmployeAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
                 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