Commit c099cc48 authored by Skia's avatar Skia

Improve refilling form to handle the checks and the banks

parent 14595936
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('counter', '0003_customer_amount'),
]
operations = [
migrations.AddField(
model_name='refilling',
name='bank',
field=models.CharField(verbose_name='bank', default='other', max_length=255, choices=[('other', 'Autre'), ('la-poste', 'La Poste'), ('credit-agricole', 'Credit Agricole'), ('credit-mutuel', 'Credit Mutuel')]),
),
migrations.AlterField(
model_name='refilling',
name='payment_method',
field=models.CharField(verbose_name='payment method', default='cash', max_length=255, choices=[('cheque', 'Chèque'), ('cash', 'Espèce')]),
),
]
......@@ -123,8 +123,9 @@ class Refilling(models.Model):
customer = models.ForeignKey(Customer, related_name="refill_customers", blank=False)
date = models.DateTimeField(_('date'), auto_now=True)
payment_method = models.CharField(_('payment method'), max_length=255,
choices=settings.SITH_COUNTER_PAYMENT_METHOD)
# TODO: add the bank if the payment is made by cheque
choices=settings.SITH_COUNTER_PAYMENT_METHOD, default='cash')
bank = models.CharField(_('bank'), max_length=255,
choices=settings.SITH_COUNTER_BANK, default='other')
def __str__(self):
return "Refilling: %.2f for %s" % (self.amount, self.customer.user.get_display_name())
......
......@@ -29,8 +29,8 @@
<h5>Refilling</h5>
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
{% csrf_token %}
{{ refill_form.as_p() }}
<input type="hidden" name="action" value="refill">
<input type="input" name="amount" value=""/>
<input type="submit" value="Go" />
</form>
</div>
......
......@@ -44,6 +44,13 @@ class GetUserForm(forms.Form):
cleaned_data['user_id'] = user.user.id
return cleaned_data
class RefillForm(forms.ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class Meta:
model = Refilling
fields = ['amount', 'payment_method', 'bank']
class CounterMain(DetailView, ProcessFormView, FormMixin):
"""
The public (barman) view
......@@ -101,6 +108,7 @@ class CounterClick(DetailView):
request.session['basket'] = {}
request.session['basket_total'] = 0
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
......@@ -110,6 +118,7 @@ class CounterClick(DetailView):
""" Handle the many possibilities of the post request """
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
return self.cancel(request)
if 'basket' not in request.session.keys():
......@@ -243,16 +252,21 @@ class CounterClick(DetailView):
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()
form = RefillForm(request.POST)
if form.is_valid():
form.instance.counter = self.object
form.instance.operator = operator
form.instance.customer = self.customer
form.instance.save()
else:
self.refill_form = form
def get_context_data(self, **kwargs):
""" Add customer to the context """
kwargs = super(CounterClick, self).get_context_data(**kwargs)
kwargs['customer'] = self.customer
kwargs['basket_total'] = self.sum_basket(self.request)
kwargs['refill_form'] = self.refill_form or RefillForm()
return kwargs
class CounterLogin(RedirectView):
......
......@@ -222,6 +222,13 @@ SITH_COUNTER_PAYMENT_METHOD = [
('cash', 'Espèce'),
]
SITH_COUNTER_BANK = [
('other', 'Autre'),
('la-poste', 'La Poste'),
('credit-agricole', 'Credit Agricole'),
('credit-mutuel', 'Credit Mutuel'),
]
# Subscription durations are in semestres (should be settingized)
SITH_SUBSCRIPTIONS = {
'un-semestre': {
......
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