From 7d8f67895a635b30d59900e76e92aee0941a768d Mon Sep 17 00:00:00 2001 From: "Benoit C. Sirois" Date: Tue, 5 Mar 2013 15:13:01 -0500 Subject: [PATCH] Finished with new calcs for remunerations --- project/assets/js/remun.js | 3 +- project/dae/templates/dae/embauche-remun.html | 34 +++++++++- project/dae/templatetags/dae.py | 24 +++++-- project/rh/models.py | 71 ++++++++++++-------- project/rh/templates/rh/include/dossier.html | 2 +- project/rh/templates/rh/include/remunerations.html | 2 - project/rh/views.py | 1 + 7 files changed, 98 insertions(+), 39 deletions(-) diff --git a/project/assets/js/remun.js b/project/assets/js/remun.js index bc98a12..c0fd635 100644 --- a/project/assets/js/remun.js +++ b/project/assets/js/remun.js @@ -16,8 +16,7 @@ function remun_line(input) { // return; // } - value = (montant_annuel.val()); - value = roundNumber(value, 2) + value = montant_annuel.val(); montant_annuel.val(roundNumber(value, 2)); diff --git a/project/dae/templates/dae/embauche-remun.html b/project/dae/templates/dae/embauche-remun.html index 56d95a2..4214d98 100644 --- a/project/dae/templates/dae/embauche-remun.html +++ b/project/dae/templates/dae/embauche-remun.html @@ -1,4 +1,5 @@ {% load l10n %} +{% load dae %} {% for f in remunForm.management_form %} {{ f }} @@ -10,7 +11,9 @@ Devise locale Annuel
(visé) Annuel Euros
(visé) + {% if remunForm.read_only %} Annuel Euros
(ajusté par période) + {% endif %} Précision {% if not remunForm.read_only %} Supprimer @@ -24,11 +27,24 @@ {% for f in group.forms %} {{ f.id }} - {{ f.type.errors }} {{ f.type }} + {{ f.type.errors }} {{ f.type }} + {% if f.instance.date_debut or f.instance.date_fin %} + {% if f.instance.date_debut or f.instance.date_fin %}({% endif %} + {% if f.instance.date_debut %}{{f.instance.date_debut}}{% endif %} + - + {% if f.instance.date_fin %}{{f.instance.date_fin}}{% endif %} + {% if f.instance.date_debut or f.instance.date_fin %}){% endif %} + {% endif %} + {{ f.devise.errors }} {{ f.devise }} {{ f.montant.errors }} {{ f.montant }} - {{ f.instance.montant_ajuste_euros|stringformat:".2f" }} + + {% if remunForm.read_only %} + + {% remun_ajuste f.instance annee_remun %} + + {% endif %} {{ f.commentaire.errors }} {{ f.commentaire }} {% if not remunForm.read_only %} {{ f.DELETE }} @@ -45,7 +61,9 @@ + {% if remunForm.read_only %} + {% endif %}   {% if not remunForm.read_only %}   @@ -58,7 +76,9 @@ + {% if remunForm.read_only %} + {% endif %}   {% if not remunForm.read_only %}   @@ -69,7 +89,9 @@ + {% if remunForm.read_only %} + {% endif %}   {% if not remunForm.read_only %}   @@ -82,7 +104,11 @@ {{ f.devise.errors }} {{ f.devise }} {{ f.montant.errors }} {{ f.montant }} - {{ f.instance.montant_ajuste_euros|stringformat:".2f" }} + {% if remunForm.read_only %} + + {% remun_ajuste f.instance annee_remun %} + + {% endif %} {{ f.commentaire.errors }} {{ f.commentaire }} {% if not remunForm.read_only %} {{ f.DELETE }} @@ -99,7 +125,9 @@ + {% if remunForm.read_only %} + {% endif %}   {% if not remunForm.read_only %}   diff --git a/project/dae/templatetags/dae.py b/project/dae/templatetags/dae.py index dd87a5d..54eef89 100644 --- a/project/dae/templatetags/dae.py +++ b/project/dae/templatetags/dae.py @@ -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) diff --git a/project/rh/models.py b/project/rh/models.py index 8f3b423..7a80262 100644 --- a/project/rh/models.py +++ b/project/rh/models.py @@ -1294,38 +1294,55 @@ class Remuneration_(RemunerationMixin, DevisableMixin): """ objects = RemunerationManager() + @staticmethod + def find_yearly_range(from_date, to_date, year): + today = date.today() + year = year or date.today().year + year_start = date(year, 1, 1) + year_end = date(year, 12, 31) + + def constrain_to_year(*dates): + """ + S'assure que les dates soient dans le range year_start a + year_end + """ + return [min(max(year_start, d), year_end) + for d in dates] + + start_date = max( + from_date or year_start, year_start) + end_date = min( + to_date or year_end, year_end) + + start_date, end_date = constrain_to_year(start_date, end_date) + + jours_annee = (year_end - year_start).days + jours_dates = (end_date - start_date).days + factor = Decimal(str(jours_dates)) / Decimal(str(jours_annee)) + + return start_date, end_date, factor + + def montant_ajuste_euros(self, annee=None): """ Le montant ajusté représente le montant annuel, ajusté sur la période de temps travaillée, multipliée par le ratio de temps travaillé (en rapport au temps plein). """ - if not annee: - annee = min( - self.date_debut or date.today(), date.today()).year - - debut_annee = date(annee, 1, 1) - fin_annee = date(annee, 12, 31) - jours_annee = (fin_annee - debut_annee).days + 1 - - date_count_debut = max( - self.date_debut or debut_annee, debut_annee) - date_count_fin = min(self.date_fin or fin_annee, fin_annee) - jours = (date_count_fin - date_count_debut).days + 1 - print "Date debut: ", date_count_debut - print "Date fin: ", date_count_fin - print "Jours: ", jours - - montant_euro = Decimal(str(self.montant_euros_float())) + date_debut, date_fin, factor = self.find_yearly_range( + self.date_debut, + self.date_fin, + annee, + ) + + montant_euros = Decimal(str(self.montant_euros_float()) or '0') + if self.type.nature_remuneration != u'Accessoire': - return (montant_euro * (( - min(self.date_fin or fin_annee, fin_annee) - - max(self.date_debut or debut_annee, debut_annee) - ).days + 1) / jours_annee * self.dossier.regime_travail / 100) + return (montant_euros * factor * + self.dossier.regime_travail / 100) else: - return montant_euro - - + return montant_euros + def montant_mois(self): return round(self.montant / 12, 2) @@ -1470,11 +1487,11 @@ TYPE_PAIEMENT_CHOICES = ( ) NATURE_REMUNERATION_CHOICES = ( - (u'Accessoire', u'Accessoire'), - (u'Charges', u'Charges patronales'), + (u'Traitement', u'Traitement'), (u'Indemnité', u'Indemnité autre'), + (u'Charges', u'Charges patronales'), + (u'Accessoire', u'Accessoire'), (u'RAS', u'Rémunération autre source'), - (u'Traitement', u'Traitement'), ) diff --git a/project/rh/templates/rh/include/dossier.html b/project/rh/templates/rh/include/dossier.html index c495f60..331c391 100644 --- a/project/rh/templates/rh/include/dossier.html +++ b/project/rh/templates/rh/include/dossier.html @@ -6,7 +6,7 @@ diff --git a/project/rh/templates/rh/include/remunerations.html b/project/rh/templates/rh/include/remunerations.html index dca6fda..c5cb2c8 100644 --- a/project/rh/templates/rh/include/remunerations.html +++ b/project/rh/templates/rh/include/remunerations.html @@ -20,5 +20,3 @@ {% endfor %} {% endif %} - - diff --git a/project/rh/views.py b/project/rh/views.py index ce45ba3..3859727 100644 --- a/project/rh/views.py +++ b/project/rh/views.py @@ -45,6 +45,7 @@ def devises(): data['taux_euro'] = taux[0].taux data['devise_code'] = d.id liste.append(data) + return liste -- 1.7.10.4