Commit 2422f608 authored by Alexandre | L'Sacienne's avatar Alexandre | L'Sacienne
Browse files

Merge branch 'lsacienne/refilling_only_for_ae_member' into 'master'

Adds a Restriction for refilling

As it was asked by many members of the AE. I added a restriction applied to the barmens.
In fact, we oftenly loose money due to the physic refilling.
The goal with this change is to only allow **the members of the AE** to refill with physic money.

See merge request !303
parents 5b0f7ca2 ba6599fa
Pipeline #2507 passed with stages
in 28 minutes and 48 seconds
...@@ -611,6 +611,7 @@ Welcome to the wiki page! ...@@ -611,6 +611,7 @@ Welcome to the wiki page!
mde.products.add(cons) mde.products.add(cons)
mde.products.add(dcons) mde.products.add(dcons)
mde.sellers.add(skia) mde.sellers.add(skia)
mde.save() mde.save()
eboutic = Counter.objects.filter(name="Eboutic").first() eboutic = Counter.objects.filter(name="Eboutic").first()
...@@ -935,6 +936,7 @@ Welcome to the wiki page! ...@@ -935,6 +936,7 @@ Welcome to the wiki page!
# Add barman to counter # Add barman to counter
c = Counter.objects.get(id=2) c = Counter.objects.get(id=2)
c.sellers.add(User.objects.get(pk=krophil.pk)) c.sellers.add(User.objects.get(pk=krophil.pk))
mde.sellers.add(sli)
c.save() c.save()
# Create an election # Create an election
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
# #
# #
from sith.settings import SITH_MAIN_CLUB
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils import timezone from django.utils import timezone
...@@ -39,7 +40,7 @@ import os ...@@ -39,7 +40,7 @@ import os
import base64 import base64
import datetime import datetime
from club.models import Club from club.models import Club, Membership
from accounting.models import CurrencyField from accounting.models import CurrencyField
from core.models import Group, User, Notification from core.models import Group, User, Notification
from subscription.models import Subscription from subscription.models import Subscription
...@@ -342,6 +343,14 @@ class Counter(models.Model): ...@@ -342,6 +343,14 @@ class Counter(models.Model):
""" """
return [b.id for b in self.get_barmen_list()] return [b.id for b in self.get_barmen_list()]
def can_refill(self):
is_ae_member = False
ae = Club.objects.get(unix_name=SITH_MAIN_CLUB["unix_name"])
for barman in self.get_barmen_list():
if ae.get_membership_for(barman):
is_ae_member = True
return is_ae_member
class Refilling(models.Model): class Refilling(models.Model):
""" """
......
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
<input type="submit" value="{% trans %}Cancel{% endtrans %}" /> <input type="submit" value="{% trans %}Cancel{% endtrans %}" />
</form> </form>
</div> </div>
{% if counter.type == 'BAR' %} {% if (counter.type == 'BAR' and barmens_can_refill) %}
<h5>{% trans %}Refilling{% endtrans %}</h5> <h5>{% trans %}Refilling{% endtrans %}</h5>
<div> <div>
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}"> <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
......
...@@ -36,7 +36,10 @@ class CounterTest(TestCase): ...@@ -36,7 +36,10 @@ class CounterTest(TestCase):
def setUp(self): def setUp(self):
call_command("populate") call_command("populate")
self.skia = User.objects.filter(username="skia").first() self.skia = User.objects.filter(username="skia").first()
self.sli = User.objects.filter(username="sli").first()
self.krophil = User.objects.filter(username="krophil").first()
self.mde = Counter.objects.filter(name="MDE").first() self.mde = Counter.objects.filter(name="MDE").first()
self.foyer = Counter.objects.get(id=2)
def test_full_click(self): def test_full_click(self):
response = self.client.post( response = self.client.post(
...@@ -93,6 +96,51 @@ class CounterTest(TestCase): ...@@ -93,6 +96,51 @@ class CounterTest(TestCase):
in str(response_content) in str(response_content)
) )
response = self.client.post(
reverse("counter:login", kwargs={"counter_id": self.mde.id}),
{"username": self.sli.username, "password": "plop"},
)
response = self.client.post(
location,
{
"action": "refill",
"amount": "5",
"payment_method": "CASH",
"bank": "OTHER",
},
)
response = self.client.post(
reverse("counter:login", kwargs={"counter_id": self.foyer.id}),
{"username": self.krophil.username, "password": "plop"},
)
response = self.client.get(
reverse("counter:details", kwargs={"counter_id": self.foyer.id})
)
counter_token = re.search(
r'name="counter_token" value="([^"]*)"', str(response.content)
).group(1)
response = self.client.post(
reverse("counter:details", kwargs={"counter_id": self.foyer.id}),
{"code": "4000k", "counter_token": counter_token},
)
location = response.get("location")
response = self.client.post(
location,
{
"action": "refill",
"amount": "5",
"payment_method": "CASH",
"bank": "OTHER",
},
)
self.assertTrue(response.status_code == 403)
class CounterStatsTest(TestCase): class CounterStatsTest(TestCase):
def setUp(self): def setUp(self):
......
...@@ -725,7 +725,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView): ...@@ -725,7 +725,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
def refill(self, request): def refill(self, request):
"""Refill the customer's account""" """Refill the customer's account"""
if self.get_object().type == "BAR": if self.get_object().type == "BAR" and self.object.can_refill():
form = RefillForm(request.POST) form = RefillForm(request.POST)
if form.is_valid(): if form.is_valid():
form.instance.counter = self.object form.instance.counter = self.object
...@@ -751,6 +751,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView): ...@@ -751,6 +751,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
kwargs["basket_total"] = self.sum_basket(self.request) kwargs["basket_total"] = self.sum_basket(self.request)
kwargs["refill_form"] = self.refill_form or RefillForm() kwargs["refill_form"] = self.refill_form or RefillForm()
kwargs["student_card_max_uid_size"] = StudentCard.UID_SIZE kwargs["student_card_max_uid_size"] = StudentCard.UID_SIZE
kwargs["barmens_can_refill"] = self.object.can_refill()
return kwargs return kwargs
......
...@@ -45,7 +45,7 @@ Par défaut, la base de données du site de prod contient des données nécessai ...@@ -45,7 +45,7 @@ Par défaut, la base de données du site de prod contient des données nécessai
* **comptable** -> administrateur comptabilité * **comptable** -> administrateur comptabilité
* **guy** -> utilisateur non cotisant et sans groupe * **guy** -> utilisateur non cotisant et sans groupe
* **rbatsbak** -> utilisateur non cotisant et sans groupe * **rbatsbak** -> utilisateur non cotisant et sans groupe
* **sli** -> cotisant avec carte étudiante attachée au compte * **sli** -> cotisant avec carte étudiante attachée au compte, barmen MDE
* **krophil** -> cotisant avec des plein d'écocups, barmen foyer * **krophil** -> cotisant avec des plein d'écocups, barmen foyer
* **comunity** -> administrateur communication * **comunity** -> administrateur communication
* **tutu** -> administrateur pédagogie * **tutu** -> administrateur pédagogie
......
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