Commit e7a36386 authored by Yoann Pietri's avatar Yoann Pietri Committed by root

Add start date tot create cotis

parent 05501c90
Pipeline #2341 passed with stage
in 3 minutes and 52 seconds
......@@ -511,7 +511,7 @@ class Vente(RevMixin, AclMixin, models.Model):
)
return
def create_cotis(self):
def create_cotis(self, date_start=False):
"""
Creates a cotisation without initializing the dates (start and end ar set to self.facture.facture.date) and without saving it. You should use Facture.reorder_purchases to set the right dates.
"""
......@@ -522,8 +522,17 @@ class Vente(RevMixin, AclMixin, models.Model):
if not hasattr(self, "cotisation") and self.type_cotisation:
cotisation = Cotisation(vente=self)
cotisation.type_cotisation = self.type_cotisation
cotisation.date_start = invoice.date
cotisation.date_end = invoice.date
if date_start:
cotisation.date_start = date_start
cotisation.date_end = cotisation.date_start + relativedelta(
months=(self.duration or 0) * self.number,
days=(self.duration_days or 0) * self.number,
)
self.save()
cotisation.save()
else:
cotisation.date_start = invoice.date
cotisation.date_end = invoice.date
def save(self, *args, **kwargs):
"""
......
......@@ -79,6 +79,24 @@ class VenteModelTests(TestCase):
self.assertEqual(end.month, expected_end.month)
self.assertEqual(end.year, expected_end.year)
def test_date_start_cotisation(self):
"""
It should be possible to add a cotisation with a specific start date
"""
v = Vente(
facture=self.f,
number=1,
name="Test purchase",
duration=0,
duration_days=1,
type_cotisation = 'All',
prix=0
)
v.create_cotis(date_start=timezone.make_aware(datetime.datetime(1998, 10, 16)))
v.save()
self.assertEqual(v.cotisation.date_end, timezone.make_aware(datetime.datetime(1998, 10, 17)))
def tearDown(self):
self.f.delete()
self.user.delete()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment