Merge branch 'cotiz' into 'master'

added 6 month free cotiz and changed compute_end

See merge request ae/Sith!156
This commit is contained in:
Pierre Brunet 2018-09-01 18:42:13 +02:00
commit 09bde1bfdf
6 changed files with 138 additions and 98 deletions

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-07-06 11:42+0200\n" "POT-Creation-Date: 2018-09-01 17:42+0200\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia <skia@libskia.so>\n" "Last-Translator: Skia <skia@libskia.so>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@ -141,7 +141,7 @@ msgid "comment"
msgstr "commentaire" msgstr "commentaire"
#: accounting/models.py:258 counter/models.py:302 counter/models.py:352 #: accounting/models.py:258 counter/models.py:302 counter/models.py:352
#: subscription/models.py:55 #: subscription/models.py:59
msgid "payment method" msgid "payment method"
msgstr "méthode de paiement" msgstr "méthode de paiement"
@ -218,7 +218,7 @@ msgstr "Compte"
msgid "Company" msgid "Company"
msgstr "Entreprise" msgstr "Entreprise"
#: accounting/models.py:269 sith/settings.py:377 #: accounting/models.py:269 sith/settings.py:378
#: stock/templates/stock/shopping_list_items.jinja:37 #: stock/templates/stock/shopping_list_items.jinja:37
msgid "Other" msgid "Other"
msgstr "Autre" msgstr "Autre"
@ -1047,7 +1047,7 @@ msgid "Mark as old"
msgstr "Marquer comme ancien" msgstr "Marquer comme ancien"
#: club/templates/club/club_members.jinja:30 #: club/templates/club/club_members.jinja:30
#: core/templates/core/file_detail.jinja:19 core/views/forms.py:253 #: core/templates/core/file_detail.jinja:19 core/views/forms.py:254
#: launderette/views.py:182 trombi/templates/trombi/detail.jinja:19 #: launderette/views.py:182 trombi/templates/trombi/detail.jinja:19
msgid "Add" msgid "Add"
msgstr "Ajouter" msgstr "Ajouter"
@ -1276,7 +1276,7 @@ msgstr "Liste d'affiches"
msgid "Props" msgid "Props"
msgstr "Propriétés" msgstr "Propriétés"
#: club/views.py:251 core/views/forms.py:254 counter/views.py:91 #: club/views.py:251 core/views/forms.py:255 counter/views.py:91
#: trombi/views.py:124 #: trombi/views.py:124
msgid "Select user" msgid "Select user"
msgstr "Choisir un utilisateur" msgstr "Choisir un utilisateur"
@ -3311,7 +3311,7 @@ msgstr "Ajouter un nouveau dossier"
msgid "Error creating folder %(folder_name)s: %(msg)s" msgid "Error creating folder %(folder_name)s: %(msg)s"
msgstr "Erreur de création du dossier %(folder_name)s : %(msg)s" msgstr "Erreur de création du dossier %(folder_name)s : %(msg)s"
#: core/views/files.py:97 core/views/forms.py:228 core/views/forms.py:232 #: core/views/files.py:97 core/views/forms.py:229 core/views/forms.py:233
#: sas/views.py:70 #: sas/views.py:70
#, python-format #, python-format
msgid "Error uploading file %(file_name)s: %(msg)s" msgid "Error uploading file %(file_name)s: %(msg)s"
@ -3337,7 +3337,7 @@ msgstr "Choisir un utilisateur"
msgid "Username, email, or account number" msgid "Username, email, or account number"
msgstr "Nom d'utilisateur, email, ou numéro de compte AE" msgstr "Nom d'utilisateur, email, ou numéro de compte AE"
#: core/views/forms.py:186 #: core/views/forms.py:187
msgid "" msgid ""
"Profile: you need to be visible on the picture, in order to be recognized (e." "Profile: you need to be visible on the picture, in order to be recognized (e."
"g. by the barmen)" "g. by the barmen)"
@ -3345,32 +3345,32 @@ msgstr ""
"Photo de profil: vous devez être visible sur la photo afin d'être reconnu " "Photo de profil: vous devez être visible sur la photo afin d'être reconnu "
"(par exemple par les barmen)" "(par exemple par les barmen)"
#: core/views/forms.py:187 #: core/views/forms.py:188
msgid "Avatar: used on the forum" msgid "Avatar: used on the forum"
msgstr "Avatar : utilisé sur le forum" msgstr "Avatar : utilisé sur le forum"
#: core/views/forms.py:188 #: core/views/forms.py:189
msgid "Scrub: let other know how your scrub looks like!" msgid "Scrub: let other know how your scrub looks like!"
msgstr "Blouse : montrez aux autres à quoi ressemble votre blouse !" msgstr "Blouse : montrez aux autres à quoi ressemble votre blouse !"
#: core/views/forms.py:233 #: core/views/forms.py:234
msgid "Bad image format, only jpeg, png, and gif are accepted" msgid "Bad image format, only jpeg, png, and gif are accepted"
msgstr "Mauvais format d'image, seuls les jpeg, png, et gif sont acceptés" msgstr "Mauvais format d'image, seuls les jpeg, png, et gif sont acceptés"
#: core/views/forms.py:253 #: core/views/forms.py:254
msgid "Godfather" msgid "Godfather"
msgstr "Parrain" msgstr "Parrain"
#: core/views/forms.py:253 #: core/views/forms.py:254
msgid "Godchild" msgid "Godchild"
msgstr "Fillot" msgstr "Fillot"
#: core/views/forms.py:264 core/views/forms.py:277 election/models.py:22 #: core/views/forms.py:265 core/views/forms.py:278 election/models.py:22
#: election/views.py:128 #: election/views.py:128
msgid "edit groups" msgid "edit groups"
msgstr "groupe d'édition" msgstr "groupe d'édition"
#: core/views/forms.py:265 core/views/forms.py:278 election/models.py:26 #: core/views/forms.py:266 core/views/forms.py:279 election/models.py:26
#: election/views.py:129 #: election/views.py:129
msgid "view groups" msgid "view groups"
msgstr "groupe de vue" msgstr "groupe de vue"
@ -3478,7 +3478,7 @@ msgstr "Bureau"
#: eboutic/templates/eboutic/eboutic_main.jinja:24 #: eboutic/templates/eboutic/eboutic_main.jinja:24
#: eboutic/templates/eboutic/eboutic_makecommand.jinja:8 #: eboutic/templates/eboutic/eboutic_makecommand.jinja:8
#: eboutic/templates/eboutic/eboutic_payment_result.jinja:4 #: eboutic/templates/eboutic/eboutic_payment_result.jinja:4
#: sith/settings.py:376 sith/settings.py:384 #: sith/settings.py:377 sith/settings.py:385
msgid "Eboutic" msgid "Eboutic"
msgstr "Eboutic" msgstr "Eboutic"
@ -3519,8 +3519,8 @@ msgstr "quantité"
msgid "Sith account" msgid "Sith account"
msgstr "Compte utilisateur" msgstr "Compte utilisateur"
#: counter/models.py:353 sith/settings.py:369 sith/settings.py:374 #: counter/models.py:353 sith/settings.py:370 sith/settings.py:375
#: sith/settings.py:396 #: sith/settings.py:397
msgid "Credit card" msgid "Credit card"
msgstr "Carte bancaire" msgstr "Carte bancaire"
@ -4412,12 +4412,12 @@ msgid "Washing and drying"
msgstr "Lavage et séchage" msgstr "Lavage et séchage"
#: launderette/templates/launderette/launderette_book.jinja:27 #: launderette/templates/launderette/launderette_book.jinja:27
#: sith/settings.py:564 #: sith/settings.py:570
msgid "Washing" msgid "Washing"
msgstr "Lavage" msgstr "Lavage"
#: launderette/templates/launderette/launderette_book.jinja:31 #: launderette/templates/launderette/launderette_book.jinja:31
#: sith/settings.py:564 #: sith/settings.py:570
msgid "Drying" msgid "Drying"
msgstr "Séchage" msgstr "Séchage"
@ -4592,243 +4592,247 @@ msgstr "Erreur de création de l'album %(album)s : %(msg)s"
msgid "Add user" msgid "Add user"
msgstr "Ajouter une personne" msgstr "Ajouter une personne"
#: sith/settings.py:213 #: sith/settings.py:214
msgid "English" msgid "English"
msgstr "Anglais" msgstr "Anglais"
#: sith/settings.py:214 #: sith/settings.py:215
msgid "French" msgid "French"
msgstr "Français" msgstr "Français"
#: sith/settings.py:350 #: sith/settings.py:351
msgid "TC" msgid "TC"
msgstr "TC" msgstr "TC"
#: sith/settings.py:351 #: sith/settings.py:352
msgid "IMSI" msgid "IMSI"
msgstr "IMSI" msgstr "IMSI"
#: sith/settings.py:352 #: sith/settings.py:353
msgid "IMAP" msgid "IMAP"
msgstr "IMAP" msgstr "IMAP"
#: sith/settings.py:353 #: sith/settings.py:354
msgid "INFO" msgid "INFO"
msgstr "INFO" msgstr "INFO"
#: sith/settings.py:354 #: sith/settings.py:355
msgid "GI" msgid "GI"
msgstr "GI" msgstr "GI"
#: sith/settings.py:355 #: sith/settings.py:356
msgid "E" msgid "E"
msgstr "E" msgstr "E"
#: sith/settings.py:356 #: sith/settings.py:357
msgid "EE" msgid "EE"
msgstr "EE" msgstr "EE"
#: sith/settings.py:357 #: sith/settings.py:358
msgid "GESC" msgid "GESC"
msgstr "GESC" msgstr "GESC"
#: sith/settings.py:358 #: sith/settings.py:359
msgid "GMC" msgid "GMC"
msgstr "GMC" msgstr "GMC"
#: sith/settings.py:359 #: sith/settings.py:360
msgid "MC" msgid "MC"
msgstr "MC" msgstr "MC"
#: sith/settings.py:360 #: sith/settings.py:361
msgid "EDIM" msgid "EDIM"
msgstr "EDIM" msgstr "EDIM"
#: sith/settings.py:361 #: sith/settings.py:362
msgid "Humanities" msgid "Humanities"
msgstr "Humanités" msgstr "Humanités"
#: sith/settings.py:362 #: sith/settings.py:363
msgid "N/A" msgid "N/A"
msgstr "N/A" msgstr "N/A"
#: sith/settings.py:366 sith/settings.py:373 sith/settings.py:394 #: sith/settings.py:367 sith/settings.py:374 sith/settings.py:395
msgid "Check" msgid "Check"
msgstr "Chèque" msgstr "Chèque"
#: sith/settings.py:367 sith/settings.py:375 sith/settings.py:395 #: sith/settings.py:368 sith/settings.py:376 sith/settings.py:396
msgid "Cash" msgid "Cash"
msgstr "Espèces" msgstr "Espèces"
#: sith/settings.py:368 #: sith/settings.py:369
msgid "Transfert" msgid "Transfert"
msgstr "Virement" msgstr "Virement"
#: sith/settings.py:381 #: sith/settings.py:382
msgid "Belfort" msgid "Belfort"
msgstr "Belfort" msgstr "Belfort"
#: sith/settings.py:382 #: sith/settings.py:383
msgid "Sevenans" msgid "Sevenans"
msgstr "Sevenans" msgstr "Sevenans"
#: sith/settings.py:383 #: sith/settings.py:384
msgid "Montbéliard" msgid "Montbéliard"
msgstr "Montbéliard" msgstr "Montbéliard"
#: sith/settings.py:441 #: sith/settings.py:442
msgid "One semester" msgid "One semester"
msgstr "Un semestre, 15 €" msgstr "Un semestre, 15 €"
#: sith/settings.py:446 #: sith/settings.py:447
msgid "Two semesters" msgid "Two semesters"
msgstr "Deux semestres, 28 €" msgstr "Deux semestres, 28 €"
#: sith/settings.py:451 #: sith/settings.py:452
msgid "Common core cursus" msgid "Common core cursus"
msgstr "Cursus tronc commun, 45 €" msgstr "Cursus tronc commun, 45 €"
#: sith/settings.py:456 #: sith/settings.py:457
msgid "Branch cursus" msgid "Branch cursus"
msgstr "Cursus branche, 45 €" msgstr "Cursus branche, 45 €"
#: sith/settings.py:461 #: sith/settings.py:462
msgid "Alternating cursus" msgid "Alternating cursus"
msgstr "Cursus alternant, 30 €" msgstr "Cursus alternant, 30 €"
#: sith/settings.py:466 #: sith/settings.py:467
msgid "Honorary member" msgid "Honorary member"
msgstr "Membre honoraire, 0 €" msgstr "Membre honoraire, 0 €"
#: sith/settings.py:471 #: sith/settings.py:472
msgid "Assidu member" msgid "Assidu member"
msgstr "Membre d'Assidu, 0 €" msgstr "Membre d'Assidu, 0 €"
#: sith/settings.py:476 #: sith/settings.py:477
msgid "Amicale/DOCEO member" msgid "Amicale/DOCEO member"
msgstr "Membre de l'Amicale/DOCEO, 0 €" msgstr "Membre de l'Amicale/DOCEO, 0 €"
#: sith/settings.py:481 #: sith/settings.py:482
msgid "UT network member" msgid "UT network member"
msgstr "Cotisant du réseau UT, 0 €" msgstr "Cotisant du réseau UT, 0 €"
#: sith/settings.py:486 #: sith/settings.py:487
msgid "CROUS member" msgid "CROUS member"
msgstr "Membres du CROUS, 0 €" msgstr "Membres du CROUS, 0 €"
#: sith/settings.py:491 #: sith/settings.py:492
msgid "Sbarro/ESTA member" msgid "Sbarro/ESTA member"
msgstr "Membre de Sbarro ou de l'ESTA, 15 €" msgstr "Membre de Sbarro ou de l'ESTA, 15 €"
#: sith/settings.py:496 #: sith/settings.py:497
msgid "One semester Welcome Week" msgid "One semester Welcome Week"
msgstr "Un semestre Welcome Week" msgstr "Un semestre Welcome Week"
#: sith/settings.py:501 #: sith/settings.py:502
msgid "Two month for free" msgid "Two months for free"
msgstr "Deux mois gratuits" msgstr "Deux mois gratuits"
#: sith/settings.py:506 #: sith/settings.py:507
msgid "Eurok's volunteer" msgid "Eurok's volunteer"
msgstr "Bénévole Eurockéennes" msgstr "Bénévole Eurockéennes"
#: sith/settings.py:528 #: sith/settings.py:512
msgid "Six weeks for free"
msgstr "6 semaines gratuites"
#: sith/settings.py:534
msgid "President" msgid "President"
msgstr "Président" msgstr "Président"
#: sith/settings.py:529 #: sith/settings.py:535
msgid "Vice-President" msgid "Vice-President"
msgstr "Vice-Président" msgstr "Vice-Président"
#: sith/settings.py:530 #: sith/settings.py:536
msgid "Treasurer" msgid "Treasurer"
msgstr "Trésorier" msgstr "Trésorier"
#: sith/settings.py:531 #: sith/settings.py:537
msgid "Communication supervisor" msgid "Communication supervisor"
msgstr "Responsable communication" msgstr "Responsable communication"
#: sith/settings.py:532 #: sith/settings.py:538
msgid "Secretary" msgid "Secretary"
msgstr "Secrétaire" msgstr "Secrétaire"
#: sith/settings.py:533 #: sith/settings.py:539
msgid "IT supervisor" msgid "IT supervisor"
msgstr "Responsable info" msgstr "Responsable info"
#: sith/settings.py:534 #: sith/settings.py:540
msgid "Board member" msgid "Board member"
msgstr "Membre du bureau" msgstr "Membre du bureau"
#: sith/settings.py:535 #: sith/settings.py:541
msgid "Active member" msgid "Active member"
msgstr "Membre actif" msgstr "Membre actif"
#: sith/settings.py:536 #: sith/settings.py:542
msgid "Curious" msgid "Curious"
msgstr "Curieux" msgstr "Curieux"
#: sith/settings.py:571 #: sith/settings.py:577
msgid "A new poster needs to be moderated" msgid "A new poster needs to be moderated"
msgstr "Une nouvelle affiche a besoin d'être modérée" msgstr "Une nouvelle affiche a besoin d'être modérée"
#: sith/settings.py:572 #: sith/settings.py:578
msgid "A new mailing list needs to be moderated" msgid "A new mailing list needs to be moderated"
msgstr "Une nouvelle mailing list a besoin d'être modérée" msgstr "Une nouvelle mailing list a besoin d'être modérée"
#: sith/settings.py:573 #: sith/settings.py:579
#, python-format #, python-format
msgid "There are %s fresh news to be moderated" msgid "There are %s fresh news to be moderated"
msgstr "Il y a %s nouvelles toutes fraîches à modérer" msgstr "Il y a %s nouvelles toutes fraîches à modérer"
#: sith/settings.py:574 #: sith/settings.py:580
msgid "New files to be moderated" msgid "New files to be moderated"
msgstr "Nouveaux fichiers à modérer" msgstr "Nouveaux fichiers à modérer"
#: sith/settings.py:575 #: sith/settings.py:581
#, python-format #, python-format
msgid "There are %s pictures to be moderated in the SAS" msgid "There are %s pictures to be moderated in the SAS"
msgstr "Il y a %s photos à modérer dans le SAS" msgstr "Il y a %s photos à modérer dans le SAS"
#: sith/settings.py:576 #: sith/settings.py:582
msgid "You've been identified on some pictures" msgid "You've been identified on some pictures"
msgstr "Vous avez été identifié sur des photos" msgstr "Vous avez été identifié sur des photos"
#: sith/settings.py:577 #: sith/settings.py:583
#, python-format #, python-format
msgid "You just refilled of %s €" msgid "You just refilled of %s €"
msgstr "Vous avez rechargé votre compte de %s€" msgstr "Vous avez rechargé votre compte de %s€"
#: sith/settings.py:578 #: sith/settings.py:584
#, python-format #, python-format
msgid "You just bought %s" msgid "You just bought %s"
msgstr "Vous avez acheté %s" msgstr "Vous avez acheté %s"
#: sith/settings.py:579 #: sith/settings.py:585
msgid "You have a notification" msgid "You have a notification"
msgstr "Vous avez une notification" msgstr "Vous avez une notification"
#: sith/settings.py:591 #: sith/settings.py:597
msgid "Success!" msgid "Success!"
msgstr "Succès !" msgstr "Succès !"
#: sith/settings.py:592 #: sith/settings.py:598
msgid "Fail!" msgid "Fail!"
msgstr "Échec !" msgstr "Échec !"
#: sith/settings.py:593 #: sith/settings.py:599
msgid "You successfully posted an article in the Weekmail" msgid "You successfully posted an article in the Weekmail"
msgstr "Article posté avec succès dans le Weekmail" msgstr "Article posté avec succès dans le Weekmail"
#: sith/settings.py:594 #: sith/settings.py:600
msgid "You successfully edited an article in the Weekmail" msgid "You successfully edited an article in the Weekmail"
msgstr "Article édité avec succès dans le Weekmail" msgstr "Article édité avec succès dans le Weekmail"
#: sith/settings.py:595 #: sith/settings.py:601
msgid "You successfully sent the Weekmail" msgid "You successfully sent the Weekmail"
msgstr "Weekmail envoyé avec succès" msgstr "Weekmail envoyé avec succès"
#: sith/settings.py:604 #: sith/settings.py:610
msgid "AE tee-shirt" msgid "AE tee-shirt"
msgstr "Tee-shirt AE" msgstr "Tee-shirt AE"
@ -5031,35 +5035,35 @@ msgstr " demandé"
msgid "%(effective_quantity)s left" msgid "%(effective_quantity)s left"
msgstr "%(effective_quantity)s restant" msgstr "%(effective_quantity)s restant"
#: subscription/models.py:40 #: subscription/models.py:44
msgid "Bad subscription type" msgid "Bad subscription type"
msgstr "Mauvais type de cotisation" msgstr "Mauvais type de cotisation"
#: subscription/models.py:45 #: subscription/models.py:49
msgid "Bad payment method" msgid "Bad payment method"
msgstr "Mauvais type de paiement" msgstr "Mauvais type de paiement"
#: subscription/models.py:50 #: subscription/models.py:54
msgid "subscription type" msgid "subscription type"
msgstr "type d'inscription" msgstr "type d'inscription"
#: subscription/models.py:53 #: subscription/models.py:57
msgid "subscription start" msgid "subscription start"
msgstr "début de la cotisation" msgstr "début de la cotisation"
#: subscription/models.py:54 #: subscription/models.py:58
msgid "subscription end" msgid "subscription end"
msgstr "fin de la cotisation" msgstr "fin de la cotisation"
#: subscription/models.py:59 #: subscription/models.py:63
msgid "location" msgid "location"
msgstr "lieu" msgstr "lieu"
#: subscription/models.py:68 #: subscription/models.py:72
msgid "You can not subscribe many time for the same period" msgid "You can not subscribe many time for the same period"
msgstr "Vous ne pouvez pas cotiser plusieurs fois pour la même période" msgstr "Vous ne pouvez pas cotiser plusieurs fois pour la même période"
#: subscription/models.py:72 #: subscription/models.py:76
msgid "Subscription error" msgid "Subscription error"
msgstr "Erreur de cotisation" msgstr "Erreur de cotisation"

View File

@ -15,5 +15,6 @@ django-debug-toolbar
libsass libsass
django-ordered-model django-ordered-model
django-simple-captcha django-simple-captcha
python-dateutil
pygraphviz pygraphviz
# mysqlclient # mysqlclient

View File

@ -499,7 +499,7 @@ SITH_SUBSCRIPTIONS = {
'duration': 1, 'duration': 1,
}, },
'deux-mois-essai': { 'deux-mois-essai': {
'name': _('Two month for free'), 'name': _('Two months for free'),
'price': 0, 'price': 0,
'duration': 0.33, 'duration': 0.33,
}, },
@ -507,6 +507,11 @@ SITH_SUBSCRIPTIONS = {
'name': _('Eurok\'s volunteer'), 'name': _('Eurok\'s volunteer'),
'price': 5, 'price': 5,
'duration': 0.1 'duration': 0.1
},
'six-semaines-essai': {
'name': _('Six weeks for free'),
'price': 0,
'duration': 0.23,
} }
# To be completed.... # To be completed....
} }

View File

@ -0,0 +1,20 @@
# -*- 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'),
),
]

View File

@ -31,6 +31,10 @@ from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.forms import PasswordResetForm from django.contrib.auth.forms import PasswordResetForm
from dateutil.relativedelta import relativedelta
import math
from core.models import User from core.models import User
from core.utils import get_start_of_semester from core.utils import get_start_of_semester
@ -172,13 +176,7 @@ class Subscription(models.Model):
if start is None: if start is None:
start = Subscription.compute_start(duration=duration, user=user) start = Subscription.compute_start(duration=duration, user=user)
# This can certainly be simplified, but it works like this return start + relativedelta(months=round(6*duration),days=math.ceil((6*duration - round(6*duration)) * 30))
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)))
def can_be_edited_by(self, user): def can_be_edited_by(self, user):
return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_root return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_root

