Browse Source

Set date to validation date

That implies that the user do no longer have choice on bill date : it's the
current date at the time of validation.

ref #85
Jocelyn Delande 8 years ago
parent
commit
0fb6bb0051
3 changed files with 17 additions and 2 deletions
  1. 3 1
      coin/billing/models.py
  2. 13 1
      coin/billing/tests.py
  3. 1 0
      requirements.txt

+ 3 - 1
coin/billing/models.py

@@ -107,7 +107,8 @@ class Invoice(models.Model):
                               default='open',
                               verbose_name='statut')
     date = models.DateField(
-        default=datetime.date.today, null=True, verbose_name='date')
+        default=datetime.date.today, null=True, verbose_name='date',
+        help_text='Cette date sera définie à la date de validation dans la facture finale')
     date_due = models.DateField(
         default=end_of_month,
         null=True,
@@ -179,6 +180,7 @@ class Invoice(models.Model):
         Switch invoice to validate mode. This set to False the draft field
         and generate the pdf
         """
+        self.date = datetime.date.today()
         self.number = Invoice.objects.get_next_invoice_number(self.date)
         self.validated = True
         self.save()

+ 13 - 1
coin/billing/tests.py

@@ -6,6 +6,7 @@ from decimal import Decimal
 
 from django.conf import settings
 from django.test import TestCase, Client
+from freezegun import freeze_time
 from coin.members.tests import MemberTestsUtils
 from coin.members.models import Member, LdapUser
 from coin.billing.models import Invoice, InvoiceQuerySet
@@ -230,15 +231,26 @@ class InvoiceQuerySetTests(TestCase):
             Invoice.objects.get_next_invoice_number(datetime.date(2016,1,1)),
             '2016-01-000001')
 
+    @freeze_time('2016-01-01')
     def test_number_workflow(self):
         iv = Invoice.objects.create()
         self.assertEqual(iv.number, 'DRAFT-1')
         iv.validate()
-        self.assertRegexpMatches(iv.number, r'.*-000001$')
+        self.assertRegexpMatches(iv.number, r'2016-01-000001$')
 
+    @freeze_time('2016-01-01')
     def test_get_second_of_month_invoice_number(self):
         first_bill = Invoice.objects.create(date=datetime.date(2016,1,1))
         first_bill.validate()
         self.assertEqual(
             Invoice.objects.get_next_invoice_number(datetime.date(2016,1,1)),
             '2016-01-000002')
+
+    def test_bill_date_is_validation_date(self):
+        bill = Invoice.objects.create(date=datetime.date(2016,1,1))
+        self.assertEqual(bill.date, datetime.date(2016,1,1))
+
+        with freeze_time('2017-01-01'):
+            bill.validate()
+            self.assertEqual(bill.date, datetime.date(2017, 1, 1))
+            self.assertEqual(bill.number, '2017-01-000001')

+ 1 - 0
requirements.txt

@@ -14,3 +14,4 @@ django-localflavor==1.1
 feedparser
 six==1.10.0
 WeasyPrint==0.31
+freezegun==0.3.8