2019-11-03 23:25:29 +00:00
|
|
|
import datetime
|
2021-02-10 10:06:09 +00:00
|
|
|
|
2019-11-03 23:25:29 +00:00
|
|
|
from dateutil.relativedelta import relativedelta
|
2021-02-10 10:06:09 +00:00
|
|
|
from django.contrib.auth.models import Permission
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.urls import reverse
|
2019-11-03 23:25:29 +00:00
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from users.models import Adherent
|
2021-02-10 10:06:09 +00:00
|
|
|
|
|
|
|
from .models import Article, Cotisation, Facture, Paiement, Vente
|
2019-11-03 23:25:29 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2019-11-03 23:25:29 +00:00
|
|
|
class NewFactureTests(TestCase):
|
2024-02-29 10:07:26 +00:00
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
cls.paiement = Paiement.objects.create(moyen="test payment")
|
|
|
|
cls.article_one_day = Article.objects.create(
|
2019-11-03 23:25:29 +00:00
|
|
|
name="One day",
|
|
|
|
prix=0,
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
duration_connection=0,
|
|
|
|
duration_days_connection=1,
|
|
|
|
duration_membership=0,
|
|
|
|
duration_days_membership=1,
|
2019-11-04 16:55:03 +00:00
|
|
|
available_for_everyone=True,
|
2019-11-03 23:25:29 +00:00
|
|
|
)
|
2024-02-29 10:07:26 +00:00
|
|
|
cls.article_one_month = Article.objects.create(
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
name="One mounth",
|
2019-11-03 23:25:29 +00:00
|
|
|
prix=0,
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
duration_connection=1,
|
|
|
|
duration_days_connection=0,
|
|
|
|
duration_membership=1,
|
|
|
|
duration_days_membership=0,
|
2019-11-04 16:55:03 +00:00
|
|
|
available_for_everyone=True,
|
2019-11-03 23:25:29 +00:00
|
|
|
)
|
2024-02-29 10:07:26 +00:00
|
|
|
cls.article_one_month_and_one_week = Article.objects.create(
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
name="One mounth and one week",
|
2019-11-03 23:25:29 +00:00
|
|
|
prix=0,
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
duration_connection=1,
|
|
|
|
duration_days_connection=7,
|
|
|
|
duration_membership=1,
|
|
|
|
duration_days_membership=7,
|
2019-11-04 16:55:03 +00:00
|
|
|
available_for_everyone=True,
|
2019-11-03 23:25:29 +00:00
|
|
|
)
|
2024-02-29 10:07:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.user.facture_set.all().delete()
|
|
|
|
self.user.delete()
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.user = Adherent.objects.create(pseudo="testUser", email="test@example.org")
|
|
|
|
self.user.set_password("plopiplop")
|
|
|
|
self.user.user_permissions.set(
|
|
|
|
[
|
|
|
|
Permission.objects.get_by_natural_key(
|
|
|
|
"add_facture", "cotisations", "facture"
|
|
|
|
),
|
|
|
|
Permission.objects.get_by_natural_key(
|
|
|
|
"use_every_payment", "cotisations", "paiement"
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
self.user.save()
|
2019-11-04 16:55:03 +00:00
|
|
|
self.client.login(username="testUser", password="plopiplop")
|
2019-11-03 23:25:29 +00:00
|
|
|
|
|
|
|
def test_invoice_with_one_day(self):
|
|
|
|
data = {
|
|
|
|
"Facture-paiement": self.paiement.pk,
|
|
|
|
"form-TOTAL_FORMS": 1,
|
|
|
|
"form-INITIAL_FORMS": 0,
|
|
|
|
"form-MIN_NUM_FORMS": 0,
|
|
|
|
"form-MAX_NUM_FORMS": 1000,
|
2024-02-29 10:07:26 +00:00
|
|
|
"form-0-article": self.article_one_day.pk,
|
2019-11-03 23:25:29 +00:00
|
|
|
"form-0-quantity": 1,
|
|
|
|
}
|
|
|
|
date = timezone.now()
|
2019-11-04 16:55:03 +00:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("cotisations:new-facture", kwargs={"userid": self.user.pk}), data
|
2019-11-03 23:25:29 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
self.assertEqual(response.url, "/users/profil/%d" % self.user.pk)
|
2019-11-03 23:25:29 +00:00
|
|
|
self.assertAlmostEqual(
|
|
|
|
self.user.end_connexion() - date,
|
|
|
|
datetime.timedelta(days=1),
|
2019-11-04 16:55:03 +00:00
|
|
|
delta=datetime.timedelta(seconds=1),
|
2019-11-03 23:25:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_invoice_with_one_month(self):
|
|
|
|
data = {
|
|
|
|
"Facture-paiement": self.paiement.pk,
|
|
|
|
"form-TOTAL_FORMS": 1,
|
|
|
|
"form-INITIAL_FORMS": 0,
|
|
|
|
"form-MIN_NUM_FORMS": 0,
|
|
|
|
"form-MAX_NUM_FORMS": 1000,
|
2024-02-29 10:07:26 +00:00
|
|
|
"form-0-article": self.article_one_month.pk,
|
2019-11-03 23:25:29 +00:00
|
|
|
"form-0-quantity": 1,
|
|
|
|
}
|
|
|
|
date = timezone.now()
|
2019-11-04 16:55:03 +00:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("cotisations:new-facture", kwargs={"userid": self.user.pk}), data
|
2019-11-03 23:25:29 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
self.assertEqual(response.url, "/users/profil/%d" % self.user.pk)
|
2019-11-03 23:25:29 +00:00
|
|
|
delta = relativedelta(self.user.end_connexion(), date)
|
2019-11-04 16:55:03 +00:00
|
|
|
delta.microseconds = 0
|
|
|
|
self.assertEqual(delta, relativedelta(months=1))
|
2019-11-03 23:25:29 +00:00
|
|
|
|
|
|
|
def test_invoice_with_one_month_and_one_week(self):
|
|
|
|
data = {
|
|
|
|
"Facture-paiement": self.paiement.pk,
|
|
|
|
"form-TOTAL_FORMS": 2,
|
|
|
|
"form-INITIAL_FORMS": 0,
|
|
|
|
"form-MIN_NUM_FORMS": 0,
|
|
|
|
"form-MAX_NUM_FORMS": 1000,
|
2024-02-29 10:07:26 +00:00
|
|
|
"form-0-article": self.article_one_day.pk,
|
2019-11-03 23:25:29 +00:00
|
|
|
"form-0-quantity": 7,
|
2024-02-29 10:07:26 +00:00
|
|
|
"form-1-article": self.article_one_month.pk,
|
2019-11-03 23:25:29 +00:00
|
|
|
"form-1-quantity": 1,
|
|
|
|
}
|
|
|
|
date = timezone.now()
|
2019-11-04 16:55:03 +00:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("cotisations:new-facture", kwargs={"userid": self.user.pk}), data
|
2019-11-03 23:25:29 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
self.assertEqual(response.url, "/users/profil/%d" % self.user.pk)
|
2019-11-03 23:25:29 +00:00
|
|
|
invoice = self.user.facture_set.first()
|
|
|
|
delta = relativedelta(self.user.end_connexion(), date)
|
2019-11-04 16:55:03 +00:00
|
|
|
delta.microseconds = 0
|
|
|
|
self.assertEqual(delta, relativedelta(months=1, days=7))
|
2019-11-03 23:25:29 +00:00
|
|
|
|
|
|
|
def test_several_articles_creates_several_purchases(self):
|
|
|
|
data = {
|
|
|
|
"Facture-paiement": self.paiement.pk,
|
|
|
|
"form-TOTAL_FORMS": 2,
|
|
|
|
"form-INITIAL_FORMS": 0,
|
|
|
|
"form-MIN_NUM_FORMS": 0,
|
|
|
|
"form-MAX_NUM_FORMS": 1000,
|
2024-02-29 10:07:26 +00:00
|
|
|
"form-0-article": self.article_one_month.pk,
|
2019-11-03 23:25:29 +00:00
|
|
|
"form-0-quantity": 1,
|
2024-02-29 10:07:26 +00:00
|
|
|
"form-1-article": self.article_one_month.pk,
|
2019-11-03 23:25:29 +00:00
|
|
|
"form-1-quantity": 1,
|
|
|
|
}
|
2019-11-04 16:55:03 +00:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("cotisations:new-facture", kwargs={"userid": self.user.pk}), data
|
|
|
|
)
|
2024-02-20 15:22:57 +00:00
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
self.assertEqual(response.url, "/users/profil/%d" % self.user.pk)
|
2019-11-03 23:25:29 +00:00
|
|
|
f = self.user.facture_set.first()
|
|
|
|
self.assertEqual(f.vente_set.count(), 2)
|