convert invoice values to proper datatypes (#6433)

This removes the need to call portail_citoyen2 templatetags to do the
conversion at template rendering time.
This commit is contained in:
Frédéric Péters 2015-02-05 20:01:33 +01:00
parent 03ea94fc7f
commit f82ab4b833
2 changed files with 19 additions and 8 deletions

View File

@ -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

View File

@ -1,5 +1,5 @@
{% extends 'base-cms.html' %}
{% load i18n portail_citoyen_tags facturier_tags %}
{% load i18n facturier_tags %}
{% block breadcrumbs %}
<li><a href="/factures/">Mes factures</a></li>
@ -44,21 +44,21 @@
<h1>Facture n° {{ invoice.id }}</h1>
<div class="rteContent col">
<div class="wrapSpecial">
{% if invoice.paid_amount|to_decimal and invoice.total_amount != invoice.paid_amount %}
{% if invoice.paid_amount and invoice.total_amount != invoice.paid_amount %}
<h2>Facture réglée partiellement</h2>
{% endif %}
<h2>Montant de la facture : {{ invoice.total_amount }} €</h2>
<h2>Montant restant à régler : {{ invoice.amount }} €</h2>
<p>Facture émise le
{{ invoice.creation_date|to_date|date:"j F Y" }}
{{ invoice.creation_date|date:"j F Y" }}
{% if invoice.prelevement_automatique %}
<br />
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 %}
</p>
@ -91,8 +91,8 @@
{% elif invoice.paid %}
<p>
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 %}
</p>
{% elif invoice.expired %}