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())
|
widget = forms.HiddenInput())
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Operation
|
model = Operation
|
||||||
fields = ['type', 'amount', 'is_checkout', 'article', 'article_nb']
|
fields = ['type', 'amount', 'article', 'article_nb']
|
||||||
widgets = {
|
widgets = {
|
||||||
'type': forms.HiddenInput(),
|
'type': forms.HiddenInput(),
|
||||||
'amount': forms.HiddenInput(),
|
'amount': forms.HiddenInput(),
|
||||||
'is_checkout': forms.HiddenInput(),
|
|
||||||
'article_nb': forms.HiddenInput(),
|
'article_nb': forms.HiddenInput(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +332,6 @@ class KPsulOperationForm(forms.ModelForm):
|
||||||
"Un achat nécessite un article et une quantité")
|
"Un achat nécessite un article et une quantité")
|
||||||
if article_nb < 1:
|
if article_nb < 1:
|
||||||
raise ValidationError("Impossible d'acheter moins de 1 article")
|
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]:
|
elif type_ope and type_ope in [Operation.DEPOSIT, Operation.WITHDRAW]:
|
||||||
if not amount or article or article_nb:
|
if not amount or article or article_nb:
|
||||||
raise ValidationError("Bad request")
|
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
|
@property
|
||||||
def is_checkout(self):
|
def is_checkout(self):
|
||||||
return (self.type == DEPOSIT or
|
return (self.type == Operation.DEPOSIT or
|
||||||
self.type == WITHDRAW or
|
self.type == Operation.WITHDRAW or
|
||||||
(self.type == PURCHASE and self.group and
|
(self.type == Operation.PURCHASE and self.group and
|
||||||
self.group.on_acc.is_cash)
|
self.group.on_acc.is_cash)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,22 @@ function KHistory(options={}) {
|
||||||
if (ope['type'] == 'purchase') {
|
if (ope['type'] == 'purchase') {
|
||||||
infos1 = ope['article_nb'];
|
infos1 = ope['article_nb'];
|
||||||
infos2 = ope['article__name'];
|
infos2 = ope['article__name'];
|
||||||
} else if (ope['type'] == 'initial') {
|
|
||||||
infos1 = parsed_amount.toFixed(2)+'€';
|
|
||||||
infos2 = 'Initial';
|
|
||||||
} else {
|
} else {
|
||||||
infos1 = parsed_amount.toFixed(2)+'€';
|
infos1 = parsed_amount.toFixed(2)+'€';
|
||||||
infos2 = (ope['type'] == 'deposit') ? 'Charge' : 'Retrait';
|
switch (ope['type']) {
|
||||||
infos2 = ope['is_checkout'] ? infos2 : 'Édition';
|
case 'initial':
|
||||||
|
infos2 = 'Initial';
|
||||||
|
break;
|
||||||
|
case 'withdraw':
|
||||||
|
infos2 = 'Retrait';
|
||||||
|
break;
|
||||||
|
case 'deposit':
|
||||||
|
infos2 = 'Charge';
|
||||||
|
break;
|
||||||
|
case 'edit':
|
||||||
|
infos2 = 'Édition';
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ope_html
|
$ope_html
|
||||||
|
|
|
@ -794,15 +794,27 @@ $(document).ready(function() {
|
||||||
updateBasketRel();
|
updateBasketRel();
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDeposit(amount, is_checkout=1) {
|
function addDeposit(amount) {
|
||||||
var deposit_basket_html = $(item_basket_default_html);
|
var deposit_basket_html = $(item_basket_default_html);
|
||||||
var amount = parseFloat(amount).toFixed(2);
|
var amount = parseFloat(amount).toFixed(2);
|
||||||
var index = addDepositToFormset(amount, is_checkout);
|
var index = addDepositToFormset(amount);
|
||||||
var text = is_checkout ? 'Charge' : 'Édition';
|
|
||||||
deposit_basket_html
|
deposit_basket_html
|
||||||
.attr('data-opeindex', index)
|
.attr('data-opeindex', index)
|
||||||
.find('.number').text(amount+"€").end()
|
.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']));
|
.find('.amount').text(amountToUKF(amount, account_data['is_cof']));
|
||||||
basket_container.prepend(deposit_basket_html);
|
basket_container.prepend(deposit_basket_html);
|
||||||
updateBasketRel();
|
updateBasketRel();
|
||||||
|
@ -910,10 +922,9 @@ $(document).ready(function() {
|
||||||
// Ask deposit or withdraw
|
// Ask deposit or withdraw
|
||||||
// -----
|
// -----
|
||||||
|
|
||||||
function askDeposit(is_checkout=1) {
|
function askDeposit() {
|
||||||
var title = is_checkout ? 'Montant de la charge' : "Montant de l'édition";
|
|
||||||
$.confirm({
|
$.confirm({
|
||||||
title: title,
|
title: 'Montant de la charge',
|
||||||
content: '<input type="number" step="0.01" min="0.01" on autofocus placeholder="€">',
|
content: '<input type="number" step="0.01" min="0.01" on autofocus placeholder="€">',
|
||||||
backgroundDismiss: true,
|
backgroundDismiss: true,
|
||||||
animation:'top',
|
animation:'top',
|
||||||
|
@ -923,7 +934,34 @@ $(document).ready(function() {
|
||||||
var amount = this.$content.find('input').val();
|
var amount = this.$content.find('input').val();
|
||||||
if (!$.isNumeric(amount) || amount <= 0)
|
if (!$.isNumeric(amount) || amount <= 0)
|
||||||
return false;
|
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() {
|
onOpen: function() {
|
||||||
var that = this
|
var that = this
|
||||||
|
@ -988,7 +1026,7 @@ $(document).ready(function() {
|
||||||
var mngmt_total_forms = 1;
|
var mngmt_total_forms = 1;
|
||||||
var prefix_regex = /__prefix__/;
|
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 operation_html = operation_empty_html.clone();
|
||||||
var index = mngmt_total_forms;
|
var index = mngmt_total_forms;
|
||||||
|
|
||||||
|
@ -998,8 +1036,7 @@ $(document).ready(function() {
|
||||||
.find('#id_form-__prefix__-type').val(type).end()
|
.find('#id_form-__prefix__-type').val(type).end()
|
||||||
.find('#id_form-__prefix__-amount').val((parseFloat(amount)).toFixed(2)).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').val(article).end()
|
||||||
.find('#id_form-__prefix__-article_nb').val(article_nb).end()
|
.find('#id_form-__prefix__-article_nb').val(article_nb).end();
|
||||||
.find('#id_form-__prefix__-is_checkout').val(is_checkout);
|
|
||||||
|
|
||||||
mngmt_total_forms_input.val(index+1);
|
mngmt_total_forms_input.val(index+1);
|
||||||
mngmt_total_forms++;
|
mngmt_total_forms++;
|
||||||
|
@ -1014,12 +1051,16 @@ $(document).ready(function() {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDepositToFormset(amount, is_checkout=1) {
|
function addDepositToFormset(amount) {
|
||||||
return addOperationToFormset('deposit', amount, '', '', is_checkout);
|
return addOperationToFormset('deposit', amount, '', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function addWithdrawToFormset(amount, is_checkout=1) {
|
function addEditToFormset(amount) {
|
||||||
return addOperationToFormset('withdraw', amount, '', '', is_checkout);
|
return addOperationToFormset('edit', amount, '', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function addWithdrawToFormset(amount) {
|
||||||
|
return addOperationToFormset('withdraw', amount, '', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPurchaseToFormset(article_id, article_nb, amount=0) {
|
function addPurchaseToFormset(article_id, article_nb, amount=0) {
|
||||||
|
@ -1295,7 +1336,7 @@ $(document).ready(function() {
|
||||||
return false;
|
return false;
|
||||||
case 119:
|
case 119:
|
||||||
// F8 - Edition
|
// F8 - Edition
|
||||||
askDeposit(0);
|
askEdit();
|
||||||
return false;
|
return false;
|
||||||
case 120:
|
case 120:
|
||||||
// F9 - Addcost
|
// F9 - Addcost
|
||||||
|
|
|
@ -138,8 +138,7 @@ def account_create_special(request):
|
||||||
ope = Operation.objects.create(
|
ope = Operation.objects.create(
|
||||||
group = opegroup,
|
group = opegroup,
|
||||||
type = Operation.INITIAL,
|
type = Operation.INITIAL,
|
||||||
amount = amount,
|
amount = amount)
|
||||||
is_checkout = False)
|
|
||||||
messages.success(request, 'Compte créé : %s' % account.trigramme)
|
messages.success(request, 'Compte créé : %s' % account.trigramme)
|
||||||
return redirect('kfet.account.create')
|
return redirect('kfet.account.create')
|
||||||
except Account.UserHasAccount as e:
|
except Account.UserHasAccount as e:
|
||||||
|
@ -960,10 +959,7 @@ def kpsul_perform_operations(request):
|
||||||
operation.amount -= operation.addcost_amount
|
operation.amount -= operation.addcost_amount
|
||||||
to_addcost_for_balance += operation.addcost_amount
|
to_addcost_for_balance += operation.addcost_amount
|
||||||
if operationgroup.on_acc.is_cash:
|
if operationgroup.on_acc.is_cash:
|
||||||
operation.is_checkout = True
|
|
||||||
to_checkout_balance += -operation.amount
|
to_checkout_balance += -operation.amount
|
||||||
else:
|
|
||||||
operation.is_checkout = False
|
|
||||||
if operationgroup.on_acc.is_cof:
|
if operationgroup.on_acc.is_cof:
|
||||||
if is_addcost:
|
if is_addcost:
|
||||||
operation.addcost_amount = operation.addcost_amount / cof_grant_divisor
|
operation.addcost_amount = operation.addcost_amount / cof_grant_divisor
|
||||||
|
@ -972,12 +968,12 @@ def kpsul_perform_operations(request):
|
||||||
else:
|
else:
|
||||||
if operationgroup.on_acc.is_cash:
|
if operationgroup.on_acc.is_cash:
|
||||||
data['errors']['account'] = 'Charge et retrait impossible sur LIQ'
|
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
|
operationgroup.amount += operation.amount
|
||||||
if operation.type == Operation.DEPOSIT:
|
if operation.type == Operation.DEPOSIT:
|
||||||
required_perms.add('kfet.perform_deposit')
|
required_perms.add('kfet.perform_deposit')
|
||||||
if (not operation.is_checkout
|
if operation.type == Operation.EDIT:
|
||||||
and operation.type in [Operation.DEPOSIT, Operation.WITHDRAW]):
|
|
||||||
required_perms.add('kfet.edit_balance_account')
|
required_perms.add('kfet.edit_balance_account')
|
||||||
need_comment = True
|
need_comment = True
|
||||||
if operationgroup.on_acc.is_cof:
|
if operationgroup.on_acc.is_cof:
|
||||||
|
@ -1073,7 +1069,6 @@ def kpsul_perform_operations(request):
|
||||||
'id': operation.pk, 'type': operation.type, 'amount': operation.amount,
|
'id': operation.pk, 'type': operation.type, 'amount': operation.amount,
|
||||||
'addcost_amount': operation.addcost_amount,
|
'addcost_amount': operation.addcost_amount,
|
||||||
'addcost_for__trigramme': is_addcost and addcost_for.trigramme or None,
|
'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__name': operation.article and operation.article.name or None,
|
||||||
'article_nb': operation.article_nb,
|
'article_nb': operation.article_nb,
|
||||||
'group_id': operationgroup.pk,
|
'group_id': operationgroup.pk,
|
||||||
|
@ -1163,11 +1158,11 @@ def kpsul_cancel_operations(request):
|
||||||
.order_by('at')
|
.order_by('at')
|
||||||
.last())
|
.last())
|
||||||
if not last_statement or last_statement.at < ope.group.at:
|
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:
|
if ope.group.on_acc.is_cash:
|
||||||
to_checkouts_balances[ope.group.checkout] -= - ope.amount
|
to_checkouts_balances[ope.group.checkout] -= - ope.amount
|
||||||
else:
|
else:
|
||||||
to_checkouts_balances[ope.group.checkout] -= ope.amount
|
to_checkouts_balances[ope.group.checkout] -= ope.amount
|
||||||
|
|
||||||
# Pour les stocks d'articles
|
# Pour les stocks d'articles
|
||||||
# Les stocks d'articles dont il y a eu un inventaire depuis la date
|
# 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,
|
'type' : ope.type,
|
||||||
'amount' : ope.amount,
|
'amount' : ope.amount,
|
||||||
'article_nb' : ope.article_nb,
|
'article_nb' : ope.article_nb,
|
||||||
'is_checkout' : ope.is_checkout,
|
|
||||||
'addcost_amount': ope.addcost_amount,
|
'addcost_amount': ope.addcost_amount,
|
||||||
'canceled_at' : ope.canceled_at,
|
'canceled_at' : ope.canceled_at,
|
||||||
'article__name':
|
'article__name':
|
||||||
|
|
Loading…
Add table
Reference in a new issue