Commit 1f3e186e authored by Skia's avatar Skia

Update counters and some views

parent 724f3d8d
Pipeline #62 failed with stage
in 1 minute and 2 seconds
......@@ -13,12 +13,6 @@
{% if user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
<li><a href="{{ url('core:group_list') }}">{% trans %}Groups{% endtrans %}</a></li>
{% endif %}
{% if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) %}
<li><a href="{{ url('counter:admin_list') }}">{% trans %}Counters management{% endtrans %}</a></li>
{% endif %}
{% if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) %}
<li><a href="{{ url('accounting:bank_list') }}">{% trans %}Accounting{% endtrans %}</a></li>
{% endif %}
{% if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
<li><a href="{{ url('subscription:subscription') }}">{% trans %}Subscriptions{% endtrans %}</a></li>
{% endif %}
......@@ -27,6 +21,9 @@
<hr>
<h4>{% trans %}Counters{% endtrans %}</h4>
<ul>
{% if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
<li><a href="{{ url('counter:admin_list') }}">{% trans %}General counters management{% endtrans %}</a></li>
{% endif %}
{% for b in settings.SITH_COUNTER_BARS %}
{% if user.is_in_group(b[1]+" admin") %}
<li><a href="{{ url('counter:details', counter_id=b[0]) }}">{{ b[1] }}</a> -
......@@ -38,6 +35,9 @@
<hr>
<h4>{% trans %}Accounting{% endtrans %}</h4>
<ul>
{% if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) or user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
<li><a href="{{ url('accounting:bank_list') }}">{% trans %}General accounting{% endtrans %}</a></li>
{% endif %}
{% for m in user.membership.filter(end_date=None).filter(role__gte=7).all() %}
{% for b in m.club.bank_accounts.all() %}
<li><strong>{% trans %}Bank account: {% endtrans %}</strong>
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('counter', '0008_auto_20160718_1805'),
]
operations = [
migrations.AlterField(
model_name='counter',
name='type',
field=models.CharField(max_length=255, verbose_name='subscription type', choices=[('BAR', 'Bar'), ('OFFICE', 'Office'), ('EBOUTIC', 'Eboutic')]),
),
]
......@@ -10,7 +10,6 @@ from random import randrange
from club.models import Club
from accounting.models import CurrencyField
from core.models import Group, User
from subscription.models import Subscriber
class Customer(models.Model):
"""
......@@ -82,7 +81,7 @@ class Counter(models.Model):
products = models.ManyToManyField(Product, related_name="counters", blank=True)
type = models.CharField(_('subscription type'),
max_length=255,
choices=[('BAR',_('Bar')), ('OFFICE',_('Office'))])
choices=[('BAR',_('Bar')), ('OFFICE',_('Office')), ('EBOUTIC',_('Eboutic'))])
edit_groups = models.ManyToManyField(Group, related_name="editable_counters", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True)
barmen_session = {}
......@@ -132,7 +131,7 @@ class Counter(models.Model):
def get_barmen_list(counter_id):
"""
Returns the barman list as list of Subscriber
Returns the barman list as list of User
Also handle the timeout of the barmen
"""
......@@ -141,7 +140,7 @@ class Counter(models.Model):
if counter_id in list(Counter.barmen_session.keys()):
for b in Counter.barmen_session[counter_id]['users']:
# Reminder: user is stored as a tuple with its login time
bl.append(Subscriber.objects.filter(id=b[0]).first())
bl.append(User.objects.filter(id=b[0]).first())
if (timezone.now() - Counter.barmen_session[counter_id]['time']) < timedelta(minutes=settings.SITH_BARMAN_TIMEOUT):
Counter.barmen_session[counter_id]['time'] = timezone.now()
else:
......@@ -151,9 +150,9 @@ class Counter(models.Model):
Counter.barmen_session[counter_id]['users'] = set()
return bl
def get_random_barman(counter_id): # TODO: improve this function
def get_random_barman(counter_id):
bl = Counter.get_barmen_list(counter_id)
return bl[0]
return bl[randrange(0, len(bl))]
class Refilling(models.Model):
"""
......
......@@ -25,6 +25,7 @@
<h5>{% trans %}Customer{% endtrans %}</h5>
<p>{{ customer.user.get_display_name() }}, {{ customer.amount }}</p>
</div>
{% if counter.type == 'BAR' %}
<div>
<h5>{% trans %}Refilling{% endtrans %}</h5>
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
......@@ -34,6 +35,7 @@
<input type="submit" value="{% trans %}Go{% endtrans %}" />
</form>
</div>
{% endif %}
<div>
<h5>{% trans %}Selling{% endtrans %}</h5>
{% if request.session['not_enough'] %}
......@@ -47,7 +49,7 @@
</form>
<p>{% trans %}Basket: {% endtrans %}</p>
<ul>
{% for id,infos in request.session['basket'].items() %}
{% for id,infos in request.session['basket']|dictsort %}
{% set product = counter.products.filter(id=id).first() %}
{% set s = infos['qty'] * infos['price'] / 100 %}
<li>{{ del_product(id, '-') }} {{ infos['qty'] }} {{ add_product(id, '+') }} {{ product.name }}: {{ "%0.2f"|format(s) }}</li>
......
......@@ -38,6 +38,7 @@
<p>{% trans %}Please, login{% endtrans %}</p>
{% endif %}
</div>
{% if counter.type == 'BAR' %}
<div>
<h3>{% trans %}Barman: {% endtrans %}</h3>
<ul>
......@@ -51,6 +52,7 @@
<p><input type="submit" value="{% trans %}login{% endtrans %}" /></p>
</form>
</div>
{% endif %}
{% endblock %}
......
......@@ -72,7 +72,10 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
kwargs['login_form'] = AuthenticationForm()
kwargs['login_form'].fields['username'].widget.attrs['autofocus'] = True
kwargs['form'] = self.get_form()
kwargs['barmen'] = Counter.get_barmen_list(self.object.id)
if self.object.type == 'BAR':
kwargs['barmen'] = Counter.get_barmen_list(self.object.id)
elif self.request.user.is_authenticated():
kwargs['barmen'] = [self.request.user]
if 'last_basket' in self.request.session.keys():
kwargs['last_basket'] = self.request.session.pop('last_basket')
kwargs['last_customer'] = self.request.session.pop('last_customer')
......@@ -109,8 +112,10 @@ class CounterClick(DetailView):
request.session['not_enough'] = False
self.refill_form = None
ret = super(CounterClick, self).get(request, *args, **kwargs)
if len(Counter.get_barmen_list(self.object.id)) < 1: # Check that at least one barman is logged in
return self.cancel(request) # Otherwise, go to main view
if ((self.object.type != "BAR" and not request.user.is_authenticated()) or
(self.object.type == "BAR" and
len(Counter.get_barmen_list(self.object.id)) < 1)): # Check that at least one barman is logged in
ret = self.cancel(request) # Otherwise, go to main view
return ret
def post(self, request, *args, **kwargs):
......@@ -173,7 +178,7 @@ class CounterClick(DetailView):
request.session['basket'][pid]['qty'] += q
else:
request.session['basket'][pid] = {'qty': q, 'price': int(price*100)}
request.session['not_enough'] = False
request.session['not_enough'] = False # Reset not_enough to save the session
request.session.modified = True
return True
......@@ -283,7 +288,8 @@ class CounterLogin(RedirectView):
form = AuthenticationForm(request, data=request.POST)
if form.is_valid():
user = Subscriber.objects.filter(username=form.cleaned_data['username']).first()
Counter.add_barman(self.counter_id, user.id)
if user.is_subscribed():
Counter.add_barman(self.counter_id, user.id)
else:
print("Error logging the barman") # TODO handle that nicely
return super(CounterLogin, self).post(request, *args, **kwargs)
......
......@@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-07-21 12:08+0200\n"
"POT-Creation-Date: 2016-07-21 17:39+0200\n"
"PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia <skia@libskia.so>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n"
......@@ -113,8 +113,7 @@ msgstr "Il n'y a pas de types comptable dans ce site web."
#: accounting/templates/accounting/bank_account_details.jinja:5
#: accounting/templates/accounting/club_account_details.jinja:5
#: accounting/templates/accounting/journal_details.jinja:5
#: core/templates/core/user_tools.jinja:20
#: core/templates/core/user_tools.jinja:39
#: core/templates/core/user_tools.jinja:36
msgid "Accounting"
msgstr "Comptabilité"
......@@ -147,7 +146,7 @@ msgstr "Nouveau compte club"
#: club/templates/club/club_detail.jinja:7
#: core/templates/core/page_detail.jinja:7
#: core/templates/core/user_base.jinja:8
#: core/templates/core/user_tools.jinja:33
#: core/templates/core/user_tools.jinja:30
#: counter/templates/counter/counter_list.jinja:14
msgid "Edit"
msgstr "Éditer"
......@@ -865,17 +864,21 @@ msgid "Sith management"
msgstr "Gestion de Sith"
#: core/templates/core/user_tools.jinja:17
msgid "Counters management"
msgstr "Gestion des comptoirs"
#: core/templates/core/user_tools.jinja:23
msgid "Subscriptions"
msgstr "Cotisations"
#: core/templates/core/user_tools.jinja:28
#: core/templates/core/user_tools.jinja:22
msgid "Counters"
msgstr "Comptoirs"
#: core/templates/core/user_tools.jinja:25
msgid "General counters management"
msgstr "Gestion générale des comptoirs"
#: core/templates/core/user_tools.jinja:39
msgid "General accounting"
msgstr "Comptabilité générale"
#: core/templates/core/user_tools.jinja:47
msgid "Club account: "
msgstr "Compte club : "
......@@ -1152,8 +1155,3 @@ msgid "You must either choose an existing user or create a new one properly"
msgstr ""
"Vous devez soit choisir un utilisateur existant, ou en créer un proprement."
#~ msgid "View account"
#~ msgstr "Voir le compte"
#~ msgid "View account:"
#~ msgstr "Voir le compte:"
......@@ -44,6 +44,7 @@ INSTALLED_APPS = (
'subscription',
'accounting',
'counter',
'eboutic',
)
MIDDLEWARE_CLASSES = (
......
......@@ -27,5 +27,6 @@ urlpatterns = [
url(r'^club/', include('club.urls', namespace="club", app_name="club")),
url(r'^counter/', include('counter.urls', namespace="counter", app_name="counter")),
url(r'^accounting/', include('accounting.urls', namespace="accounting", app_name="accounting")),
url(r'^eboutic/', include('eboutic.urls', namespace="eboutic", app_name="eboutic")),
url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!!
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