forked from DGNum/gestioCOF
Enregistrement des opérations dans K-Psul
- Ajout d'une transaction pour tous les save lors d'une commande K-Psul afin de préserver la cohérence de la BDD
This commit is contained in:
parent
4cb89aa005
commit
e978209ebc
|
@ -450,14 +450,18 @@ 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
|
||||||
# Saving operation group
|
|
||||||
operationgroup.save()
|
|
||||||
data['operationgroup'] = operationgroup.pk
|
|
||||||
|
|
||||||
# Filling operationgroup id for each operations and saving
|
# Apply all saves in a transaction to ensure database integrity
|
||||||
for operation in operations:
|
try:
|
||||||
operation.group = operationgroup
|
with transaction.atomic:
|
||||||
operation.save()
|
# Saving operation group
|
||||||
data['operations'].append(operation.pk)
|
operationgroup.save()
|
||||||
|
data['operationgroup'] = operationgroup.pk
|
||||||
|
|
||||||
|
# Filling operationgroup id for each operations and saving
|
||||||
|
for operation in operations:
|
||||||
|
operation.group = operationgroup
|
||||||
|
operation.save()
|
||||||
|
data['operations'].append(operation.pk)
|
||||||
|
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
Loading…
Reference in a new issue