forked from DGNum/gestioCOF
Modification de l'enregistrement sur K-Psul
- Passe le calcul du montant d'un achat dans la vue au lieu du clean du form - Corrige le calcul d'un achat et le calcul total du montant de la commande - Ajoute l'enregistrement du statut COF de la personne associée à la commande La subvention COF, la majoration possible (type concert), autres... devront être prises en compte donc le calcul d'un achat doit être dans la vue. Les achats et les retraits doivent avoir un montant négatif tandis que les charges ont un montant positif. L'enregistrement du statut COF servira aux futures statistiques.
This commit is contained in:
parent
5ff7ee51b3
commit
49bb7d99cd
3 changed files with 31 additions and 4 deletions
|
@ -155,7 +155,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['amount'] = article.price * article_nb
|
|
||||||
self.cleaned_data['is_checkout'] = True
|
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:
|
||||||
|
@ -168,5 +167,5 @@ class KPsulOperationForm(forms.ModelForm):
|
||||||
KPsulOperationFormSet = modelformset_factory(
|
KPsulOperationFormSet = modelformset_factory(
|
||||||
Operation,
|
Operation,
|
||||||
form = KPsulOperationForm,
|
form = KPsulOperationForm,
|
||||||
extra = 0,
|
extra = 1,
|
||||||
min_num = 1, validate_min = True)
|
min_num = 1, validate_min = True)
|
||||||
|
|
19
kfet/migrations/0011_auto_20160807_1720.py
Normal file
19
kfet/migrations/0011_auto_20160807_1720.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('kfet', '0010_auto_20160806_2343'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='operation',
|
||||||
|
name='amount',
|
||||||
|
field=models.DecimalField(decimal_places=2, max_digits=6, default=0, blank=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -402,15 +402,24 @@ def kpsul_perform_operations(request):
|
||||||
if 'errors' in data:
|
if 'errors' in data:
|
||||||
return JsonResponse(data, status=400)
|
return JsonResponse(data, status=400)
|
||||||
|
|
||||||
# Pre-saving
|
# Pre-saving (no commit)
|
||||||
operationgroup = operationgroup_form.save(commit = False)
|
operationgroup = operationgroup_form.save(commit = False)
|
||||||
operations = operation_formset.save(commit = False)
|
operations = operation_formset.save(commit = False)
|
||||||
|
|
||||||
|
# Calculating amount of each PURCHASE operations
|
||||||
|
# and total amount for operation group
|
||||||
for operation in operations:
|
for operation in operations:
|
||||||
|
if operation.type == Operation.PURCHASE:
|
||||||
|
operation.amount = - operation.article.price * operation.article_nb
|
||||||
operationgroup.amount += operation.amount
|
operationgroup.amount += operation.amount
|
||||||
operationgroup.save()
|
|
||||||
|
|
||||||
|
# Filling cof status for statistics
|
||||||
|
operationgroup.is_cof = operationgroup.on_acc.is_cof
|
||||||
|
# Saving operation group
|
||||||
|
operationgroup.save()
|
||||||
data['operationgroup'] = operationgroup.pk
|
data['operationgroup'] = operationgroup.pk
|
||||||
|
|
||||||
|
# Filling operationgroup id for each operations and saving
|
||||||
for operation in operations:
|
for operation in operations:
|
||||||
operation.group = operationgroup
|
operation.group = operationgroup
|
||||||
operation.save()
|
operation.save()
|
||||||
|
|
Loading…
Reference in a new issue