View File

@ -92,7 +92,7 @@ class SubscriptionUnitTest(TestCase):
d = Subscription.compute_end(duration=0.33) d = Subscription.compute_end(duration=0.33)
self.assertTrue(d == date(2015, 11, 18)) self.assertTrue(d == date(2015, 11, 18))
d = Subscription.compute_end(duration=0.67) 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) d = Subscription.compute_end(duration=0.5)
self.assertTrue(d == date(2015, 12, 18)) self.assertTrue(d == date(2015, 12, 18))
@ -135,7 +135,17 @@ class SubscriptionIntegrationTest(TestCase):
s.subscription_end = s.compute_end(duration=0.67, s.subscription_end = s.compute_end(duration=0.67,
start=s.subscription_start) start=s.subscription_start)
s.save() 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) @mock.patch('subscription.models.date', FakeDate)
def test_dates_sliding_with_subscribed_user(self): def test_dates_sliding_with_subscribed_user(self):
@ -150,6 +160,8 @@ class SubscriptionIntegrationTest(TestCase):
date_mock_today(2016, 8, 25) date_mock_today(2016, 8, 25)
d = Subscription.compute_end(duration=settings.SITH_SUBSCRIPTIONS['deux-semestres']['duration'], d = Subscription.compute_end(duration=settings.SITH_SUBSCRIPTIONS['deux-semestres']['duration'],
user=user) user=user)
self.assertTrue(d == date(2017, 8, 29)) self.assertTrue(d == date(2017, 8, 29))
@mock.patch('subscription.models.date', FakeDate) @mock.patch('subscription.models.date', FakeDate)