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
|
||||
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue