Fix some counter stuff

This commit is contained in:
Skia
2016-07-22 13:34:34 +02:00
parent 256651f580
commit 0ecb78a101
8 changed files with 79 additions and 71 deletions

View File

@ -95,6 +95,8 @@ class Counter(models.Model):
return self.name
def get_absolute_url(self):
if self.type == "EBOUTIC":
return reverse('eboutic:main')
return reverse('counter:details', kwargs={'counter_id': self.id})
def can_be_edited_by(self, user):

View File

@ -10,8 +10,13 @@
<h3>{% trans %}Counter admin list{% endtrans %}</h3>
<ul>
{% for c in counter_list %}
{% if c.type == "EBOUTIC" %}
<li><a href="{{ url('eboutic:main') }}">{{ c }}</a> -
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a></li>
{% else %}
<li><a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a></li>
{% endif %}
{% endfor %}
</ul>
{% else %}

View File

@ -9,11 +9,7 @@
{% endmacro %}
{% block content %}
<h3>{% trans %}Counter{% endtrans %}</h3>
<h4>{{ counter }}</h4>
<p><strong>{% trans %}Club: {% endtrans %}</strong> {{ counter.club }}</p>
<p><strong>{% trans %}Products: {% endtrans %}</strong> {{ counter.products.all() }}</p>
<h3>{% trans counter_name=counter %}{{ counter_name }} counter{% endtrans %}</h3>
<div>
<h3>{% trans %}Sellings{% endtrans %}</h3>

View File

@ -124,12 +124,20 @@ class CounterClick(DetailView):
self.object = self.get_object()
self.customer = Customer.objects.filter(user__id=self.kwargs['user_id']).first()
self.refill_form = None
if len(Counter.get_barmen_list(self.object.id)) < 1: # Check that at least one barman is logged in
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
return self.cancel(request)
if 'basket' not in request.session.keys():
request.session['basket'] = {}
request.session['basket_total'] = 0
request.session['not_enough'] = False
if self.object.type != "BAR":
self.operator = request.user
elif self.is_barman_price():
self.operator = self.customer.user
else:
self.operator = Counter.get_random_barman(self.object.id)
if 'add_product' in request.POST['action']:
self.add_product(request)
@ -147,7 +155,7 @@ class CounterClick(DetailView):
return self.render_to_response(context)
def is_barman_price(self):
if self.customer.user.id in [s.id for s in Counter.get_barmen_list(self.object.id)]:
if self.object.type == "BAR" and self.customer.user.id in [s.id for s in Counter.get_barmen_list(self.object.id)]:
return True
else:
return False
@ -210,7 +218,7 @@ class CounterClick(DetailView):
nb = 1
else:
nb = int(nb)
p = Product.objects.filter(code=code).first()
p = self.object.products.filter(code=code).first()
if p is not None:
while nb > 0 and not self.add_product(request, nb, p.id):
nb -= 1
@ -220,10 +228,6 @@ class CounterClick(DetailView):
def finish(self, request):
""" Finish the click session, and validate the basket """
with transaction.atomic():
if self.is_barman_price():
seller = self.customer.user
else:
seller = Counter.get_random_barman(self.object.id)
request.session['last_basket'] = []
for pid,infos in request.session['basket'].items():
# This duplicates code for DB optimization (prevent to load many times the same object)
@ -236,7 +240,7 @@ class CounterClick(DetailView):
raise DataError(_("You have not enough money to buy all the basket"))
request.session['last_basket'].append("%d x %s" % (infos['qty'], p.name))
s = Selling(product=p, counter=self.object, unit_price=uprice,
quantity=infos['qty'], seller=seller, customer=self.customer)
quantity=infos['qty'], seller=self.operator, customer=self.customer)
s.save()
request.session['last_customer'] = self.customer.user.get_display_name()
request.session['last_total'] = "%0.2f" % self.sum_basket(request)
@ -256,14 +260,10 @@ class CounterClick(DetailView):
def refill(self, request):
"""Refill the customer's account"""
if self.is_barman_price():
operator = self.customer.user
else:
operator = Counter.get_random_barman(self.object.id)
form = RefillForm(request.POST)
if form.is_valid():
form.instance.counter = self.object
form.instance.operator = operator
form.instance.operator = self.operator
form.instance.customer = self.customer
form.instance.save()
else: