Commit 1feea061 authored by Skia's avatar Skia

Add basic refill support

parent 9989b75b
Pipeline #47 passed with stage
in 1 minute and 16 seconds
# TODO
## Easter eggs
* 'A' 'L' 'L' 'O': Entendre le Allooo de Madame Coucoune
* idem avec cacafe
* Un meat spin quelque part
* Konami code
......@@ -127,16 +127,16 @@ class Refilling(models.Model):
# TODO: add the bank if the payment is made by cheque
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):
# return reverse('counter:details', kwargs={'counter_id': self.id})
def save(self, *args, **kwargs):
self.full_clean()
self.customer.amount += self.quantity * self.unit_price
self.customer.amount += self.amount
self.customer.save()
super(Selling, self).save(*args, **kwargs)
super(Refilling, self).save(*args, **kwargs)
class Selling(models.Model):
"""
......
......@@ -22,7 +22,20 @@
<p><strong>Club: </strong> {{ counter.club }}</p>
<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'] %}
<p><strong>Not enough money</strong></p>
{% endif %}
......
......@@ -64,6 +64,7 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
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
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 'last_basket' in self.request.session.keys():
......@@ -120,6 +121,8 @@ class CounterClick(DetailView):
self.add_product(request)
elif 'del_product' in request.POST['action']:
self.del_product(request)
elif 'refill' in request.POST['action']:
self.refill(request)
elif 'code' in request.POST['action']:
return self.parse_code(request)
elif 'cancel' in request.POST['action']:
......@@ -233,6 +236,17 @@ class CounterClick(DetailView):
request.session.pop('basket', None)
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):
""" Add customer to the context """
kwargs = super(CounterClick, self).get_context_data(**kwargs)
......
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