mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Add start date tot create cotis
This commit is contained in:
parent
05501c90d9
commit
e7a363866a
2 changed files with 30 additions and 3 deletions
|
@ -511,7 +511,7 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
)
|
)
|
||||||
return
|
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.
|
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,6 +522,15 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
if not hasattr(self, "cotisation") and self.type_cotisation:
|
if not hasattr(self, "cotisation") and self.type_cotisation:
|
||||||
cotisation = Cotisation(vente=self)
|
cotisation = Cotisation(vente=self)
|
||||||
cotisation.type_cotisation = self.type_cotisation
|
cotisation.type_cotisation = self.type_cotisation
|
||||||
|
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_start = invoice.date
|
||||||
cotisation.date_end = invoice.date
|
cotisation.date_end = invoice.date
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,24 @@ class VenteModelTests(TestCase):
|
||||||
self.assertEqual(end.month, expected_end.month)
|
self.assertEqual(end.month, expected_end.month)
|
||||||
self.assertEqual(end.year, expected_end.year)
|
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):
|
def tearDown(self):
|
||||||
self.f.delete()
|
self.f.delete()
|
||||||
self.user.delete()
|
self.user.delete()
|
||||||
|
|
Loading…
Reference in a new issue