Enregistrement d'opérations K-Psul

- Le stock des articles est mis à jour
This commit is contained in:
Aurélien Delobelle 2016-08-08 00:41:31 +02:00
parent d065c7634c
commit 03aa26e34f

View file

@ -416,16 +416,19 @@ def kpsul_perform_operations(request):
# 1. Calculating amount of each PURCHASE operations # 1. Calculating amount of each PURCHASE operations
# 2. and total amount for operation group # 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: for operation in operations:
# 1
if operation.type == Operation.PURCHASE: if operation.type == Operation.PURCHASE:
# 1
operation.amount = - operation.article.price * operation.article_nb operation.amount = - operation.article.price * operation.article_nb
if operationgroup.on_acc.is_cof: if operationgroup.on_acc.is_cof:
operation.amount = operation.amount / cof_grant_divisor operation.amount = operation.amount / cof_grant_divisor
# 2 # 2
operationgroup.amount += operation.amount operation.article.stock -= operation.article_nb
# 3 # 3
operationgroup.amount += operation.amount
# 4
if operation.type == Operation.DEPOSIT: if operation.type == Operation.DEPOSIT:
required_perms.append('kfet.can_perform_deposit') required_perms.append('kfet.can_perform_deposit')
@ -452,7 +455,7 @@ def kpsul_perform_operations(request):
# Filling cof status for statistics # Filling cof status for statistics
operationgroup.is_cof = operationgroup.on_acc.is_cof operationgroup.is_cof = operationgroup.on_acc.is_cof
# Updating account's balance # Updating (no commit) account's balance
operationgroup.on_acc.balance += operationgroup.amount operationgroup.on_acc.balance += operationgroup.amount
# Apply all saves in a transaction to ensure database integrity # Apply all saves in a transaction to ensure database integrity
@ -466,9 +469,12 @@ def kpsul_perform_operations(request):
operationgroup.on_acc.save() operationgroup.on_acc.save()
# Filling operationgroup id for each operations and saving # Filling operationgroup id for each operations and saving
# Saving articles with new stock
for operation in operations: for operation in operations:
operation.group = operationgroup operation.group = operationgroup
operation.save() operation.save()
if operation.type == Operation.PURCHASE:
operation.article.save()
data['operations'].append(operation.pk) data['operations'].append(operation.pk)
except IntegrityError: except IntegrityError:
data['errors'].append('DB error') data['errors'].append('DB error')