3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-12-23 07:23:47 +00:00

Fix cancel consumption

This commit is contained in:
Yoann Pétri 2020-03-30 22:58:56 +02:00
parent fb95d78102
commit 3f970fe199

View file

@ -342,23 +342,47 @@ def cancel_consumption(request, pk):
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()
kegH = kegHistory[0]
else:
kegHistory = KegHistory.objects.filter(keg=keg).order_by('-closingDate')
if kegHistory:
kegH = kegHistory[0]
else:
kegH = None
if kegH:
kegH.quantitySold -= Decimal(consumption.quantity * 0.5)
kegH.amountSold -= Decimal(consumption.quantity * product.amount)
kegH.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()
kegH = kegHistory[0]
else:
kegHistory = KegHistory.objects.filter(keg=keg).order_by('-closingDate')
if kegHistory:
kegH = kegHistory[0]
else:
kegH = None
if kegH:
kegH.quantitySold -= Decimal(consumption.quantity * 0.25)
kegH.amountSold -= Decimal(consumption.quantity * product.amount)
kegH.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()
kegH = kegHistory[0]
else:
kegHistory = KegHistory.objects.filter(keg=keg).order_by('-closingDate')
if kegHistory:
kegH = kegHistory[0]
else:
kegH = None
if kegH:
kegH.quantitySold += Decimal(consumption.quantity * 0.125)
kegH.amountSold += Decimal(consumption.quantity * product.amount)
kegH.save()
consumption.delete()
messages.success(request, "La consommation a bien été annulée")
return redirect(reverse('users:profile', kwargs={'pk': user.pk}))