diff --git a/kfet/forms.py b/kfet/forms.py index 26ada7bc..71f5a78e 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -132,27 +132,48 @@ class CheckoutRestrictForm(CheckoutForm): class CheckoutStatementCreateForm(forms.ModelForm): - balance_001 = forms.IntegerField(min_value=0, initial=0) - balance_002 = forms.IntegerField(min_value=0, initial=0) - balance_005 = forms.IntegerField(min_value=0, initial=0) - balance_01 = forms.IntegerField(min_value=0, initial=0) - balance_02 = forms.IntegerField(min_value=0, initial=0) - balance_05 = forms.IntegerField(min_value=0, initial=0) - balance_1 = forms.IntegerField(min_value=0, initial=0) - balance_2 = forms.IntegerField(min_value=0, initial=0) - balance_5 = forms.IntegerField(min_value=0, initial=0) - balance_10 = forms.IntegerField(min_value=0, initial=0) - balance_20 = forms.IntegerField(min_value=0, initial=0) - balance_50 = forms.IntegerField(min_value=0, initial=0) - balance_100 = forms.IntegerField(min_value=0, initial=0) - balance_200 = forms.IntegerField(min_value=0, initial=0) - balance_500 = forms.IntegerField(min_value=0, initial=0) + balance_001 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_002 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_005 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_01 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_02 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_05 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_1 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_2 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_5 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_10 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_20 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_50 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_100 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_200 = forms.IntegerField(min_value=0, initial=0, required=False) + balance_500 = forms.IntegerField(min_value=0, initial=0, required=False) class Meta: model = CheckoutStatement exclude = ['by', 'at', 'checkout', 'amount_error', 'amount_taken', 'balance_old', 'balance_new'] + def clean(self): + not_count = self.cleaned_data['not_count'] + if not not_count and ( + self.cleaned_data['balance_001'] is None + or self.cleaned_data['balance_002'] is None + or self.cleaned_data['balance_005'] is None + or self.cleaned_data['balance_01'] is None + or self.cleaned_data['balance_02'] is None + or self.cleaned_data['balance_05'] is None + or self.cleaned_data['balance_1'] is None + or self.cleaned_data['balance_2'] is None + or self.cleaned_data['balance_5'] is None + or self.cleaned_data['balance_10'] is None + or self.cleaned_data['balance_20'] is None + or self.cleaned_data['balance_50'] is None + or self.cleaned_data['balance_100'] is None + or self.cleaned_data['balance_200'] is None + or self.cleaned_data['balance_500'] is None): + raise ValidationError("Y'a un problème. Si tu comptes la caisse, mets au moins des 0 stp (et t'as pas idée de comment c'est long de vérifier que t'as mis des valeurs de partout...)") + super(CheckoutStatementCreateForm, self).clean() + class CheckoutStatementUpdateForm(forms.ModelForm): class Meta: model = CheckoutStatement diff --git a/kfet/migrations/0033_checkoutstatement_not_count.py b/kfet/migrations/0033_checkoutstatement_not_count.py new file mode 100644 index 00000000..50c58256 --- /dev/null +++ b/kfet/migrations/0033_checkoutstatement_not_count.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0032_auto_20160822_2350'), + ] + + operations = [ + migrations.AddField( + model_name='checkoutstatement', + name='not_count', + field=models.BooleanField(default=False), + ), + ] diff --git a/kfet/migrations/0034_auto_20160823_0206.py b/kfet/migrations/0034_auto_20160823_0206.py new file mode 100644 index 00000000..90d0965c --- /dev/null +++ b/kfet/migrations/0034_auto_20160823_0206.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0033_checkoutstatement_not_count'), + ] + + operations = [ + migrations.AlterField( + model_name='checkoutstatement', + name='taken_cheque', + field=models.DecimalField(max_digits=6, decimal_places=2, default=0), + ), + ] diff --git a/kfet/models.py b/kfet/models.py index 39953196..52862f1b 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -259,6 +259,7 @@ class CheckoutStatement(models.Model): amount_taken = models.DecimalField(max_digits = 6, decimal_places = 2) amount_error = models.DecimalField(max_digits = 6, decimal_places = 2) at = models.DateTimeField(auto_now_add = True) + not_count = models.BooleanField(default=False) taken_001 = models.PositiveSmallIntegerField(default=0) taken_002 = models.PositiveSmallIntegerField(default=0) @@ -275,7 +276,7 @@ class CheckoutStatement(models.Model): taken_100 = models.PositiveSmallIntegerField(default=0) taken_200 = models.PositiveSmallIntegerField(default=0) taken_500 = models.PositiveSmallIntegerField(default=0) - taken_cheque = models.PositiveSmallIntegerField(default=0) + taken_cheque = models.DecimalField(default=0, max_digits=6, decimal_places=2) def __str__(self): return '%s %s' % (self.checkout, self.at) @@ -285,8 +286,10 @@ class CheckoutStatement(models.Model): checkout_id = self.checkout_id self.balance_old = (Checkout.objects .values_list('balance', flat=True).get(pk=checkout_id)) + if self.not_count: + self.balance_new = self.balance_old - self.amount_taken self.amount_error = ( - self.balance_new + self.amount_taken - self.balance_old) + self.balance_new + self.amount_taken - self.balance_old) with transaction.atomic(): Checkout.objects.filter(pk=checkout_id).update(balance=self.balance_new) super(CheckoutStatement, self).save(*args, **kwargs) diff --git a/kfet/templates/kfet/checkoutstatement_create.html b/kfet/templates/kfet/checkoutstatement_create.html index d9400f9b..0edb66ad 100644 --- a/kfet/templates/kfet/checkoutstatement_create.html +++ b/kfet/templates/kfet/checkoutstatement_create.html @@ -1,4 +1,5 @@ {% extends "kfet/base.html" %} +{% load l10n %} {% block title %}Nouveau relevé{% endblock %} {% block content-header-title %}Caisse {{ checkout.name }} - Nouveau relevé{% endblock %} @@ -14,18 +15,164 @@
{% include "kfet/base_messages.html" %}
-
-
- {% csrf_token %} - {{ form.as_p }} - {% if not perms.kfet.add_checkoutstatement %} - - {% endif %} - -
-
+
+ {% csrf_token %} +
+

