From 69bb38297f58e1084fa30f94a768f6305f09d46d Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 4 Oct 2021 18:15:07 +0200 Subject: [PATCH] Fix membership dates for new memberships, fix tests Signed-off-by: Yohann D'ANELLO --- apps/member/migrations/0003_create_bde_and_kfet.py | 8 ++++---- apps/member/models.py | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/member/migrations/0003_create_bde_and_kfet.py b/apps/member/migrations/0003_create_bde_and_kfet.py index d2f80c2d..2dbcd9dc 100644 --- a/apps/member/migrations/0003_create_bde_and_kfet.py +++ b/apps/member/migrations/0003_create_bde_and_kfet.py @@ -19,8 +19,8 @@ def create_bde_and_kfet(apps, schema_editor): membership_fee_paid=500, membership_fee_unpaid=500, membership_duration=396, - membership_start="2020-08-01", - membership_end="2021-09-30", + membership_start="2021-08-01", + membership_end="2022-09-30", ) Club.objects.get_or_create( id=2, @@ -31,8 +31,8 @@ def create_bde_and_kfet(apps, schema_editor): membership_fee_paid=3500, membership_fee_unpaid=3500, membership_duration=396, - membership_start="2020-08-01", - membership_end="2021-09-30", + membership_start="2021-08-01", + membership_end="2022-09-30", ) NoteClub.objects.get_or_create( diff --git a/apps/member/models.py b/apps/member/models.py index 9bb4ecf0..9cb0cbde 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -413,6 +413,12 @@ class Membership(models.Model): """ Calculate fee and end date before saving the membership and creating the transaction if needed. """ + # Ensure that club membership dates are valid + old_membership_start = self.club.membership_start + self.club.update_membership_dates() + if self.club.membership_start != old_membership_start: + self.club.save() + created = not self.pk if not created: for role in self.roles.all():