From 49bb7d99cd17f942dc4e835294758037575cfe71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sun, 7 Aug 2016 17:22:39 +0200 Subject: [PATCH] Modification de l'enregistrement sur K-Psul MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. --- kfet/forms.py | 3 +-- kfet/migrations/0011_auto_20160807_1720.py | 19 +++++++++++++++++++ kfet/views.py | 13 +++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 kfet/migrations/0011_auto_20160807_1720.py diff --git a/kfet/forms.py b/kfet/forms.py index 4ba5f7c1..2c01c3c2 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -155,7 +155,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['amount'] = article.price * article_nb 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: @@ -168,5 +167,5 @@ class KPsulOperationForm(forms.ModelForm): KPsulOperationFormSet = modelformset_factory( Operation, form = KPsulOperationForm, - extra = 0, + extra = 1, min_num = 1, validate_min = True) diff --git a/kfet/migrations/0011_auto_20160807_1720.py b/kfet/migrations/0011_auto_20160807_1720.py new file mode 100644 index 00000000..97525676 --- /dev/null +++ b/kfet/migrations/0011_auto_20160807_1720.py @@ -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), + ), + ] diff --git a/kfet/views.py b/kfet/views.py index b3eee1f2..7c801b9b 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -402,15 +402,24 @@ def kpsul_perform_operations(request): if 'errors' in data: return JsonResponse(data, status=400) - # Pre-saving + # Pre-saving (no commit) operationgroup = operationgroup_form.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: + if operation.type == Operation.PURCHASE: + operation.amount = - operation.article.price * operation.article_nb 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 + + # Filling operationgroup id for each operations and saving for operation in operations: operation.group = operationgroup operation.save()