Assistant sur nouveau relevé
- Reprise de l'affichage - Affichage en direct des totaux et erreurs - Possibilité de ne pas compter la caisse ajoutée (et identifiée par `not_count` dans le modèle Statement si tel est le cas)
This commit is contained in:
parent
f73b25e65f
commit
b6c75fd84a
6 changed files with 239 additions and 29 deletions
|
@ -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
|
||||
|
|
19
kfet/migrations/0033_checkoutstatement_not_count.py
Normal file
19
kfet/migrations/0033_checkoutstatement_not_count.py
Normal file
|
@ -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),
|
||||
),
|
||||
]
|
19
kfet/migrations/0034_auto_20160823_0206.py
Normal file
19
kfet/migrations/0034_auto_20160823_0206.py
Normal file
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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,6 +286,8 @@ 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)
|
||||
with transaction.atomic():
|
||||
|
|
|
@ -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 @@
|
|||
<div class="col-sm-8 col-md-9 col-content-right">
|
||||
{% include "kfet/base_messages.html" %}
|
||||
<div class="content-right">
|
||||
<div class="content-right-block">
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<div class="content-right-block">
|
||||
<h2>Général</h2>
|
||||
<div>
|
||||
<label>
|
||||
Ne pas compter la caisse
|
||||
{{ form.not_count }}
|
||||
</label><br>
|
||||
Ancienne balance : <span id="balance_old">{{ checkout.balance|unlocalize }}</span> €<br>
|
||||
Nouvelle balance : <span id="balance_new">0</span> €<br>
|
||||
Pris : <span id="amount_taken">0</span> €<br>
|
||||
Erreur : <span id="amount_error">0</span> €<br>
|
||||
{% if not perms.kfet.add_checkoutstatement %}
|
||||
<input type="password" name="KFETPASSWORD">
|
||||
<label for="password">Mot de passe:</label>
|
||||
<input type="password" id="password" name="KFETPASSWORD">
|
||||
{% endif %}
|
||||
<input type="submit" value="Enregistrer">
|
||||
</div>
|
||||
</div>
|
||||
<div class="content-right-block">
|
||||
<h2>Pris</h2>
|
||||
<div id="detail_taken">
|
||||
<table class="table table-bordered">
|
||||
<tr style="font-weight:bold;">
|
||||
<td>5€</td>
|
||||
<td>10€</td>
|
||||
<td>20€</td>
|
||||
<td>50€</td>
|
||||
<td>100€</td>
|
||||
<td>200€</td>
|
||||
<td>500€</td>
|
||||
<tr>
|
||||
<tr>
|
||||
<td><input id="id_taken_5" name="taken_5" data-value="5" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_10" name="taken_10" data-value="10" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_20" name="taken_20" data-value="20" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_50" name="taken_50" data-value="50" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_100" name="taken_100" data-value="100" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_200" name="taken_200" data-value="200" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_500" name="taken_500" data-value="500" min="0" value="0" type="number" class="form-control" required></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table class="table table-bordered">
|
||||
<tr style="font-weight:bold;">
|
||||
<td>2€</td>
|
||||
<td>1€</td>
|
||||
<td>0.50€</td>
|
||||
<td>0.20€</td>
|
||||
<td>0.10€</td>
|
||||
<td>0.05€</td>
|
||||
<td>0.02€</td>
|
||||
<td>0.01€</td>
|
||||
<tr>
|
||||
<tr>
|
||||
<td><input id="id_taken_2" name="taken_2" data-value="2" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_1" name="taken_1" data-value="1" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_05" name="taken_05" data-value="0.5" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_02" name="taken_02" data-value="0.2" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_01" name="taken_01" data-value="0.1" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_005" name="taken_005" data-value="0.05" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_002" name="taken_002" data-value="0.02" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_taken_001" name="taken_001" data-value="0.01" min="0" value="0" type="number" class="form-control" required></td>
|
||||
</tr>
|
||||
</table>
|
||||
Chèque: <input id="id_taken_cheque" name="taken_cheque" data-value="1" min="0" step="0.01" value="0" type="number" class="form-control" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content-right-block">
|
||||
<h2>En caisse</h2>
|
||||
<div id="detail_balance">
|
||||
<table class="table table-bordered">
|
||||
<tr style="font-weight:bold;">
|
||||
<td>5€</td>
|
||||
<td>10€</td>
|
||||
<td>20€</td>
|
||||
<td>50€</td>
|
||||
<td>100€</td>
|
||||
<td>200€</td>
|
||||
<td>500€</td>
|
||||
<tr>
|
||||
<tr>
|
||||
<td><input id="id_balance_5" name="balance_5" data-value="5" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_10" name="balance_10" data-value="10" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_20" name="balance_20" data-value="20" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_50" name="balance_50" data-value="50" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_100" name="balance_100" data-value="100" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_200" name="balance_200" data-value="200" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_500" name="balance_500" data-value="500" min="0" value="0" type="number" class="form-control" required></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table class="table table-bordered">
|
||||
<tr style="font-weight:bold;">
|
||||
<td>2€</td>
|
||||
<td>1€</td>
|
||||
<td>0.50€</td>
|
||||
<td>0.20€</td>
|
||||
<td>0.10€</td>
|
||||
<td>0.05€</td>
|
||||
<td>0.02€</td>
|
||||
<td>0.01€</td>
|
||||
<tr>
|
||||
<tr>
|
||||
<td><input id="id_balance_2" name="balance_2" data-value="2" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_1" name="balance_1" data-value="1" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_05" name="balance_05" data-value="0.5" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_02" name="balance_02" data-value="0.2" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_01" name="balance_01" data-value="0.1" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_005" name="balance_005" data-value="0.05" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_002" name="balance_002" data-value="0.02" min="0" value="0" type="number" class="form-control" required></td>
|
||||
<td><input id="id_balance_001" name="balance_001" data-value="0.01" min="0" value="0" type="number" class="form-control" required></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('#id_not_count').on('change', function() {
|
||||
if ($(this).prop('checked')) {
|
||||
$('#detail_balance input').prop('disabled', true);
|
||||
} else {
|
||||
$('#detail_balance input').prop('disabled', false);
|
||||
}
|
||||
updateAmounts();
|
||||
});
|
||||
|
||||
$('#detail_balance input, #detail_taken input').on('input', function() {
|
||||
updateAmounts();
|
||||
});
|
||||
|
||||
function getTotal(id_container) {
|
||||
var total = 0;
|
||||
$('#'+id_container+' input').each(function() {
|
||||
total += parseFloat($(this).attr('data-value')) * parseFloat($(this).val());
|
||||
});
|
||||
return total;
|
||||
}
|
||||
|
||||
function updateAmounts() {
|
||||
var balance_old = parseFloat($('#balance_old').text());
|
||||
var taken = getTotal('detail_taken');
|
||||
if ($('#id_not_count').prop('checked')) {
|
||||
var error = 0;
|
||||
var balance_new = balance_old - taken;
|
||||
} else {
|
||||
var balance_new = getTotal('detail_balance');
|
||||
var error = balance_new + taken - balance_old;
|
||||
}
|
||||
$('#balance_new').text(balance_new.toFixed(2));
|
||||
$('#amount_taken').text(taken.toFixed(2));
|
||||
$('#amount_error').text(error.toFixed(2));
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -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,6 +458,7 @@ class CheckoutStatementCreate(SuccessMessageMixin, CreateView):
|
|||
return self.form_invalid(form)
|
||||
# Creating
|
||||
form.instance.amount_taken = getAmountTaken(form.instance)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue