Commit 09bde1bf authored by Krophil's avatar Krophil

Merge branch 'cotiz' into 'master'

added 6 month free cotiz and changed compute_end

See merge request !156
parents bef10c0f 7a1b9bd4
Pipeline #1517 passed with stage
in 5 minutes and 54 seconds
This diff is collapsed.
......@@ -499,7 +499,7 @@ SITH_SUBSCRIPTIONS = {
'duration': 1,
},
'deux-mois-essai': {
'name': _('Two month for free'),
'name': _('Two months for free'),
'price': 0,
'duration': 0.33,
},
......@@ -507,6 +507,11 @@ SITH_SUBSCRIPTIONS = {
'name': _('Eurok\'s volunteer'),
'price': 5,
'duration': 0.1
},
'six-semaines-essai': {
'name': _('Six weeks for free'),
'price': 0,
'duration': 0.23,
}
# To be completed....
}
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-08-31 18:16
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('subscription', '0007_auto_20180706_1135'),
]
operations = [
migrations.AlterField(
model_name='subscription',
name='subscription_type',
field=models.CharField(choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('benevoles-euroks', "Eurok's volunteer"), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-mois-essai', 'Two month for free'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('six-semaines-essai', 'Six weeks for free'), ('un-semestre', 'One semester'), ('un-semestre-welcome', 'One semester Welcome Week')], max_length=255, verbose_name='subscription type'),
),
]
......@@ -31,6 +31,10 @@ from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.contrib.auth.forms import PasswordResetForm
from dateutil.relativedelta import relativedelta
import math
from core.models import User
from core.utils import get_start_of_semester
......@@ -172,14 +176,8 @@ class Subscription(models.Model):
if start is None:
start = Subscription.compute_start(duration=duration, user=user)
# This can certainly be simplified, but it works like this
try:
return start.replace(month=int(round((start.month - 1 + 6 * duration) % 12 + 1, 0)),
year=int(round(start.year + int(duration / 2) + (1 if int(start.month + 6 * duration) > 12 and (duration % 2 == 1 or duration < 1) else 0), 0)))
except ValueError as e: # This catches 29th of February errors
return start.replace(day=1, month=int(round((start.month + 6 * duration) % 12 + 1, 0)),
year=int(round(start.year + int(duration / 2) + (1 if int(start.month + 6 * duration) > 12 and (duration % 2 == 1 or duration < 1) else 0), 0)))
return start + relativedelta(months=round(6*duration),days=math.ceil((6*duration - round(6*duration)) * 30))
def can_be_edited_by(self, user):
return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_root
......
......@@ -92,7 +92,7 @@ class SubscriptionUnitTest(TestCase):
d = Subscription.compute_end(duration=0.33)
self.assertTrue(d == date(2015, 11, 18))
d = Subscription.compute_end(duration=0.67)
self.assertTrue(d == date(2016, 1, 18))
self.assertTrue(d == date(2016, 1, 19))
d = Subscription.compute_end(duration=0.5)
self.assertTrue(d == date(2015, 12, 18))
......@@ -135,7 +135,17 @@ class SubscriptionIntegrationTest(TestCase):
s.subscription_end = s.compute_end(duration=0.67,
start=s.subscription_start)
s.save()
self.assertTrue(s.subscription_end == date(2017, 12, 29))
self.assertTrue(s.subscription_end == date(2017, 12, 30))
def test_duration_six_weeks(self):
s = Subscription(member=User.objects.filter(pk=self.user.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = date(2018, 9, 1)
s.subscription_end = s.compute_end(duration=0.23,
start=s.subscription_start)
s.save()
self.assertTrue(s.subscription_end == date(2018, 10, 13))
@mock.patch('subscription.models.date', FakeDate)
def test_dates_sliding_with_subscribed_user(self):
......@@ -150,6 +160,8 @@ class SubscriptionIntegrationTest(TestCase):
date_mock_today(2016, 8, 25)
d = Subscription.compute_end(duration=settings.SITH_SUBSCRIPTIONS['deux-semestres']['duration'],
user=user)
self.assertTrue(d == date(2017, 8, 29))
@mock.patch('subscription.models.date', FakeDate)
......
Markdown is supported
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