diff --git a/gestion/views.py b/gestion/views.py index d9a415f..7c56c46 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -338,6 +338,27 @@ def cancel_consumption(request, pk): if product.use_stocks: product.stock += consumption.quantity product.save() + if(product.draft_category == Product.DRAFT_PINTE): + keg = get_object_or_404(Keg, pinte=product) + kegHistory = KegHistory.objects.filter(keg=keg, isCurrentKegHistory=True) + if kegHistory: + kegHistory[0].quantitySold -= Decimal(quantity * 0.5) + kegHistory[0].amountSold -= Decimal(quantity * product.amount) + kegHistory[0].save() + elif(product.draft_category == Product.DRAFT_DEMI): + keg = get_object_or_404(Keg, demi=product) + kegHistory = KegHistory.objects.filter(keg=keg, isCurrentKegHistory=True) + if kegHistory: + kegHistory[0].quantitySold -= Decimal(quantity * 0.25) + kegHistory[0].amountSold -= Decimal(quantity * product.amount) + kegHistory[0].save() + elif(product.draft_category == Product.DRAFT_GALOPIN): + keg = get_object_or_404(Keg, galopin=product) + kegHistory = KegHistory.objects.filter(keg=keg, isCurrentKegHistory=True) + if kegHistory: + kegHistory[0].quantitySold += Decimal(quantity * 0.125) + kegHistory[0].amountSold += Decimal(quantity * product.amount) + kegHistory[0].save() consumption.delete() messages.success(request, "La consommation a bien été annulée") return redirect(reverse('users:profile', kwargs={'pk': user.pk}))