From f82ab4b833cdddd60a1edabeb8a82d795467b847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 5 Feb 2015 20:01:33 +0100 Subject: [PATCH] convert invoice values to proper datatypes (#6433) This removes the need to call portail_citoyen2 templatetags to do the conversion at template rendering time. --- facturier/models.py | 11 +++++++++++ facturier/templates/facturier/tipi.html | 16 ++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/facturier/models.py b/facturier/models.py index 81e3815..9e3ebed 100644 --- a/facturier/models.py +++ b/facturier/models.py @@ -1,3 +1,6 @@ +from datetime import datetime +from decimal import Decimal + from django.db import models from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _, pgettext_lazy @@ -99,6 +102,14 @@ class Regie(models.Model): invoice['download_url'] = reverse('invoice-download', args=(self.slug, invoice_id, invoice_hash)) break + # convert values to proper datatypes + for amount_key in ('paid_amount', 'total_amount', 'amount'): + if invoice.get(amount_key): + invoice[amount_key] = Decimal(invoice[amount_key]) + for date_key in ('creation_date', 'expiration_date', 'paid_date', + 'tipi_paid_date'): + if invoice.get(date_key): + invoice[date_key] = datetime.strptime(invoice[date_key], '%Y-%m-%d') return invoice diff --git a/facturier/templates/facturier/tipi.html b/facturier/templates/facturier/tipi.html index fbce3cf..8db74c2 100644 --- a/facturier/templates/facturier/tipi.html +++ b/facturier/templates/facturier/tipi.html @@ -1,5 +1,5 @@ {% extends 'base-cms.html' %} -{% load i18n portail_citoyen_tags facturier_tags %} +{% load i18n facturier_tags %} {% block breadcrumbs %}
  • Mes factures
  • @@ -44,21 +44,21 @@

    Facture n° {{ invoice.id }}

    - {% if invoice.paid_amount|to_decimal and invoice.total_amount != invoice.paid_amount %} + {% if invoice.paid_amount and invoice.total_amount != invoice.paid_amount %}

    Facture réglée partiellement

    {% endif %}

    Montant de la facture : {{ invoice.total_amount }} €

    Montant restant à régler : {{ invoice.amount }} €

    Facture émise le - {{ invoice.creation_date|to_date|date:"j F Y" }} + {{ invoice.creation_date|date:"j F Y" }} {% if invoice.prelevement_automatique %}
    Prélèvement automatique - {% if invoice.amount|to_decimal %} - prévu le {{ invoice.expiration_date|to_date|date:"j F Y" }} + {% if invoice.amount %} + prévu le {{ invoice.expiration_date|date:"j F Y" }} {% else %} - effectué le {{ invoice.paid_date|to_date|date:"j F Y" }} + effectué le {{ invoice.paid_date|date:"j F Y" }} {% endif %} {% endif %}

    @@ -91,8 +91,8 @@ {% elif invoice.paid %}

    Cette facture a été réglée - {% if invoice.paid_date %}le {{ invoice.paid_date|to_date|date:"j F Y" }} - {% elif invoice.tipi_paid_date %} le {{ invoice.tipi_paid_date|to_date|date:"j F Y" }} {% endif %} + {% if invoice.paid_date %}le {{ invoice.paid_date|date:"j F Y" }} + {% elif invoice.tipi_paid_date %} le {{ invoice.tipi_paid_date|date:"j F Y" }} {% endif %}

    {% elif invoice.expired %}