From 03aa26e34fdee0d55b805fcd0922b2bae96fc701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Mon, 8 Aug 2016 00:41:31 +0200 Subject: [PATCH] =?UTF-8?q?Enregistrement=20d'op=C3=A9rations=20K-Psul?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Le stock des articles est mis à jour --- kfet/views.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kfet/views.py b/kfet/views.py index e81640ba..5e1e560d 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -416,16 +416,19 @@ def kpsul_perform_operations(request): # 1. Calculating amount of each PURCHASE operations # 2. and total amount for operation group - # 3. Adding required permissions to perform each operation + # 3. Updating (no commit) stock of article for PURCHASE operations + # 4. Adding required permissions to perform each operation for operation in operations: - # 1 if operation.type == Operation.PURCHASE: + # 1 operation.amount = - operation.article.price * operation.article_nb if operationgroup.on_acc.is_cof: operation.amount = operation.amount / cof_grant_divisor - # 2 - operationgroup.amount += operation.amount + # 2 + operation.article.stock -= operation.article_nb # 3 + operationgroup.amount += operation.amount + # 4 if operation.type == Operation.DEPOSIT: required_perms.append('kfet.can_perform_deposit') @@ -452,7 +455,7 @@ def kpsul_perform_operations(request): # Filling cof status for statistics operationgroup.is_cof = operationgroup.on_acc.is_cof - # Updating account's balance + # Updating (no commit) account's balance operationgroup.on_acc.balance += operationgroup.amount # Apply all saves in a transaction to ensure database integrity @@ -466,9 +469,12 @@ def kpsul_perform_operations(request): operationgroup.on_acc.save() # Filling operationgroup id for each operations and saving + # Saving articles with new stock for operation in operations: operation.group = operationgroup operation.save() + if operation.type == Operation.PURCHASE: + operation.article.save() data['operations'].append(operation.pk) except IntegrityError: data['errors'].append('DB error')