Général

+
+
+ Ancienne balance : {{ checkout.balance|unlocalize }}
+ Nouvelle balance : 0
+ Pris : 0
+ Erreur : 0
+ {% if not perms.kfet.add_checkoutstatement %} + + + {% endif %} + +
+
+
+

Pris

+
+ + + + + + + + + + + + + + + + + + + +
5€10€20€50€100€200€500€
+ + + + + + + + + + + + + + + + + + + + + +
2€1€0.50€0.20€0.10€0.05€0.02€0.01€
+ Chèque: +
+
+
+

En caisse

+
+ + + + + + + + + + + + + + + + + + + +
5€10€20€50€100€200€500€
+ + + + + + + + + + + + + + + + + + + + + +
2€1€0.50€0.20€0.10€0.05€0.02€0.01€
+
+
+
+ + {% endblock %} diff --git a/kfet/views.py b/kfet/views.py index 418347c0..ab70c640 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -418,7 +418,7 @@ def getAmountTaken(data): + data.taken_5 * 5 + data.taken_10 * 10 + data.taken_20 * 20 + data.taken_50 * 50 + data.taken_100 * 100 + data.taken_200 * 200 - + data.taken_500 * 500 + data.taken_cheque) + + data.taken_500 * 500 + float(data.taken_cheque)) def getAmountBalance(data): return Decimal(data['balance_001'] * 0.01 + data['balance_002'] * 0.02 @@ -458,7 +458,8 @@ class CheckoutStatementCreate(SuccessMessageMixin, CreateView): return self.form_invalid(form) # Creating form.instance.amount_taken = getAmountTaken(form.instance) - form.instance.balance_new = getAmountBalance(form.cleaned_data) + if not form.instance.not_count: + form.instance.balance_new = getAmountBalance(form.cleaned_data) form.instance.checkout_id = self.kwargs['pk_checkout'] form.instance.by = self.request.user.profile.account_kfet return super(CheckoutStatementCreate, self).form_valid(form)