Finished with new calcs for remunerations
[auf_rh_dae.git] / project / dae / templatetags / dae.py
index dd87a5d..54eef89 100644 (file)
@@ -1,8 +1,10 @@
 # -*- encoding: utf-8 -*-
 
 import os
+import datetime
 
 from django import template
+from django.db.models import Q
 # -*- coding: utf-8 -*-
 
 from project import groups
@@ -98,6 +100,7 @@ def pagination(context, page):
 def remun_form(context, dossier):
 
     return {
+        'annee_remun': None,
         'remunForm': ReadOnlyRemunFormSet(instance=dossier)
         }
 
@@ -106,6 +109,7 @@ def remun_form(context, dossier):
 def rh_remun_form(context, dossier):
 
     return {
+        'annee_remun': None,
         'remunForm': RHReadOnlyRemunFormSet(instance=dossier)
         }
 
@@ -113,6 +117,7 @@ def rh_remun_form(context, dossier):
 @register.inclusion_tag('dae/embauche-remun.html', takes_context=True)
 def poste_cmp_remun_form(context, poste_cmp):
     return {
+        'annee_remun': None,
         'remunForm': PosteCompReadOnlyRemunFormSet(instance=poste_cmp)
         }
 
@@ -120,6 +125,7 @@ def poste_cmp_remun_form(context, poste_cmp):
 @register.inclusion_tag('dae/embauche-remun.html', takes_context=True)
 def dossier_cmp_remun_form(context, dossier_cmp):
     return {
+        'annee_remun': None,
         'remunForm': DossierCompReadOnlyRemunFormSet(instance=dossier_cmp)
         }
 
@@ -134,15 +140,25 @@ def rh_remun_form_for_year(context, dossier, year):
         )
 
     def _get_qs(inst):
-        return inst.model.objects.filter(
-            dossier=inst.instance,
-            date_debut__year=year,
-            )
+        year_start = datetime.date(year, 1, 1)
+        year_end = datetime.date(year, 12, 31)
+        qs = inst.model.objects.filter(
+            Q(dossier=inst.instance) & (
+                Q(date_debut__lte=year_end, date_fin__gte=year_start) |
+                Q(date_debut__lte=year_end, date_fin__isnull=True) |
+                Q(date_debut__isnull=True, date_fin__gte=year_start) |
+                Q(date_debut__isnull=True, date_fin__isnull=True)
+                ))
+        return qs
         
     fs.get_queryset = _get_qs
 
     return {
+        'annee_remun': year,
         'remunForm': fs(instance=dossier)
         }
 
 
+@register.simple_tag
+def remun_ajuste(remun, annee=None):
+    return '%.2f' % remun.montant_ajuste_euros(annee)