Implement barman prices and improve counter views

This commit is contained in:
Skia 2016-06-01 01:33:20 +02:00
parent 6c48b7c718
commit ffe2aec980
5 changed files with 44 additions and 21 deletions

View File

@ -140,6 +140,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
# Counters # Counters
Customer(user=skia, account_id="6568j", amount=0).save() Customer(user=skia, account_id="6568j", amount=0).save()
Customer(user=r, account_id="4000", amount=0).save()
p = ProductType(name="Bières bouteilles") p = ProductType(name="Bières bouteilles")
p.save() p.save()
barb = Product(name="Barbar", code="BARB", product_type=p, purchase_price="1.50", selling_price="1.7", barb = Product(name="Barbar", code="BARB", product_type=p, purchase_price="1.50", selling_price="1.7",

View File

@ -269,6 +269,9 @@ class AnonymousUser(AuthAnonymousUser):
return True return True
return False return False
def get_display_name(self):
return _("Visitor")
class LockError(Exception): class LockError(Exception):
"""There was a lock error on the object""" """There was a lock error on the object"""
pass pass

View File

@ -22,7 +22,7 @@
<p><strong>Club: </strong> {{ counter.club }}</p> <p><strong>Club: </strong> {{ counter.club }}</p>
<div> <div>
<p>Customer: {{ customer }}</p> <p>Customer: {{ customer.user.get_display_name() }}, {{ customer.amount }} €</p>
<p>Basket: </p> <p>Basket: </p>
<ul> <ul>
{% for id,qte in request.session['basket'].items() %} {% for id,qte in request.session['basket'].items() %}

View File

@ -16,6 +16,17 @@
<div> <div>
<h3>Sellings</h3>
{% if last_basket %}
<h4>Last selling: </h4>
<p>Client: {{ last_customer }}, new amount: {{ new_customer_amount }} €.</p>
<ul>
{% for s in last_basket %}
<li>{{ s }}</li>
{% endfor %}
</ul>
<p><strong>Total: {{ last_total }} €</strong></p>
{% endif %}
{% if barmen %} {% if barmen %}
<p>Enter client code:</p> <p>Enter client code:</p>
<form method="post" action="{{ url('counter:details', counter_id=counter.id) }}"> <form method="post" action="{{ url('counter:details', counter_id=counter.id) }}">

View File

@ -60,6 +60,11 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
kwargs['login_form'] = AuthenticationForm() kwargs['login_form'] = AuthenticationForm()
kwargs['form'] = self.get_form() kwargs['form'] = self.get_form()
kwargs['barmen'] = Counter.get_barmen_list(self.object.id) kwargs['barmen'] = Counter.get_barmen_list(self.object.id)
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')
kwargs['last_total'] = self.request.session.pop('last_total')
kwargs['new_customer_amount'] = self.request.session.pop('new_customer_amount')
return kwargs return kwargs
def form_valid(self, form): def form_valid(self, form):
@ -69,26 +74,9 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
self.kwargs['user_id'] = form.cleaned_data['user_id'] self.kwargs['user_id'] = form.cleaned_data['user_id']
return super(CounterMain, self).form_valid(form) return super(CounterMain, self).form_valid(form)
def get_success_url(self): def get_success_url(self):
return reverse_lazy('counter:click', args=self.args, kwargs=self.kwargs) return reverse_lazy('counter:click', args=self.args, kwargs=self.kwargs)
class BasketForm(forms.Form):
def __init__(self, *args, **kwargs):
print(kwargs)
super(BasketForm, self).__init__(*args, **kwargs)
for p in kwargs['initial']['counter'].products.all(): # TODO: filter on the allowed products for this counter
self.fields[p.id] = forms.IntegerField(label=p.name, required=False)
# TODO ^: add some extra infos for the products (price, or ID to load infos dynamically)
def clean(self):
cleaned_data = super(BasketForm, self).clean()
total = 0
for pid,q in cleaned_data.items():
p = Product.objects.filter(id=pid).first()
total += (q or 0)*p.selling_price
print(total)
class CounterClick(DetailView): class CounterClick(DetailView):
""" """
The click view The click view
@ -151,13 +139,33 @@ class CounterClick(DetailView):
def finish(self, request): def finish(self, request):
""" Finish the click session, and validate the basket """ """ Finish the click session, and validate the basket """
if self.customer in Counter.get_barmen_list(self.object.id):
seller = self.customer.user
barman = True
else:
seller = Counter.get_random_barman(self.object.id)
barman = False
total = 0
kwargs = {
'counter_id': self.object.id,
}
request.session['last_basket'] = []
for pid,qty in request.session['basket'].items(): for pid,qty in request.session['basket'].items():
p = Product.objects.filter(pk=pid).first() p = Product.objects.filter(pk=pid).first()
s = Selling(product=p, counter=self.object, unit_price=p.selling_price, if barman:
quantity=qty, seller=Counter.get_random_barman(self.object.id), customer=self.customer) uprice = p.special_selling_price
else:
uprice = p.selling_price
total += uprice
request.session['last_basket'].append("%d x %s" % (qty, p.name))
s = Selling(product=p, counter=self.object, unit_price=uprice,
quantity=qty, seller=seller, customer=self.customer)
s.save() s.save()
kwargs = {'counter_id': self.object.id} request.session['last_customer'] = self.customer.user.get_display_name()
request.session['last_total'] = str(total)
request.session['new_customer_amount'] = str(self.customer.amount)
del request.session['basket'] del request.session['basket']
request.session.modified = True
return HttpResponseRedirect(reverse_lazy('counter:details', args=self.args, kwargs=kwargs)) return HttpResponseRedirect(reverse_lazy('counter:details', args=self.args, kwargs=kwargs))
def cancel(self, request): def cancel(self, request):