|
@@ -1,4 +1,6 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
+from __future__ import unicode_literals
|
|
|
+
|
|
|
import datetime
|
|
|
import random
|
|
|
import uuid
|
|
@@ -17,21 +19,21 @@ from coin.utils import private_files_storage, start_of_month, end_of_month
|
|
|
|
|
|
def next_invoice_number():
|
|
|
"Détermine un numéro de facture aléatoire"
|
|
|
- return u'%s%02i-%i-%i' % (datetime.date.today().year,
|
|
|
+ return '%s%02i-%i-%i' % (datetime.date.today().year,
|
|
|
datetime.date.today().month,
|
|
|
random.randrange(100, 999),
|
|
|
random.randrange(100, 999))
|
|
|
|
|
|
def invoice_pdf_filename(instance, filename):
|
|
|
"Nom du fichier pdf à stocker pour les factures"
|
|
|
- return u'invoices/%d_%s_%s.pdf' % (getattr(instance,'member.id',0), instance.number, uuid.uuid4())
|
|
|
+ return 'invoices/%d_%s_%s.pdf' % (getattr(instance,'member.id',0), instance.number, uuid.uuid4())
|
|
|
|
|
|
class Invoice(models.Model):
|
|
|
|
|
|
INVOICES_STATUS_CHOICES = (
|
|
|
- ('open', u'A payer'),
|
|
|
- ('closed', u'Reglée'),
|
|
|
- ('trouble', u'Litige')
|
|
|
+ ('open', 'A payer'),
|
|
|
+ ('closed', 'Reglée'),
|
|
|
+ ('trouble', 'Litige')
|
|
|
)
|
|
|
|
|
|
validated = models.BooleanField(default=False, verbose_name='Validée')
|
|
@@ -46,14 +48,14 @@ class Invoice(models.Model):
|
|
|
date_due = models.DateField(
|
|
|
default=end_of_month,
|
|
|
null=True,
|
|
|
- verbose_name=u'Date d\'échéance de paiement')
|
|
|
+ verbose_name='Date d\'échéance de paiement')
|
|
|
member = models.ForeignKey(Member, null=True, blank=True, default=None,
|
|
|
related_name='invoices',
|
|
|
verbose_name='Membre',
|
|
|
on_delete=models.SET_NULL)
|
|
|
pdf = models.FileField(storage=private_files_storage, upload_to=invoice_pdf_filename,
|
|
|
null=True, blank=True,
|
|
|
- verbose_name=u'PDF')
|
|
|
+ verbose_name='PDF')
|
|
|
|
|
|
def amount(self):
|
|
|
"Calcul le montant de la facture en fonction des éléments de détails"
|
|
@@ -88,7 +90,7 @@ class Invoice(models.Model):
|
|
|
def generate_pdf(self):
|
|
|
"Make and store a pdf file for the invoice"
|
|
|
pdf_file = render_as_pdf('billing/invoice_pdf.html', {"invoice": self})
|
|
|
- self.pdf.save(u'%s.pdf' % self.number, pdf_file)
|
|
|
+ self.pdf.save('%s.pdf' % self.number, pdf_file)
|
|
|
|
|
|
def validate(self):
|
|
|
"""
|
|
@@ -104,7 +106,7 @@ class Invoice(models.Model):
|
|
|
return self.validated and bool(self.pdf) and private_files_storage.exists(self.pdf.name)
|
|
|
|
|
|
def __unicode__(self):
|
|
|
- return u'#%s %0.2f€ %s' % (self.number, self.amount(), self.date_due)
|
|
|
+ return '#%s %0.2f€ %s' % (self.number, self.amount(), self.date_due)
|
|
|
|
|
|
class Meta:
|
|
|
verbose_name = 'facture'
|
|
@@ -115,7 +117,7 @@ class InvoiceDetail(models.Model):
|
|
|
label = models.CharField(max_length=100)
|
|
|
amount = models.DecimalField(max_digits=5, decimal_places=2,
|
|
|
verbose_name='Montant')
|
|
|
- quantity = models.DecimalField(null=True, verbose_name=u'Quantité',
|
|
|
+ quantity = models.DecimalField(null=True, verbose_name='Quantité',
|
|
|
default=1.0, decimal_places=2, max_digits=4)
|
|
|
tax = models.DecimalField(null=True, default=0.0, decimal_places=2,
|
|
|
max_digits=4, verbose_name='TVA',
|
|
@@ -129,14 +131,14 @@ class InvoiceDetail(models.Model):
|
|
|
default=start_of_month,
|
|
|
null=True,
|
|
|
blank=True,
|
|
|
- verbose_name=u'Début de période',
|
|
|
- help_text=u'Date de début de période sur laquelle est facturé cet item')
|
|
|
+ verbose_name='Début de période',
|
|
|
+ help_text='Date de début de période sur laquelle est facturé cet item')
|
|
|
period_to = models.DateField(
|
|
|
default=end_of_month,
|
|
|
null=True,
|
|
|
blank=True,
|
|
|
- verbose_name=u'Fin de période',
|
|
|
- help_text=u'Date de fin de période sur laquelle est facturé cet item')
|
|
|
+ verbose_name='Fin de période',
|
|
|
+ help_text='Date de fin de période sur laquelle est facturé cet item')
|
|
|
|
|
|
def __unicode__(self):
|
|
|
return self.label
|
|
@@ -153,10 +155,10 @@ class InvoiceDetail(models.Model):
|
|
|
class Payment(models.Model):
|
|
|
|
|
|
PAYMENT_MEAN_CHOICES = (
|
|
|
- ('cash', u'Espèces'),
|
|
|
- ('check', u'Chèque'),
|
|
|
- ('transfer', u'Virement'),
|
|
|
- ('other', u'Autre')
|
|
|
+ ('cash', 'Espèces'),
|
|
|
+ ('check', 'Chèque'),
|
|
|
+ ('transfer', 'Virement'),
|
|
|
+ ('other', 'Autre')
|
|
|
)
|
|
|
|
|
|
payment_mean = models.CharField(max_length=100, null=True,
|
|
@@ -170,7 +172,7 @@ class Payment(models.Model):
|
|
|
related_name='payments')
|
|
|
|
|
|
def __unicode__(self):
|
|
|
- return u'Paiment de %0.2f€' % self.amount
|
|
|
+ return 'Paiment de %0.2f€' % self.amount
|
|
|
|
|
|
class Meta:
|
|
|
verbose_name = 'paiement'
|