forked from DGNum/gestioCOF
Merge branch 'Aufinal/history_form' into 'master'
On utilise un vrai formulaire pour l'historique Closes #242 See merge request klub-dev-ens/gestioCOF!461
This commit is contained in:
commit
84ff0d7182
8 changed files with 73 additions and 72 deletions
|
@ -7,6 +7,7 @@ from django.core import validators
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.forms import modelformset_factory
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from djconfig.forms import ConfigForm
|
||||
|
||||
from gestioncof.models import CofProfile
|
||||
|
@ -482,10 +483,23 @@ class KFetConfigForm(ConfigForm):
|
|||
|
||||
|
||||
class FilterHistoryForm(forms.Form):
|
||||
checkouts = forms.ModelMultipleChoiceField(queryset=Checkout.objects.all())
|
||||
accounts = forms.ModelMultipleChoiceField(queryset=Account.objects.all())
|
||||
from_date = forms.DateTimeField(widget=DateTimeWidget)
|
||||
to_date = forms.DateTimeField(widget=DateTimeWidget)
|
||||
start = forms.DateTimeField(label=_("De"), widget=DateTimeWidget, required=False)
|
||||
end = forms.DateTimeField(label=_("À"), widget=DateTimeWidget, required=False)
|
||||
checkout = forms.ModelChoiceField(
|
||||
label=_("Caisse"),
|
||||
queryset=Checkout.objects.all(),
|
||||
required=False,
|
||||
empty_label=_("Toutes les caisses"),
|
||||
)
|
||||
account = forms.ModelChoiceField(
|
||||
label=_("Compte"),
|
||||
queryset=Account.objects.all(),
|
||||
required=False,
|
||||
empty_label=_("Tous les comptes"),
|
||||
)
|
||||
|
||||
transfers_only = forms.BooleanField(widget=forms.HiddenInput, required=False)
|
||||
opes_only = forms.BooleanField(widget=forms.HiddenInput, required=False)
|
||||
|
||||
|
||||
# -----
|
||||
|
|
|
@ -109,3 +109,7 @@
|
|||
#history .entry .glyphicon {
|
||||
padding-left:15px;
|
||||
}
|
||||
|
||||
#history-form .form-group {
|
||||
position: relative;
|
||||
}
|
||||
|
|
|
@ -205,17 +205,21 @@ function KHistory(options = {}) {
|
|||
$group.find('.amount').text(amount);
|
||||
}
|
||||
|
||||
this.fetch = function (fetch_options) {
|
||||
options = $.extend({}, this.fetch_options, fetch_options);
|
||||
var that = this;
|
||||
this.fetch = function (fetch_options = {}) {
|
||||
if (typeof (fetch_options) == "string")
|
||||
data = fetch_options
|
||||
else
|
||||
data = $.extend({}, this.fetch_options, fetch_options);
|
||||
|
||||
return $.ajax({
|
||||
context: this,
|
||||
dataType: "json",
|
||||
url: django_urls["kfet.history.json"](),
|
||||
method: "POST",
|
||||
data: options,
|
||||
method: "GET",
|
||||
data: data,
|
||||
}).done(function (data) {
|
||||
for (let group of data['groups']) {
|
||||
that.add_history_group(group);
|
||||
this.add_history_group(group);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ $(document).ready(function() {
|
|||
khistory = new KHistory({
|
||||
display_trigramme: false,
|
||||
fetch_options: {
|
||||
'accounts': [{{ account.pk }}],
|
||||
account: {{ account.pk }},
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends 'kfet/base_col_2.html' %}
|
||||
{% load l10n staticfiles widget_tweaks %}
|
||||
{% load l10n staticfiles widget_tweaks bootstrap %}
|
||||
|
||||
{% block extra_head %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'kfet/vendor/multiple-select/multiple-select.css' %}">
|
||||
|
@ -20,13 +20,8 @@
|
|||
<span id="nb_opes"></span>
|
||||
<span class="sub">opérations</span>
|
||||
</div>
|
||||
<div class="text">
|
||||
<ul class="list-unstyled">
|
||||
<li style="position: relative;"><b>De</b> {{ filter_form.from_date|add_class:"form-control" }}</li>
|
||||
<li style="position: relative;"><b>à</b> {{ filter_form.to_date|add_class:"form-control" }}</li>
|
||||
<li><b>Caisses</b> {{ filter_form.checkouts }}</li>
|
||||
<li><b>Comptes</b> {{ filter_form.accounts }}</li>
|
||||
</ul>
|
||||
<div class="text" id="history-form">
|
||||
{{ filter_form|bootstrap}}
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<button class="btn btn-primary" id="btn-fetch">Valider</button>
|
||||
|
@ -48,30 +43,13 @@ $(document).ready(function() {
|
|||
|
||||
khistory = new KHistory();
|
||||
|
||||
var $from_date = $('#id_from_date');
|
||||
var $to_date = $('#id_to_date');
|
||||
var $checkouts = $('#id_checkouts');
|
||||
var $accounts = $('#id_accounts');
|
||||
|
||||
function getSelectedMultiple($el) {
|
||||
var selected = [];
|
||||
$el.find(':selected').each(function() {
|
||||
selected.push($(this).val())
|
||||
});
|
||||
return selected;
|
||||
}
|
||||
var $from_date = $('#id_start');
|
||||
var $to_date = $('#id_end');
|
||||
var $checkout = $('#id_checkout');
|
||||
var $account = $('#id_account');
|
||||
|
||||
function getHistory() {
|
||||
var data = {};
|
||||
if ($from_date.val())
|
||||
data['from'] = moment($from_date.val()).format('YYYY-MM-DD HH:mm:ss');
|
||||
if ($to_date.val())
|
||||
data['to'] = moment($to_date.val()).format('YYYY-MM-DD HH:mm:ss');
|
||||
var checkouts = getSelectedMultiple($checkouts);
|
||||
if ($checkouts)
|
||||
data['checkouts'] = checkouts;
|
||||
var accounts = getSelectedMultiple($accounts);
|
||||
data['accounts'] = accounts;
|
||||
data = $("#history-form").find("input, select, textarea").serialize();
|
||||
|
||||
khistory.fetch(data).done(function () {
|
||||
var nb_opes = khistory.$container.find('.entry:not(.canceled)').length;
|
||||
|
@ -84,7 +62,11 @@ $(document).ready(function() {
|
|||
format : 'YYYY-MM-DD HH:mm',
|
||||
stepping : 5,
|
||||
locale : 'fr',
|
||||
showTodayButton: true
|
||||
showTodayButton: true,
|
||||
widgetPositioning: {
|
||||
horizontal: "left",
|
||||
vertical: "bottom",
|
||||
}
|
||||
};
|
||||
|
||||
$from_date.datetimepicker($.extend({}, defaults_datetimepicker, {
|
||||
|
@ -101,14 +83,6 @@ $(document).ready(function() {
|
|||
$('#from_date').data("DateTimePicker").maxDate(e.date);
|
||||
});
|
||||
|
||||
$("select").multipleSelect({
|
||||
width: '100%',
|
||||
filter: true,
|
||||
allSelected: " ",
|
||||
selectAllText: "Tout-te-s",
|
||||
countSelected: "# sur %"
|
||||
});
|
||||
|
||||
$("#btn-fetch").on('click', function() {
|
||||
khistory.reset();
|
||||
getHistory();
|
||||
|
|
|
@ -1142,8 +1142,8 @@ $(document).ready(function() {
|
|||
|
||||
khistory = new KHistory({
|
||||
fetch_options: {
|
||||
from: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'),
|
||||
opesonly: true,
|
||||
start: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'),
|
||||
opes_only: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ $(document).ready(function() {
|
|||
|
||||
var khistory = new KHistory({
|
||||
fetch_options:{
|
||||
transfersonly: true,
|
||||
transfers_only: true,
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.contrib.messages.views import SuccessMessageMixin
|
|||
from django.db import transaction
|
||||
from django.db.models import Count, F, Prefetch, Q, Sum
|
||||
from django.forms import formset_factory
|
||||
from django.http import Http404, JsonResponse
|
||||
from django.http import Http404, HttpResponseBadRequest, JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
|
@ -1407,12 +1407,17 @@ def cancel_operations(request):
|
|||
@login_required
|
||||
def history_json(request):
|
||||
# Récupération des paramètres
|
||||
from_date = request.POST.get("from", None)
|
||||
to_date = request.POST.get("to", None)
|
||||
checkouts = request.POST.getlist("checkouts[]", None)
|
||||
accounts = request.POST.getlist("accounts[]", None)
|
||||
transfers_only = request.POST.get("transfersonly", False)
|
||||
opes_only = request.POST.get("opesonly", False)
|
||||
form = FilterHistoryForm(request.GET)
|
||||
|
||||
if not form.is_valid():
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
start = form.cleaned_data["start"]
|
||||
end = form.cleaned_data["end"]
|
||||
account = form.cleaned_data["account"]
|
||||
checkout = form.cleaned_data["checkout"]
|
||||
transfers_only = form.cleaned_data["transfers_only"]
|
||||
opes_only = form.cleaned_data["opes_only"]
|
||||
|
||||
# Construction de la requête (sur les transferts) pour le prefetch
|
||||
|
||||
|
@ -1421,9 +1426,9 @@ def history_json(request):
|
|||
)
|
||||
|
||||
# Le check sur les comptes est dans le prefetch pour les transferts
|
||||
if accounts:
|
||||
if account:
|
||||
transfer_queryset_prefetch = transfer_queryset_prefetch.filter(
|
||||
Q(from_acc__in=accounts) | Q(to_acc__in=accounts)
|
||||
Q(from_acc=account) | Q(to_acc=account)
|
||||
)
|
||||
|
||||
if not request.user.has_perm("kfet.is_team"):
|
||||
|
@ -1458,21 +1463,21 @@ def history_json(request):
|
|||
)
|
||||
|
||||
# Application des filtres
|
||||
if from_date:
|
||||
opegroups = opegroups.filter(at__gte=from_date)
|
||||
transfergroups = transfergroups.filter(at__gte=from_date)
|
||||
if to_date:
|
||||
opegroups = opegroups.filter(at__lt=to_date)
|
||||
transfergroups = transfergroups.filter(at__lt=to_date)
|
||||
if checkouts:
|
||||
opegroups = opegroups.filter(checkout__in=checkouts)
|
||||
if start:
|
||||
opegroups = opegroups.filter(at__gte=start)
|
||||
transfergroups = transfergroups.filter(at__gte=start)
|
||||
if end:
|
||||
opegroups = opegroups.filter(at__lt=end)
|
||||
transfergroups = transfergroups.filter(at__lt=end)
|
||||
if checkout:
|
||||
opegroups = opegroups.filter(checkout__in=checkout)
|
||||
transfergroups = TransferGroup.objects.none()
|
||||
if transfers_only:
|
||||
opegroups = OperationGroup.objects.none()
|
||||
if opes_only:
|
||||
transfergroups = TransferGroup.objects.none()
|
||||
if accounts:
|
||||
opegroups = opegroups.filter(on_acc__in=accounts)
|
||||
if account:
|
||||
opegroups = opegroups.filter(on_acc=account)
|
||||
# Un non-membre de l'équipe n'a que accès à son historique
|
||||
if not request.user.has_perm("kfet.is_team"):
|
||||
opegroups = opegroups.filter(on_acc=request.user.profile.account_kfet)
|
||||
|
|
Loading…
Reference in a new issue