forked from DGNum/gestioCOF
Majoration sur K-Psul
En appuyant sur F9, il est possible de définir une majoration destinée à un compte en donnant le trigramme du compte destinataire et la valeur en euro de la majoration par article
This commit is contained in:
parent
8b66294b41
commit
e27559d123
6 changed files with 141 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
|||
from decimal import Decimal
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.contrib.auth.models import User, Group, Permission
|
||||
|
@ -237,6 +238,23 @@ KPsulOperationFormSet = modelformset_factory(
|
|||
extra = 0,
|
||||
min_num = 1, validate_min = True)
|
||||
|
||||
class AddcostForm(forms.Form):
|
||||
trigramme = forms.CharField(required = False)
|
||||
amount = forms.DecimalField(
|
||||
required = False,
|
||||
max_digits=6,decimal_places=2,min_value=Decimal(0))
|
||||
|
||||
def clean(self):
|
||||
trigramme = self.cleaned_data.get('trigramme')
|
||||
if trigramme:
|
||||
try:
|
||||
Account.objects.get(trigramme=trigramme)
|
||||
except Account.DoesNotExist:
|
||||
raise ValidationError('Compte invalide')
|
||||
else:
|
||||
self.cleaned_data['amount'] = 0
|
||||
super(AddcostForm, self).clean()
|
||||
|
||||
# -----
|
||||
# Settings forms
|
||||
# -----
|
||||
|
|
18
kfet/migrations/0031_auto_20160822_0523.py
Normal file
18
kfet/migrations/0031_auto_20160822_0523.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('kfet', '0030_auto_20160821_0029'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='globalpermissions',
|
||||
options={'permissions': (('is_team', 'Is part of the team'), ('perform_deposit', 'Effectuer une charge'), ('perform_negative_operations', 'Enregistrer des commandes en négatif'), ('override_frozen_protection', "Forcer le gel d'un compte"), ('cancel_old_operations', 'Annuler des commandes non récentes'), ('manage_perms', 'Gérer les permissions K-Fêt'), ('manage_addcosts', 'Gérer les majorations')), 'managed': False},
|
||||
),
|
||||
]
|
|
@ -483,7 +483,8 @@ class GlobalPermissions(models.Model):
|
|||
'Enregistrer des commandes en négatif'),
|
||||
('override_frozen_protection', "Forcer le gel d'un compte"),
|
||||
('cancel_old_operations', 'Annuler des commandes non récentes'),
|
||||
('manage_perms', 'Gérer les permissions K-Fêt')
|
||||
('manage_perms', 'Gérer les permissions K-Fêt'),
|
||||
('manage_addcosts', 'Gérer les majorations'),
|
||||
)
|
||||
|
||||
class Settings(models.Model):
|
||||
|
|
|
@ -534,8 +534,8 @@ $(document).ready(function() {
|
|||
var articleSelect = $('#article_autocomplete');
|
||||
var articleId = $('#article_id');
|
||||
var articleNb = $('#article_number');
|
||||
// 8:Backspace|9:Tab|13:Enter|46:DEL|112-117:F1-6|121:F10|122:F11|123:F12
|
||||
var normalKeys = /^(8|9|13|46|112|113|114|115|116|117|121|122|123)$/;
|
||||
// 8:Backspace|9:Tab|13:Enter|46:DEL|112-117:F1-6|120-123:F9-F12
|
||||
var normalKeys = /^(8|9|13|46|112|113|114|115|116|117|120|121|122|123)$/;
|
||||
var articlesList = [];
|
||||
|
||||
function deleteNonMatching(array, str) {
|
||||
|
@ -1023,6 +1023,69 @@ $(document).ready(function() {
|
|||
history_container.children().remove();
|
||||
}
|
||||
|
||||
// -----
|
||||
// Addcost
|
||||
// -----
|
||||
|
||||
function sendAddcost(trigramme, amount, password='') {
|
||||
var data = {
|
||||
trigramme: trigramme,
|
||||
amount: amount,
|
||||
}
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url : "{% url 'kfet.kpsul.update_addcost' %}",
|
||||
method : "POST",
|
||||
data : data,
|
||||
beforeSend: function ($xhr) {
|
||||
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
if (password != '')
|
||||
$xhr.setRequestHeader("KFetPassword", password);
|
||||
},
|
||||
})
|
||||
.done(function(data) {
|
||||
location.reload();
|
||||
})
|
||||
.fail(function($xhr) {
|
||||
var data = $xhr.responseJSON;
|
||||
switch ($xhr.status) {
|
||||
case 403:
|
||||
requestAuth(data, function(password) {
|
||||
sendAddcost(trigramme, amount, password);
|
||||
});
|
||||
break;
|
||||
case 400:
|
||||
displayErrors(getErrorsHtml(data));
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function askAddcost() {
|
||||
$.confirm({
|
||||
title: 'Majoration',
|
||||
content: '<input type="text" placeholder="Trigramme" autocomplete="off" name="trigramme" spellcheck="false" style="text-transform:uppercase" autofocus><input type="number" step="0.01" min="0.01" placeholder="€" name="amount">',
|
||||
backgroundDismiss: true,
|
||||
animation:'top',
|
||||
closeAnimation:'bottom',
|
||||
keyboardEnabled: true,
|
||||
confirm: function() {
|
||||
var trigramme = this.$content.find('input[name=trigramme]').val().toUpperCase();
|
||||
var amount = this.$content.find('input[name=amount]').val();
|
||||
sendAddcost(trigramme, amount);
|
||||
},
|
||||
onOpen: function() {
|
||||
var that = this
|
||||
this.$content.find('input[name=amount]').on('keypress', function(e) {
|
||||
if (e.keyCode == 13)
|
||||
that.$confirmButton.click();
|
||||
});
|
||||
},
|
||||
onClose: function() { this._lastFocused = articleSelect; }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// -----
|
||||
// Cancel from history
|
||||
// -----
|
||||
|
@ -1156,6 +1219,10 @@ $(document).ready(function() {
|
|||
articleSelect.focus();
|
||||
}
|
||||
return false;
|
||||
case 120:
|
||||
// F9 - Addcost
|
||||
askAddcost();
|
||||
return false;
|
||||
case 121:
|
||||
// F10 - Hard reset
|
||||
hardReset();
|
||||
|
|
|
@ -119,6 +119,8 @@ urlpatterns = [
|
|||
name = 'kfet.kpsul.history'),
|
||||
url('^k-psul/articles_data', views.kpsul_articles_data,
|
||||
name = 'kfet.kpsul.articles_data'),
|
||||
url('^k-psul/update_addcost$', views.kpsul_update_addcost,
|
||||
name = 'kfet.kpsul.update_addcost'),
|
||||
|
||||
# -----
|
||||
# Settings urls
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.core.cache import cache
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
|
@ -518,6 +519,37 @@ def kpsul_checkout_data(request):
|
|||
raise http404
|
||||
return JsonResponse(data)
|
||||
|
||||
@permission_required('kfet.is_team')
|
||||
def kpsul_update_addcost(request):
|
||||
addcost_form = AddcostForm(request.POST)
|
||||
|
||||
if not addcost_form.is_valid():
|
||||
print(addcost_form.errors)
|
||||
return JsonResponse({}, status=400)
|
||||
required_perms = ['kfet.manage_addcosts']
|
||||
if not request.user.has_perms(required_perms):
|
||||
data = {
|
||||
'errors': {
|
||||
'missing_perms': get_missing_perms(required_perms, request.user)
|
||||
}
|
||||
}
|
||||
return JsonResponse(data, status=403)
|
||||
|
||||
trigramme = addcost_form.cleaned_data['trigramme']
|
||||
account = trigramme and Account.objects.get(trigramme=trigramme) or None
|
||||
Settings.objects.filter(name='ADDCOST_FOR').update(value_account=account)
|
||||
Settings.objects.filter(name='ADDCOST_AMOUNT').update(value_decimal=addcost_form.cleaned_data['amount'])
|
||||
cache.delete('ADDCOST_FOR')
|
||||
cache.delete('ADDCOST_AMOUNT')
|
||||
data = {
|
||||
'addcost': {
|
||||
'for': trigramme and account.trigramme or None,
|
||||
'amount': addcost_form.cleaned_data['amount'],
|
||||
}
|
||||
}
|
||||
consumers.KPsul.group_send('kfet.kpsul', data)
|
||||
return JsonResponse(data)
|
||||
|
||||
def get_missing_perms(required_perms, user):
|
||||
missing_perms_codenames = [ (perm.split('.'))[1]
|
||||
for perm in required_perms if not user.has_perm(perm)]
|
||||
|
|
Loading…
Reference in a new issue