Add basic refill support

This commit is contained in:
Skia 2016-06-26 20:07:29 +02:00
parent 9989b75b3e
commit 1feea061f6
4 changed files with 40 additions and 4 deletions

9
TODO.md Normal file
View File

@ -0,0 +1,9 @@
# TODO
## Easter eggs
* 'A' 'L' 'L' 'O': Entendre le Allooo de Madame Coucoune
* idem avec cacafe
* Un meat spin quelque part
* Konami code

View File

@ -127,16 +127,16 @@ class Refilling(models.Model):
# TODO: add the bank if the payment is made by cheque # TODO: add the bank if the payment is made by cheque
def __str__(self): def __str__(self):
return "Refilling: %f for %s" % (self.amount, self.customer.user.get_display_name()) return "Refilling: %.2f for %s" % (self.amount, self.customer.user.get_display_name())
# def get_absolute_url(self): # def get_absolute_url(self):
# return reverse('counter:details', kwargs={'counter_id': self.id}) # return reverse('counter:details', kwargs={'counter_id': self.id})
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.full_clean() self.full_clean()
self.customer.amount += self.quantity * self.unit_price self.customer.amount += self.amount
self.customer.save() self.customer.save()
super(Selling, self).save(*args, **kwargs) super(Refilling, self).save(*args, **kwargs)
class Selling(models.Model): class Selling(models.Model):
""" """

View File

@ -22,7 +22,20 @@
<p><strong>Club: </strong> {{ counter.club }}</p> <p><strong>Club: </strong> {{ counter.club }}</p>
<div> <div>
<p>Customer: {{ customer.user.get_display_name() }}, {{ customer.amount }} €</p> <h5>Customer</h5>
<p>{{ customer.user.get_display_name() }}, {{ customer.amount }} €</p>
</div>
<div>
<h5>Refilling</h5>
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
{% csrf_token %}
<input type="hidden" name="action" value="refill">
<input type="input" name="amount" value=""/>
<input type="submit" value="Go" />
</form>
</div>
<div>
<h5>Selling</h5>
{% if request.session['not_enough'] %} {% if request.session['not_enough'] %}
<p><strong>Not enough money</strong></p> <p><strong>Not enough money</strong></p>
{% endif %} {% endif %}

View File

@ -64,6 +64,7 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
kwargs = super(CounterMain, self).get_context_data(**kwargs) kwargs = super(CounterMain, self).get_context_data(**kwargs)
# TODO: make some checks on the counter type, in order not to make the AuthenticationForm if there is no need to # TODO: make some checks on the counter type, in order not to make the AuthenticationForm if there is no need to
kwargs['login_form'] = AuthenticationForm() kwargs['login_form'] = AuthenticationForm()
kwargs['login_form'].fields['username'].widget.attrs['autofocus'] = True
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(): if 'last_basket' in self.request.session.keys():
@ -120,6 +121,8 @@ class CounterClick(DetailView):
self.add_product(request) self.add_product(request)
elif 'del_product' in request.POST['action']: elif 'del_product' in request.POST['action']:
self.del_product(request) self.del_product(request)
elif 'refill' in request.POST['action']:
self.refill(request)
elif 'code' in request.POST['action']: elif 'code' in request.POST['action']:
return self.parse_code(request) return self.parse_code(request)
elif 'cancel' in request.POST['action']: elif 'cancel' in request.POST['action']:
@ -233,6 +236,17 @@ class CounterClick(DetailView):
request.session.pop('basket', None) request.session.pop('basket', None)
return HttpResponseRedirect(reverse_lazy('counter:details', args=self.args, kwargs=kwargs)) return HttpResponseRedirect(reverse_lazy('counter:details', args=self.args, kwargs=kwargs))
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)
amount = float(request.POST['amount'])
s = Refilling(counter=self.object, operator=operator, customer=self.customer,
amount=amount, payment_method="cash")
s.save()
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
""" Add customer to the context """ """ Add customer to the context """
kwargs = super(CounterClick, self).get_context_data(**kwargs) kwargs = super(CounterClick, self).get_context_data(**kwargs)