Commit d8eb6af8 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

- Do not create a new object if `since` is today.

- Update the value of _was_chair in `save`, since `__init__` is not called when you do not get a fresh object from the db.
parent af01bf53
......@@ -222,7 +222,7 @@ class CommitteeMembership(models.Model):
# If the chair changed and we're still active, we create a new instance
# Inactive instances should be handled manually
if (self.pk is not None and self._was_chair != self.chair and
not self.until):
not self.until and self.since != timezone.now().date()):
logger.info("Creating new membership instance")
self.until = timezone.now().date() - datetime.timedelta(days=1)
super().save(*args, **kwargs)
......@@ -230,6 +230,8 @@ class CommitteeMembership(models.Model):
# Set since date to older expiration:
self.since = timezone.now().date()
self.until = None
self._was_chair = self.chair
super().save(*args, **kwargs)
def delete(self, *args, **kwargs):
......
......@@ -96,6 +96,8 @@ class CommitteeMembersChairTest(TestCase):
self.testuser = Member.objects.get(pk=1)
self.testuser2 = Member.objects.get(pk=2)
self.m1 = CommitteeMembership(committee=self.testcie,
since=timezone.now().date().replace(
year=1900),
member=self.testuser,
chair=True)
self.m1.full_clean()
......
Supports Markdown
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