forked from DGNum/gestioCOF
Merge branch 'Aufinal/editions' into 'master'
K-Fêt - Fix: Les éditions ne touchent plus la caisse - Fix: Seuls les achats sont possibles sur LIQ See merge request !198
This commit is contained in:
commit
7dc233c0e2
7 changed files with 143 additions and 66 deletions
|
@ -326,11 +326,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(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +345,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/0050_remove_checkout.py
Normal file
23
kfet/migrations/0050_remove_checkout.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', '0049_merge'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='operation',
|
||||||
|
name='is_checkout',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='operation',
|
||||||
|
name='type',
|
||||||
|
field=models.CharField(choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial'), ('edit', 'Édition')], max_length=8),
|
||||||
|
),
|
||||||
|
]
|
|
@ -540,51 +540,60 @@ class Operation(models.Model):
|
||||||
DEPOSIT = 'deposit'
|
DEPOSIT = 'deposit'
|
||||||
WITHDRAW = 'withdraw'
|
WITHDRAW = 'withdraw'
|
||||||
INITIAL = 'initial'
|
INITIAL = 'initial'
|
||||||
|
EDIT = 'edit'
|
||||||
|
|
||||||
TYPE_ORDER_CHOICES = (
|
TYPE_ORDER_CHOICES = (
|
||||||
(PURCHASE, 'Achat'),
|
(PURCHASE, 'Achat'),
|
||||||
(DEPOSIT, 'Charge'),
|
(DEPOSIT, 'Charge'),
|
||||||
(WITHDRAW, 'Retrait'),
|
(WITHDRAW, 'Retrait'),
|
||||||
(INITIAL, 'Initial'),
|
(INITIAL, 'Initial'),
|
||||||
|
(EDIT, 'Édition'),
|
||||||
)
|
)
|
||||||
|
|
||||||
group = models.ForeignKey(
|
group = models.ForeignKey(
|
||||||
OperationGroup, on_delete = models.PROTECT,
|
OperationGroup, on_delete=models.PROTECT,
|
||||||
related_name = "opes")
|
related_name="opes")
|
||||||
type = models.CharField(
|
type = models.CharField(
|
||||||
choices = TYPE_ORDER_CHOICES,
|
choices=TYPE_ORDER_CHOICES,
|
||||||
max_length = choices_length(TYPE_ORDER_CHOICES))
|
max_length=choices_length(TYPE_ORDER_CHOICES))
|
||||||
amount = models.DecimalField(
|
amount = models.DecimalField(
|
||||||
max_digits = 6, decimal_places = 2,
|
max_digits=6, decimal_places=2,
|
||||||
blank = True, default = 0)
|
blank=True, default=0)
|
||||||
is_checkout = models.BooleanField(default = True)
|
|
||||||
# Optional
|
# Optional
|
||||||
article = models.ForeignKey(
|
article = models.ForeignKey(
|
||||||
Article, on_delete = models.PROTECT,
|
Article, on_delete=models.PROTECT,
|
||||||
related_name = "operations",
|
related_name="operations",
|
||||||
blank = True, null = True, default = None)
|
blank=True, null=True, default=None)
|
||||||
article_nb = models.PositiveSmallIntegerField(
|
article_nb = models.PositiveSmallIntegerField(
|
||||||
blank = True, null = True, default = None)
|
blank=True, null=True, default=None)
|
||||||
canceled_by = models.ForeignKey(
|
canceled_by = models.ForeignKey(
|
||||||
Account, on_delete = models.PROTECT,
|
Account, on_delete=models.PROTECT,
|
||||||
related_name = "+",
|
related_name="+",
|
||||||
blank = True, null = True, default = None)
|
blank=True, null=True, default=None)
|
||||||
canceled_at = models.DateTimeField(
|
canceled_at = models.DateTimeField(
|
||||||
blank = True, null = True, default = None)
|
blank=True, null=True, default=None)
|
||||||
addcost_for = models.ForeignKey(
|
addcost_for = models.ForeignKey(
|
||||||
Account, on_delete = models.PROTECT,
|
Account, on_delete=models.PROTECT,
|
||||||
related_name = "addcosts",
|
related_name="addcosts",
|
||||||
blank = True, null = True, default = None)
|
blank=True, null=True, default=None)
|
||||||
addcost_amount = models.DecimalField(
|
addcost_amount = models.DecimalField(
|
||||||
max_digits = 6, decimal_places = 2,
|
max_digits=6, decimal_places=2,
|
||||||
blank = True, null = True, default = None)
|
blank=True, null=True, default=None)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_checkout(self):
|
||||||
|
return (self.type == Operation.DEPOSIT or
|
||||||
|
self.type == Operation.WITHDRAW or
|
||||||
|
(self.type == Operation.PURCHASE and self.group.on_acc.is_cash)
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
templates = {
|
templates = {
|
||||||
self.PURCHASE: "{nb} {article.name} ({amount}€)",
|
self.PURCHASE: "{nb} {article.name} ({amount}€)",
|
||||||
self.DEPOSIT: "charge ({amount})",
|
self.DEPOSIT: "charge ({amount}€)",
|
||||||
self.WITHDRAW: "retrait ({amount})",
|
self.WITHDRAW: "retrait ({amount}€)",
|
||||||
self.INITIAL: "initial ({amount})",
|
self.INITIAL: "initial ({amount}€)",
|
||||||
|
self.EDIT: "édition ({amount}€)",
|
||||||
}
|
}
|
||||||
return templates[self.type].format(nb=self.article_nb,
|
return templates[self.type].format(nb=self.article_nb,
|
||||||
article=self.article,
|
article=self.article,
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -134,7 +134,10 @@ function getErrorsHtml(data) {
|
||||||
content += '</ul>';
|
content += '</ul>';
|
||||||
}
|
}
|
||||||
if ('account' in data['errors']) {
|
if ('account' in data['errors']) {
|
||||||
content += data['errors']['account'];
|
content += 'Général';
|
||||||
|
content += '<ul>';
|
||||||
|
content += '<li>Opération invalide sur le compte '+data['errors']['account']+'</li>';
|
||||||
|
content += '</ul>';
|
||||||
}
|
}
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
|
@ -875,15 +875,27 @@ $(document).ready(function() {
|
||||||
return (-5 <= stock - nb && stock - nb <= 5);
|
return (-5 <= stock - nb && stock - nb <= 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
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'], false));
|
||||||
|
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'], false));
|
.find('.amount').text(amountToUKF(amount, account_data['is_cof'], false));
|
||||||
basket_container.prepend(deposit_basket_html);
|
basket_container.prepend(deposit_basket_html);
|
||||||
updateBasketRel();
|
updateBasketRel();
|
||||||
|
@ -1046,11 +1058,10 @@ $(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" lang="en" step="0.01" min="0.01" on autofocus placeholder="€">',
|
content: '<input type="number" lang="en" step="0.01" min="0.01" autofocus placeholder="€">',
|
||||||
backgroundDismiss: true,
|
backgroundDismiss: true,
|
||||||
animation:'top',
|
animation:'top',
|
||||||
closeAnimation:'bottom',
|
closeAnimation:'bottom',
|
||||||
|
@ -1059,7 +1070,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" lang="en" step="0.01" min="0.01" 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
|
||||||
|
@ -1077,7 +1115,7 @@ $(document).ready(function() {
|
||||||
function askWithdraw() {
|
function askWithdraw() {
|
||||||
$.confirm({
|
$.confirm({
|
||||||
title: 'Montant du retrait',
|
title: 'Montant du retrait',
|
||||||
content: '<input type="number" lang="en" step="0.01" min="0.01" on autofocus placeholder="€">',
|
content: '<input type="number" lang="en" step="0.01" min="0.01" autofocus placeholder="€">',
|
||||||
backgroundDismiss: true,
|
backgroundDismiss: true,
|
||||||
animation:'top',
|
animation:'top',
|
||||||
closeAnimation:'bottom',
|
closeAnimation:'bottom',
|
||||||
|
@ -1124,7 +1162,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;
|
||||||
|
|
||||||
|
@ -1134,8 +1172,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++;
|
||||||
|
@ -1150,12 +1187,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) {
|
||||||
|
@ -1440,7 +1481,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
|
||||||
|
|
|
@ -165,8 +165,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:
|
||||||
|
@ -1010,10 +1009,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
|
||||||
|
@ -1021,13 +1017,13 @@ def kpsul_perform_operations(request):
|
||||||
to_articles_stocks[operation.article] -= operation.article_nb
|
to_articles_stocks[operation.article] -= operation.article_nb
|
||||||
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'] = 'LIQ'
|
||||||
|
if operation.type != Operation.EDIT:
|
||||||
to_checkout_balance += operation.amount
|
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:
|
||||||
|
@ -1124,8 +1120,7 @@ def kpsul_perform_operations(request):
|
||||||
ope_data = {
|
ope_data = {
|
||||||
'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': operation.addcost_for 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,
|
||||||
|
@ -1215,7 +1210,7 @@ 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:
|
||||||
|
@ -1380,7 +1375,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…
Reference in a new issue