Browse Source

Separating bills from payment

Alexandre Aubin 8 years ago
parent
commit
ad644779f1
3 changed files with 14 additions and 3 deletions
  1. 2 0
      coin/billing/admin.py
  2. 11 2
      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(Payment)

+ 11 - 2
coin/billing/models.py

@@ -269,6 +269,11 @@ class Payment(models.Model):
         ('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,
                                     default='transfer',
                                     choices=PAYMENT_MEAN_CHOICES,
@@ -276,8 +281,8 @@ class Payment(models.Model):
     amount = models.DecimalField(max_digits=5, decimal_places=2, null=True,
                                  verbose_name='montant')
     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):
         return 'Paiment de %0.2f€' % self.amount
@@ -293,6 +298,10 @@ def set_invoice_as_paid_if_needed(sender, instance, **kwargs):
     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
     """
+
+    if instance.invoice == None :
+	return
+
     if (instance.invoice.amount_paid >= instance.invoice.amount and
             instance.invoice.status == 'open'):
         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
 # 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:
 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name