Browse Source

Add default dates

Fabs 11 years ago
parent
commit
b48a847d95
1 changed files with 17 additions and 5 deletions
  1. 17 5
      coin/billing/models.py

+ 17 - 5
coin/billing/models.py

@@ -1,4 +1,6 @@
 # -*- coding: utf-8 -*-
+import datetime
+import calendar
 from django.db import models
 from coin.offers.models import Offer 
 
@@ -13,12 +15,22 @@ class Invoice(models.Model):
     status = models.CharField(max_length=50, choices=INVOICES_STATUS_CHOICES,
                               default='open')
     amount = models.DecimalField(max_digits=5, decimal_places=2)
-    date = models.DateField(auto_now_add=True, null=True)
-    period_from = models.DateField(auto_now_add=False, null=True)
-    period_to = models.DateField(auto_now_add=False, null=True)
-    date_due = models.DateField(auto_now_add=False, null=True)
+    date = models.DateField(default=datetime.date.today, null=True)
+    period_from = models.DateField(
+        default=datetime.date(datetime.date.today().year,
+                datetime.date.today().month, 1),
+        null=True)
+    period_to = models.DateField(
+        default=datetime.date(datetime.date.today().year,
+                datetime.date.today().month + 1, 1) - datetime.timedelta (days = 1),
+        null=True)
+    date_due = models.DateField(
+        default=datetime.date(datetime.date.today().year,
+                    datetime.date.today().month + 1, 1) - datetime.timedelta (days = 1),
+        null=True)
     offer = models.ForeignKey(Offer)
 
+
 class InvoiceDetail(models.Model):
 
     label = models.CharField(max_length=100)
@@ -34,5 +46,5 @@ class InvoiceDetail(models.Model):
 class Payment(models.Model):
     payment_means = models.CharField(max_length=100, null=True)
     amount = models.DecimalField(max_digits=7, decimal_places=2, null=True)
-    date = models.DateField(auto_now_add=True)
+    date = models.DateField(default=datetime.date.today)
     invoce = models.ForeignKey(Invoice)