Parcourir la source

Separating bills from payment

Alexandre Aubin il y a 8 ans
Parent
commit
b466c5aa19
3 fichiers modifiés avec 14 ajouts et 4 suppressions
  1. 2 0
      coin/billing/admin.py
  2. 11 3
      coin/billing/models.py
  3. 1 1
      coin/settings_base.py

+ 2 - 0
coin/billing/admin.py

@@ -159,3 +159,5 @@ class InvoiceAdmin(admin.ModelAdmin):
 
 
 
 
 admin.site.register(Invoice, InvoiceAdmin)
 admin.site.register(Invoice, InvoiceAdmin)
+
+admin.site.register(Payment)

+ 11 - 3
coin/billing/models.py

@@ -211,7 +211,7 @@ class Invoice(models.Model):
         self.validated = True
         self.validated = True
         self.save()
         self.save()
         self.generate_pdf()
         self.generate_pdf()
-        
+
         assert self.pdf_exists()
         assert self.pdf_exists()
 
 
     def pdf_exists(self):
     def pdf_exists(self):
@@ -281,6 +281,11 @@ class Payment(models.Model):
         ('other', 'Autre')
         ('other', 'Autre')
     )
     )
 
 
+    member = models.ForeignKey(Member, null=True, blank=True, default=None,
+		               related_name='payment',
+		               verbose_name='membre',
+		               on_delete=models.SET_NULL)
+
     payment_mean = models.CharField(max_length=100, null=True,
     payment_mean = models.CharField(max_length=100, null=True,
                                     default='transfer',
                                     default='transfer',
                                     choices=PAYMENT_MEAN_CHOICES,
                                     choices=PAYMENT_MEAN_CHOICES,
@@ -288,8 +293,8 @@ class Payment(models.Model):
     amount = models.DecimalField(max_digits=5, decimal_places=2, null=True,
     amount = models.DecimalField(max_digits=5, decimal_places=2, null=True,
                                  verbose_name='montant')
                                  verbose_name='montant')
     date = models.DateField(default=datetime.date.today)
     date = models.DateField(default=datetime.date.today)
-    invoice = models.ForeignKey(Invoice, verbose_name='facture',
-                                related_name='payments')
+    invoice = models.ForeignKey(Invoice, verbose_name='facture', null=True,
+                                blank=True, related_name='payments')
 
 
     def __unicode__(self):
     def __unicode__(self):
         return 'Paiment de %0.2f€' % self.amount
         return 'Paiment de %0.2f€' % self.amount
@@ -305,6 +310,9 @@ def set_invoice_as_paid_if_needed(sender, instance, **kwargs):
     Lorsqu'un paiement est enregistré, vérifie si la facture est alors
     Lorsqu'un paiement est enregistré, vérifie si la facture est alors
     complétement payée. Dans ce cas elle passe en réglée
     complétement payée. Dans ce cas elle passe en réglée
     """
     """
+    if instance.invoice == None :
+	return
+
     if (instance.invoice.amount_paid() >= instance.invoice.amount() and
     if (instance.invoice.amount_paid() >= instance.invoice.amount() and
             instance.invoice.status == 'open'):
             instance.invoice.status == 'open'):
         instance.invoice.status = 'closed'
         instance.invoice.status = 'closed'

+ 1 - 1
coin/settings_base.py

@@ -32,7 +32,7 @@ DATABASES = {
 
 
 # Hosts/domain names that are valid for this site; required if DEBUG is False
 # Hosts/domain names that are valid for this site; required if DEBUG is False
 # See https://docs.djangoproject.com/en/1.7/ref/settings/#allowed-hosts
 # See https://docs.djangoproject.com/en/1.7/ref/settings/#allowed-hosts
-ALLOWED_HOSTS = []
+ALLOWED_HOSTS = [ "yolo.test" ]
 
 
 # Local time zone for this installation. Choices can be found here:
 # Local time zone for this installation. Choices can be found here:
 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name