3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-22 11:23:11 +00:00

Update KegHistory when canceling operation

This commit is contained in:
root 2020-03-29 23:51:42 +02:00
parent 3cc7966bbc
commit fb95d78102

View file

@ -338,6 +338,27 @@ def cancel_consumption(request, pk):
if product.use_stocks: if product.use_stocks:
product.stock += consumption.quantity product.stock += consumption.quantity
product.save() 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() consumption.delete()
messages.success(request, "La consommation a bien été annulée") messages.success(request, "La consommation a bien été annulée")
return redirect(reverse('users:profile', kwargs={'pk': user.pk})) return redirect(reverse('users:profile', kwargs={'pk': user.pk}))