forked from DGNum/gestioCOF
adapt code to is_checkout removal
This commit is contained in:
parent
cadaf43131
commit
d7740e66fe
6 changed files with 105 additions and 40 deletions
|
@ -313,11 +313,10 @@ class KPsulOperationForm(forms.ModelForm):
|
|||
widget = forms.HiddenInput())
|
||||
class Meta:
|
||||
model = Operation
|
||||
fields = ['type', 'amount', 'is_checkout', 'article', 'article_nb']
|
||||
fields = ['type', 'amount', 'article', 'article_nb']
|
||||
widgets = {
|
||||
'type': forms.HiddenInput(),
|
||||
'amount': forms.HiddenInput(),
|
||||
'is_checkout': forms.HiddenInput(),
|
||||
'article_nb': forms.HiddenInput(),
|
||||
}
|
||||
|
||||
|
@ -333,7 +332,6 @@ class KPsulOperationForm(forms.ModelForm):
|
|||
"Un achat nécessite un article et une quantité")
|
||||
if article_nb < 1:
|
||||
raise ValidationError("Impossible d'acheter moins de 1 article")
|
||||
self.cleaned_data['is_checkout'] = True
|
||||
elif type_ope and type_ope in [Operation.DEPOSIT, Operation.WITHDRAW]:
|
||||
if not amount or article or article_nb:
|
||||
raise ValidationError("Bad request")
|
||||
|
|
23
kfet/migrations/0048_auto_20170324_2313.py
Normal file
23
kfet/migrations/0048_auto_20170324_2313.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('kfet', '0047_auto_20170104_1528'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='operation',
|
||||
name='is_checkout',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='operation',
|
||||
name='type',
|
||||
field=models.CharField(max_length=8, choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial'), ('edit', 'Édition')]),
|
||||
),
|
||||
]
|
|
@ -552,9 +552,9 @@ class Operation(models.Model):
|
|||
|
||||
@property
|
||||
def is_checkout(self):
|
||||
return (self.type == DEPOSIT or
|
||||
self.type == WITHDRAW or
|
||||
(self.type == PURCHASE and self.group and
|
||||
return (self.type == Operation.DEPOSIT or
|
||||
self.type == Operation.WITHDRAW or
|
||||
(self.type == Operation.PURCHASE and self.group and
|
||||
self.group.on_acc.is_cash)
|
||||
)
|
||||
|
||||
|
|
|
@ -31,13 +31,22 @@ function KHistory(options={}) {
|
|||
if (ope['type'] == 'purchase') {
|
||||
infos1 = ope['article_nb'];
|
||||
infos2 = ope['article__name'];
|
||||
} else if (ope['type'] == 'initial') {
|
||||
infos1 = parsed_amount.toFixed(2)+'€';
|
||||
infos2 = 'Initial';
|
||||
} else {
|
||||
infos1 = parsed_amount.toFixed(2)+'€';
|
||||
infos2 = (ope['type'] == 'deposit') ? 'Charge' : 'Retrait';
|
||||
infos2 = ope['is_checkout'] ? infos2 : 'Édition';
|
||||
switch (ope['type']) {
|
||||
case 'initial':
|
||||
infos2 = 'Initial';
|
||||
break;
|
||||
case 'withdraw':
|
||||
infos2 = 'Retrait';
|
||||
break;
|
||||
case 'deposit':
|
||||
infos2 = 'Charge';
|
||||
break;
|
||||
case 'edit':
|
||||
infos2 = 'Édition';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$ope_html
|
||||
|
|
|
@ -794,15 +794,27 @@ $(document).ready(function() {
|
|||
updateBasketRel();
|
||||
}
|
||||
|
||||
function addDeposit(amount, is_checkout=1) {
|
||||
function addDeposit(amount) {
|
||||
var deposit_basket_html = $(item_basket_default_html);
|
||||
var amount = parseFloat(amount).toFixed(2);
|
||||
var index = addDepositToFormset(amount, is_checkout);
|
||||
var text = is_checkout ? 'Charge' : 'Édition';
|
||||
var index = addDepositToFormset(amount);
|
||||
deposit_basket_html
|
||||
.attr('data-opeindex', index)
|
||||
.find('.number').text(amount+"€").end()
|
||||
.find('.name').text(text).end()
|
||||
.find('.name').text('Charge').end()
|
||||
.find('.amount').text(amountToUKF(amount, account_data['is_cof']));
|
||||
basket_container.prepend(deposit_basket_html);
|
||||
updateBasketRel();
|
||||
}
|
||||
|
||||
function addEdit(amount) {
|
||||
var deposit_basket_html = $(item_basket_default_html);
|
||||
var amount = parseFloat(amount).toFixed(2);
|
||||
var index = addEditToFormset(amount);
|
||||
deposit_basket_html
|
||||
.attr('data-opeindex', index)
|
||||
.find('.number').text(amount+"€").end()
|
||||
.find('.name').text('Édition').end()
|
||||
.find('.amount').text(amountToUKF(amount, account_data['is_cof']));
|
||||
basket_container.prepend(deposit_basket_html);
|
||||
updateBasketRel();
|
||||
|
@ -910,10 +922,9 @@ $(document).ready(function() {
|
|||
// Ask deposit or withdraw
|
||||
// -----
|
||||
|
||||
function askDeposit(is_checkout=1) {
|
||||
var title = is_checkout ? 'Montant de la charge' : "Montant de l'édition";
|
||||
function askDeposit() {
|
||||
$.confirm({
|
||||
title: title,
|
||||
title: 'Montant de la charge',
|
||||
content: '<input type="number" step="0.01" min="0.01" on autofocus placeholder="€">',
|
||||
backgroundDismiss: true,
|
||||
animation:'top',
|
||||
|
@ -923,7 +934,34 @@ $(document).ready(function() {
|
|||
var amount = this.$content.find('input').val();
|
||||
if (!$.isNumeric(amount) || amount <= 0)
|
||||
return false;
|
||||
addDeposit(amount, is_checkout);
|
||||
addDeposit(amount);
|
||||
},
|
||||
onOpen: function() {
|
||||
var that = this
|
||||
this.$content.find('input').on('keydown', function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
e.preventDefault();
|
||||
that.$confirmButton.click();
|
||||
}
|
||||
});
|
||||
},
|
||||
onClose: function() { this._lastFocused = (articleSelect.val() ? articleNb : articleSelect) ; }
|
||||
});
|
||||
}
|
||||
|
||||
function askEdit() {
|
||||
$.confirm({
|
||||
title: "Montant de l'édition",
|
||||
content: '<input type="number" step="0.01" min="0.01" on autofocus placeholder="€">',
|
||||
backgroundDismiss: true,
|
||||
animation:'top',
|
||||
closeAnimation:'bottom',
|
||||
keyboardEnabled: true,
|
||||
confirm: function() {
|
||||
var amount = this.$content.find('input').val();
|
||||
if (!$.isNumeric(amount))
|
||||
return false;
|
||||
addEdit(amount);
|
||||
},
|
||||
onOpen: function() {
|
||||
var that = this
|
||||
|
@ -988,7 +1026,7 @@ $(document).ready(function() {
|
|||
var mngmt_total_forms = 1;
|
||||
var prefix_regex = /__prefix__/;
|
||||
|
||||
function addOperationToFormset(type, amount, article='', article_nb='', is_checkout=1) {
|
||||
function addOperationToFormset(type, amount, article='', article_nb='') {
|
||||
var operation_html = operation_empty_html.clone();
|
||||
var index = mngmt_total_forms;
|
||||
|
||||
|
@ -998,8 +1036,7 @@ $(document).ready(function() {
|
|||
.find('#id_form-__prefix__-type').val(type).end()
|
||||
.find('#id_form-__prefix__-amount').val((parseFloat(amount)).toFixed(2)).end()
|
||||
.find('#id_form-__prefix__-article').val(article).end()
|
||||
.find('#id_form-__prefix__-article_nb').val(article_nb).end()
|
||||
.find('#id_form-__prefix__-is_checkout').val(is_checkout);
|
||||
.find('#id_form-__prefix__-article_nb').val(article_nb).end();
|
||||
|
||||
mngmt_total_forms_input.val(index+1);
|
||||
mngmt_total_forms++;
|
||||
|
@ -1014,12 +1051,16 @@ $(document).ready(function() {
|
|||
return index;
|
||||
}
|
||||
|
||||
function addDepositToFormset(amount, is_checkout=1) {
|
||||
return addOperationToFormset('deposit', amount, '', '', is_checkout);
|
||||
function addDepositToFormset(amount) {
|
||||
return addOperationToFormset('deposit', amount, '', '');
|
||||
}
|
||||
|
||||
function addWithdrawToFormset(amount, is_checkout=1) {
|
||||
return addOperationToFormset('withdraw', amount, '', '', is_checkout);
|
||||
function addEditToFormset(amount) {
|
||||
return addOperationToFormset('edit', amount, '', '');
|
||||
}
|
||||
|
||||
function addWithdrawToFormset(amount) {
|
||||
return addOperationToFormset('withdraw', amount, '', '');
|
||||
}
|
||||
|
||||
function addPurchaseToFormset(article_id, article_nb, amount=0) {
|
||||
|
@ -1295,7 +1336,7 @@ $(document).ready(function() {
|
|||
return false;
|
||||
case 119:
|
||||
// F8 - Edition
|
||||
askDeposit(0);
|
||||
askEdit();
|
||||
return false;
|
||||
case 120:
|
||||
// F9 - Addcost
|
||||
|
|
|
@ -138,8 +138,7 @@ def account_create_special(request):
|
|||
ope = Operation.objects.create(
|
||||
group = opegroup,
|
||||
type = Operation.INITIAL,
|
||||
amount = amount,
|
||||
is_checkout = False)
|
||||
amount = amount)
|
||||
messages.success(request, 'Compte créé : %s' % account.trigramme)
|
||||
return redirect('kfet.account.create')
|
||||
except Account.UserHasAccount as e:
|
||||
|
@ -960,10 +959,7 @@ def kpsul_perform_operations(request):
|
|||
operation.amount -= operation.addcost_amount
|
||||
to_addcost_for_balance += operation.addcost_amount
|
||||
if operationgroup.on_acc.is_cash:
|
||||
operation.is_checkout = True
|
||||
to_checkout_balance += -operation.amount
|
||||
else:
|
||||
operation.is_checkout = False
|
||||
if operationgroup.on_acc.is_cof:
|
||||
if is_addcost:
|
||||
operation.addcost_amount = operation.addcost_amount / cof_grant_divisor
|
||||
|
@ -972,12 +968,12 @@ def kpsul_perform_operations(request):
|
|||
else:
|
||||
if operationgroup.on_acc.is_cash:
|
||||
data['errors']['account'] = 'Charge et retrait impossible sur LIQ'
|
||||
to_checkout_balance += operation.amount
|
||||
if operation.type != Operation.EDIT:
|
||||
to_checkout_balance += operation.amount
|
||||
operationgroup.amount += operation.amount
|
||||
if operation.type == Operation.DEPOSIT:
|
||||
required_perms.add('kfet.perform_deposit')
|
||||
if (not operation.is_checkout
|
||||
and operation.type in [Operation.DEPOSIT, Operation.WITHDRAW]):
|
||||
if operation.type == Operation.EDIT:
|
||||
required_perms.add('kfet.edit_balance_account')
|
||||
need_comment = True
|
||||
if operationgroup.on_acc.is_cof:
|
||||
|
@ -1073,7 +1069,6 @@ def kpsul_perform_operations(request):
|
|||
'id': operation.pk, 'type': operation.type, 'amount': operation.amount,
|
||||
'addcost_amount': operation.addcost_amount,
|
||||
'addcost_for__trigramme': is_addcost and addcost_for.trigramme or None,
|
||||
'is_checkout': operation.is_checkout,
|
||||
'article__name': operation.article and operation.article.name or None,
|
||||
'article_nb': operation.article_nb,
|
||||
'group_id': operationgroup.pk,
|
||||
|
@ -1163,11 +1158,11 @@ def kpsul_cancel_operations(request):
|
|||
.order_by('at')
|
||||
.last())
|
||||
if not last_statement or last_statement.at < ope.group.at:
|
||||
if ope.type == Operation.PURCHASE:
|
||||
if ope.is_checkout:
|
||||
if ope.group.on_acc.is_cash:
|
||||
to_checkouts_balances[ope.group.checkout] -= - ope.amount
|
||||
else:
|
||||
to_checkouts_balances[ope.group.checkout] -= ope.amount
|
||||
else:
|
||||
to_checkouts_balances[ope.group.checkout] -= ope.amount
|
||||
|
||||
# Pour les stocks d'articles
|
||||
# Les stocks d'articles dont il y a eu un inventaire depuis la date
|
||||
|
@ -1328,7 +1323,6 @@ def history_json(request):
|
|||
'type' : ope.type,
|
||||
'amount' : ope.amount,
|
||||
'article_nb' : ope.article_nb,
|
||||
'is_checkout' : ope.is_checkout,
|
||||
'addcost_amount': ope.addcost_amount,
|
||||
'canceled_at' : ope.canceled_at,
|
||||
'article__name':
|
||||
|
|
Loading…
Reference in a new issue