3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-24 04:13:13 +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) keg = get_object_or_404(Keg, pinte=product)
kegHistory = KegHistory.objects.filter(keg=keg, isCurrentKegHistory=True) kegHistory = KegHistory.objects.filter(keg=keg, isCurrentKegHistory=True)
if kegHistory: if kegHistory:
kegHistory[0].quantitySold -= Decimal(quantity * 0.5) kegH = kegHistory[0]
kegHistory[0].amountSold -= Decimal(quantity * product.amount) else:
kegHistory[0].save() 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): elif(product.draft_category == Product.DRAFT_DEMI):
keg = get_object_or_404(Keg, demi=product) keg = get_object_or_404(Keg, demi=product)
kegHistory = KegHistory.objects.filter(keg=keg, isCurrentKegHistory=True) kegHistory = KegHistory.objects.filter(keg=keg, isCurrentKegHistory=True)
if kegHistory: if kegHistory:
kegHistory[0].quantitySold -= Decimal(quantity * 0.25) kegH = kegHistory[0]
kegHistory[0].amountSold -= Decimal(quantity * product.amount) else:
kegHistory[0].save() 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): elif(product.draft_category == Product.DRAFT_GALOPIN):
keg = get_object_or_404(Keg, galopin=product) keg = get_object_or_404(Keg, galopin=product)
kegHistory = KegHistory.objects.filter(keg=keg, isCurrentKegHistory=True) kegHistory = KegHistory.objects.filter(keg=keg, isCurrentKegHistory=True)
if kegHistory: if kegHistory:
kegHistory[0].quantitySold += Decimal(quantity * 0.125) kegH = kegHistory[0]
kegHistory[0].amountSold += Decimal(quantity * product.amount) else:
kegHistory[0].save() 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() 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}))