Enregistrement d'opérations K-Psul
- Le stock des articles est mis à jour
This commit is contained in:
parent
d065c7634c
commit
03aa26e34f
1 changed files with 11 additions and 5 deletions
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue