forked from DGNum/gestioCOF
Ajout des relevés
This commit is contained in:
parent
fb8882d06e
commit
996baa944c
9 changed files with 147 additions and 20 deletions
|
@ -2,7 +2,8 @@ from django import forms
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.contrib.auth.models import User
|
||||
from django.forms import modelformset_factory
|
||||
from kfet.models import Account, Checkout, Article, OperationGroup, Operation
|
||||
from kfet.models import (Account, Checkout, Article, OperationGroup, Operation,
|
||||
CheckoutStatement)
|
||||
from gestioncof.models import CofProfile
|
||||
|
||||
# -----
|
||||
|
@ -97,6 +98,11 @@ class CheckoutRestrictForm(CheckoutForm):
|
|||
class Meta(CheckoutForm.Meta):
|
||||
fields = ['name', 'valid_from', 'valid_to']
|
||||
|
||||
class CheckoutStatementForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = CheckoutStatement
|
||||
fields = ['balance_new', 'amount_taken']
|
||||
|
||||
# -----
|
||||
# Article forms
|
||||
# -----
|
||||
|
|
|
@ -6,6 +6,7 @@ from django.contrib.auth.models import User
|
|||
from gestioncof.models import CofProfile
|
||||
from django.utils.six.moves import reduce
|
||||
from django.utils import timezone
|
||||
from django.db import transaction
|
||||
from datetime import date, timedelta
|
||||
import re
|
||||
|
||||
|
@ -260,6 +261,22 @@ class CheckoutStatement(models.Model):
|
|||
amount_error = models.DecimalField(max_digits = 6, decimal_places = 2)
|
||||
at = models.DateTimeField(auto_now_add = True)
|
||||
|
||||
def __str__(self):
|
||||
return '%s %s' % (self.checkout, self.at)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.pk:
|
||||
checkout_id = self.checkout_id
|
||||
self.balance_old = (Checkout.objects
|
||||
.values_list('balance', flat=True).get(pk=checkout_id))
|
||||
self.amount_error = (
|
||||
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)
|
||||
else:
|
||||
super(CheckoutStatement, self).save(*args, **kwargs)
|
||||
|
||||
class ArticleCategory(models.Model):
|
||||
name = models.CharField(max_length = 45)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<p>Statut COF: {{ account.is_cof }}</p>
|
||||
<p>Compte gelé: {{ account.is_frozen }}</p>
|
||||
<p>Solde: {{ account.balance }} €</p>
|
||||
{% if account.balance != account.real_balance %}
|
||||
{% if account.negative.balance_offset %}
|
||||
<p>Solde réel: {{ account.real_balance }} €</p>
|
||||
{% endif %}
|
||||
{% if account.negative.authorized_overdraft %}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<ul>
|
||||
{% for checkout in checkouts %}
|
||||
<li><a href="{% url 'kfet.checkout.update' checkout.pk %}">{{ checkout }}</a></li>
|
||||
<li><a href="{% url 'kfet.checkout.read' checkout.pk %}">{{ checkout }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
|
|
@ -12,10 +12,30 @@
|
|||
</p>
|
||||
{% endif %}
|
||||
|
||||
<p>
|
||||
<a href="{% url 'kfet.checkoutstatement.create' checkout.pk %}">
|
||||
Effectuer un relevé
|
||||
</a>
|
||||
<p>
|
||||
|
||||
<p>Nom: {{ checkout.name }}</p>
|
||||
<p>Valide du {{ checkout.valid_from|date:'l j F Y, G:i' }} au {{ checkout.valid_to|date:'l j F Y, G:i' }}</p>
|
||||
<p>Créée par: {{ checkout.created_by }}</p>
|
||||
<p>Balance: {{ checkout.balance }} €</p>
|
||||
<p>Protected: {{ checkout.is_protected }}</p>
|
||||
|
||||
Relevés:
|
||||
{% with statements=checkout.statements.all %}
|
||||
{% if not statements %}
|
||||
Pas de relevé
|
||||
{% else %}
|
||||
<ul>
|
||||
{% for statement in statements %}
|
||||
<li>{{ statement }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
||||
|
|
13
kfet/templates/kfet/checkoutstatement.html
Normal file
13
kfet/templates/kfet/checkoutstatement.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
{% extends "kfet/base.html" %}
|
||||
|
||||
{% block title %}Relevés{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<ul>
|
||||
{% for statement in checkoutstatements %}
|
||||
<li>{{ statement }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
15
kfet/templates/kfet/checkoutstatement_create.html
Normal file
15
kfet/templates/kfet/checkoutstatement_create.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
{% extends "kfet/base.html" %}
|
||||
|
||||
{% block title %}Nouveau relevé{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
En caisse : {{ checkout.balance }}
|
||||
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Enregistrer">
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
43
kfet/urls.py
43
kfet/urls.py
|
@ -12,29 +12,29 @@ urlpatterns = [
|
|||
# -----
|
||||
|
||||
# Account - General
|
||||
url(r'^account/$', views.account,
|
||||
url(r'^accounts/$', views.account,
|
||||
name = 'kfet.account'),
|
||||
url(r'^account/is_validandfree$', views.account_is_validandfree_ajax,
|
||||
url(r'^accounts/is_validandfree$', views.account_is_validandfree_ajax,
|
||||
name = 'kfet.account.is_validandfree.ajax'),
|
||||
|
||||
# Account - Create
|
||||
url(r'^account/new$', views.account_create,
|
||||
url(r'^accounts/new$', views.account_create,
|
||||
name = 'kfet.account.create'),
|
||||
url(r'^account/new/user/(?P<username>.+)$', views.account_create_ajax,
|
||||
url(r'^accounts/new/user/(?P<username>.+)$', views.account_create_ajax,
|
||||
name = 'kfet.account.create.fromuser'),
|
||||
url(r'^account/new/clipper/(?P<login_clipper>.+)$', views.account_create_ajax,
|
||||
url(r'^accounts/new/clipper/(?P<login_clipper>.+)$', views.account_create_ajax,
|
||||
name = 'kfet.account.create.fromclipper'),
|
||||
url(r'^account/new/empty$', views.account_create_ajax,
|
||||
url(r'^accounts/new/empty$', views.account_create_ajax,
|
||||
name = 'kfet.account.create.empty'),
|
||||
url(r'^autocomplete/account_new$', autocomplete.account_create,
|
||||
name = 'kfet.account.create.autocomplete'),
|
||||
|
||||
# Account - Read
|
||||
url(r'^account/(?P<trigramme>.{3})$', views.account_read,
|
||||
url(r'^accounts/(?P<trigramme>.{3})$', views.account_read,
|
||||
name = 'kfet.account.read'),
|
||||
|
||||
# Account - Update
|
||||
url(r'^account/(?P<trigramme>.{3})/edit$', views.account_update,
|
||||
url(r'^accounts/(?P<trigramme>.{3})/edit$', views.account_update,
|
||||
name = 'kfet.account.update'),
|
||||
|
||||
# -----
|
||||
|
@ -42,40 +42,51 @@ urlpatterns = [
|
|||
# -----
|
||||
|
||||
# Checkout - General
|
||||
url('^checkout/$',
|
||||
url('^checkouts/$',
|
||||
permission_required('kfet.is_team')(views.CheckoutList.as_view()),
|
||||
name = 'kfet.checkout'),
|
||||
# Checkout - Create
|
||||
url('^checkout/new$',
|
||||
url('^checkouts/new$',
|
||||
permission_required('kfet.is_team')(views.CheckoutCreate.as_view()),
|
||||
name = 'kfet.checkout.create'),
|
||||
# Checkout - Read
|
||||
url('^checkout/(?P<pk>\d+)$',
|
||||
url('^checkouts/(?P<pk>\d+)$',
|
||||
permission_required('kfet.is_team')(views.CheckoutRead.as_view()),
|
||||
name = 'kfet.checkout.read'),
|
||||
# Checkout - Update
|
||||
url('^checkout/(?P<pk>\d+)/edit$',
|
||||
url('^checkouts/(?P<pk>\d+)/edit$',
|
||||
permission_required('kfet.is_team')(views.CheckoutUpdate.as_view()),
|
||||
name = 'kfet.checkout.update'),
|
||||
|
||||
### Checkout Statements urls
|
||||
|
||||
# Checkout Statement - General
|
||||
url('^checkouts/statements/$',
|
||||
permission_required('kfet.is_team')(views.CheckoutStatementList.as_view()),
|
||||
name = 'kfet.checkoutstatement'),
|
||||
# Checkout Statement - Create
|
||||
url('^checkouts/(?P<pk_checkout>\d+)/statements/add',
|
||||
permission_required('kfet.is_team')(views.CheckoutStatementCreate.as_view()),
|
||||
name = 'kfet.checkoutstatement.create'),
|
||||
|
||||
# -----
|
||||
# Article urls
|
||||
# -----
|
||||
|
||||
# Article - General
|
||||
url('^article/$',
|
||||
url('^articles/$',
|
||||
permission_required('kfet.is_team')(views.ArticleList.as_view()),
|
||||
name = 'kfet.article'),
|
||||
# Article - Create
|
||||
url('^article/new$',
|
||||
url('^articles/new$',
|
||||
permission_required('kfet.is_team')(views.ArticleCreate.as_view()),
|
||||
name = 'kfet.article.create'),
|
||||
# Article - Read
|
||||
url('^article/(?P<pk>\d+)$',
|
||||
url('^articles/(?P<pk>\d+)$',
|
||||
permission_required('kfet.is_team')(views.ArticleRead.as_view()),
|
||||
name = 'kfet.article.read'),
|
||||
# Article - Update
|
||||
url('^article/(?P<pk>\d+)/edit$',
|
||||
url('^articles/(?P<pk>\d+)/edit$',
|
||||
permission_required('kfet.is_team')(views.ArticleUpdate.as_view()),
|
||||
name = 'kfet.article.update'),
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ from django.db import IntegrityError, transaction
|
|||
from django.db.models import F
|
||||
from django.utils import timezone
|
||||
from gestioncof.models import CofProfile, Clipper
|
||||
from kfet.models import Account, Checkout, Article, Settings, AccountNegative
|
||||
from kfet.models import (Account, Checkout, Article, Settings, AccountNegative,
|
||||
CheckoutStatement)
|
||||
from kfet.forms import *
|
||||
from collections import defaultdict
|
||||
|
||||
|
@ -303,6 +304,50 @@ class CheckoutUpdate(SuccessMessageMixin, UpdateView):
|
|||
# Updating
|
||||
return super(CheckoutUpdate, self).form_valid(form)
|
||||
|
||||
# -----
|
||||
# Checkout Statement views
|
||||
# -----
|
||||
|
||||
# Checkout Statement - General
|
||||
|
||||
class CheckoutStatementList(ListView):
|
||||
model = CheckoutStatement
|
||||
queryset = CheckoutStatement.objects.order_by('-at')
|
||||
template_name = 'kfet/checkoutstatement.html'
|
||||
context_object_name= 'checkoutstatements'
|
||||
|
||||
# Checkout Statement - Create
|
||||
|
||||
class CheckoutStatementCreate(SuccessMessageMixin, CreateView):
|
||||
model = CheckoutStatement
|
||||
template_name = 'kfet/checkoutstatement_create.html'
|
||||
form_class = CheckoutStatementForm
|
||||
success_message = 'Nouveau relevé : %(checkout)s - %(at)s'
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('kfet.checkout.read', kwargs={'pk':self.kwargs['pk_checkout']})
|
||||
|
||||
def get_success_message(self, cleaned_data):
|
||||
return self.success_message % dict(
|
||||
cleaned_data,
|
||||
checkout = self.object.checkout.name,
|
||||
at = self.object.at)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CheckoutStatementCreate, self).get_context_data(**kwargs)
|
||||
checkout = Checkout.objects.get(pk=self.kwargs['pk_checkout'])
|
||||
context['checkout'] = checkout
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
# Checking permission
|
||||
if not self.request.user.has_perm('kfet.add_checkoutstatement'):
|
||||
raise PermissionDenied
|
||||
# Creating
|
||||
form.instance.checkout_id = self.kwargs['pk_checkout']
|
||||
form.instance.by = self.request.user.profile.account_kfet
|
||||
return super(CheckoutStatementCreate, self).form_valid(form)
|
||||
|
||||
# -----
|
||||
# Article views
|
||||
# -----
|
||||
|
|
Loading…
Reference in a new issue