|
@@ -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')
|