Browse Source

Merge branch 'jd-auto-member-status' of FFDN/coin into master

jocelyn 6 years ago
parent
commit
6339fd94b8
2 changed files with 26 additions and 3 deletions
  1. 8 0
      coin/members/models.py
  2. 18 3
      coin/members/tests.py

+ 8 - 0
coin/members/models.py

@@ -461,6 +461,14 @@ class MembershipFee(models.Model):
         if self.start_date is not None and self.end_date is None:
             self.end_date = self.start_date + datetime.timedelta(364)
 
+    def save(self, *args, **kwargs):
+        ret = super(MembershipFee, self).save(*args, **kwargs)
+        today = datetime.date.today()
+        if self.start_date <= today and today <= self.end_date:
+            self.member.status = self.member.MEMBER_STATUS_MEMBER
+            self.member.save()
+        return ret
+
     def __unicode__(self):
         return '%s - %s - %i€' % (self.member, self.start_date, self.amount)
 

+ 18 - 3
coin/members/tests.py

@@ -2,17 +2,17 @@
 from __future__ import unicode_literals
 
 import os
-import logging
+
 import ldapdb
 from datetime import date
 from cStringIO import StringIO
 from dateutil.relativedelta import relativedelta
+from freezegun import freeze_time
 import unittest
 
 from django import db
 from django.conf import settings
-from django.test import TestCase, Client, override_settings
-from django.contrib.auth.models import User
+from django.test import TestCase, Client
 from django.core import mail, management
 from django.core.exceptions import ValidationError
 
@@ -359,6 +359,21 @@ class MemberTests(TestCase):
         # de cotisation
         self.assertEqual(member.is_paid_up(), True)
 
+    @freeze_time('2016-01-01')
+    def test_adding_running_fee_set_membership_status(self):
+        member = Member.objects.create(
+            first_name='a', last_name='b', username='c',
+            status=Member.MEMBER_STATUS_PENDING)
+
+        # Créé une cotisation passée
+        MembershipFee.objects.create(
+            member=member, amount=20,
+            start_date=date(2015, 12, 12),
+            end_date=date(2016, 12, 12))
+
+        member = Member.objects.get(pk=member.pk)
+        self.assertEqual(member.status, member.MEMBER_STATUS_MEMBER)
+
     def test_member_cant_be_created_without_names(self):
         """
         Test qu'un membre ne peut pas être créé sans "noms"