Commandes sur #13
- Un commentaire est demandé. Une permission est nécessaire (afin d'enregistrer la personne ayant enregistré la commande) - Fix annulation K-Psul. Appuyer sur Suppr appelait tout le temps `cancelOperations` même si aucune opération à supprimer n'était sélectionné.
This commit is contained in:
parent
bbbfd4aef5
commit
9e66137c09
5 changed files with 71 additions and 12 deletions
|
@ -222,7 +222,7 @@ class KPsulOperationGroupForm(forms.ModelForm):
|
|||
widget = forms.HiddenInput())
|
||||
class Meta:
|
||||
model = OperationGroup
|
||||
fields = ['on_acc', 'checkout']
|
||||
fields = ['on_acc', 'checkout', 'comment']
|
||||
widgets = {
|
||||
'on_acc' : forms.HiddenInput(),
|
||||
}
|
||||
|
|
18
kfet/migrations/0035_auto_20160823_1505.py
Normal file
18
kfet/migrations/0035_auto_20160823_1505.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', '0034_auto_20160823_0206'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='globalpermissions',
|
||||
options={'managed': False, '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'), ('perform_commented_operations', 'Enregistrer des commandes avec commentaires'))},
|
||||
),
|
||||
]
|
|
@ -86,6 +86,10 @@ class Account(models.Model):
|
|||
def is_cash(self):
|
||||
return self.trigramme == 'LIQ'
|
||||
|
||||
@property
|
||||
def need_comment(self):
|
||||
return self.trigramme == '#13'
|
||||
|
||||
@staticmethod
|
||||
def is_validandfree(trigramme):
|
||||
data = { 'is_valid' : False, 'is_free' : False }
|
||||
|
@ -109,13 +113,13 @@ class Account(models.Model):
|
|||
if self.is_cash:
|
||||
# Yes, so no perms and no stop
|
||||
return set(), False
|
||||
if self.need_comment:
|
||||
perms.add('kfet.perform_commented_operations')
|
||||
# Checking is frozen account
|
||||
if self.is_frozen:
|
||||
perms.add('kfet.override_frozen_protection')
|
||||
new_balance = self.balance + amount
|
||||
if new_balance < 0 and amount < 0:
|
||||
print(new_balance)
|
||||
print(amount)
|
||||
# Retrieving overdraft amount limit
|
||||
if (hasattr(self, 'negative')
|
||||
and self.negative.authz_overdraft_amount is not None):
|
||||
|
@ -518,6 +522,7 @@ class GlobalPermissions(models.Model):
|
|||
('cancel_old_operations', 'Annuler des commandes non récentes'),
|
||||
('manage_perms', 'Gérer les permissions K-Fêt'),
|
||||
('manage_addcosts', 'Gérer les majorations'),
|
||||
('perform_commented_operations', 'Enregistrer des commandes avec commentaires'),
|
||||
)
|
||||
|
||||
class Settings(models.Model):
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
|
||||
{% csrf_token %}
|
||||
|
||||
<form id="operationgroup_form">{{ operationgroup_form }}</form>
|
||||
|
||||
<div class="row kpsul_top">
|
||||
<div class="col-sm-8">
|
||||
<div class="row" id="account">
|
||||
|
@ -100,9 +98,8 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<form id="operation_formset" style="display:none">
|
||||
{{ operation_formset.as_p }}
|
||||
</form>
|
||||
<form id="operationgroup_form" style="display:none;">{{ operationgroup_form }}</form>
|
||||
<form id="operation_formset" style="display:none;">{{ operation_formset }}</form>
|
||||
|
||||
<div style="display:none;" id="operation_empty_html" data-opeindex="__prefix__">
|
||||
{{ operation_formset.empty_form }}
|
||||
|
@ -351,7 +348,7 @@ $(document).ready(function() {
|
|||
callback(password);
|
||||
},
|
||||
onOpen: function() {
|
||||
var that = this
|
||||
var that = this;
|
||||
this.$content.find('input').on('keypress', function(e) {
|
||||
if (e.keyCode == 13)
|
||||
that.$confirmButton.click();
|
||||
|
@ -361,6 +358,34 @@ $(document).ready(function() {
|
|||
});
|
||||
}
|
||||
|
||||
function askComment(callback) {
|
||||
var comment = $('#id_comment').val();
|
||||
$.confirm({
|
||||
title: 'Commentaire requis',
|
||||
content: '<input type="text" name="comment_opegroup" value="'+comment+'" autofocus>',
|
||||
backgroundDismiss: true,
|
||||
animation: 'top',
|
||||
closeAnimation: 'bottom',
|
||||
keyboardEnabled: true,
|
||||
confirm: function() {
|
||||
$('#id_comment').val(this.$content.find('input').val());
|
||||
callback();
|
||||
},
|
||||
onOpen: function() {
|
||||
var that = this;
|
||||
this.$content.find('input').on('keypress', function(e) {
|
||||
if (e.keyCode == 13)
|
||||
that.$confirmButton.click();
|
||||
});
|
||||
},
|
||||
onClose: function() { this._lastFocused = articleSelect; }
|
||||
});
|
||||
}
|
||||
|
||||
function resetComment() {
|
||||
$('#id_comment').val('');
|
||||
}
|
||||
|
||||
// -----
|
||||
// Errors ajax
|
||||
// -----
|
||||
|
@ -438,7 +463,11 @@ $(document).ready(function() {
|
|||
requestAuth(data, performOperations);
|
||||
break;
|
||||
case 400:
|
||||
displayErrors(getErrorsHtml(data));
|
||||
if ('need_comment' in data['errors']) {
|
||||
askComment(performOperations);
|
||||
} else {
|
||||
displayErrors(getErrorsHtml(data));
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
@ -705,7 +734,6 @@ $(document).ready(function() {
|
|||
|
||||
function addPurchase(id, nb) {
|
||||
var amount_euro = amountEuroPurchase(id, nb).toFixed(2);
|
||||
console.log(amount_euro);
|
||||
var index = addPurchaseToFormset(article_data[1], nb, amount_euro);
|
||||
article_basket_html = $(item_basket_default_html);
|
||||
article_basket_html
|
||||
|
@ -1165,7 +1193,8 @@ $(document).ready(function() {
|
|||
history_container.find('.ope.ui-selected').each(function () {
|
||||
opes_to_cancel.push($(this).attr('data-ope'));
|
||||
});
|
||||
cancelOperations(opes_to_cancel);
|
||||
if (opes_to_cancel.length > 0)
|
||||
cancelOperations(opes_to_cancel);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1239,6 +1268,7 @@ $(document).ready(function() {
|
|||
function coolReset(give_tri_focus=true) {
|
||||
resetAccount();
|
||||
resetBasket();
|
||||
resetComment();
|
||||
resetSelectable();
|
||||
if (give_tri_focus)
|
||||
triInput.focus();
|
||||
|
|
|
@ -719,6 +719,12 @@ def kpsul_perform_operations(request):
|
|||
amount = operationgroup.amount)
|
||||
required_perms |= perms
|
||||
|
||||
if operationgroup.on_acc.need_comment:
|
||||
operationgroup.comment = operationgroup.comment.strip()
|
||||
if not operationgroup.comment:
|
||||
data['errors']['need_comment'] = True
|
||||
return JsonResponse(data, status=400)
|
||||
|
||||
if stop or not request.user.has_perms(required_perms):
|
||||
missing_perms = get_missing_perms(required_perms, request.user)
|
||||
if missing_perms:
|
||||
|
|
Loading…
Reference in a new issue