mirror of
https://github.com/nanoy42/coope
synced 2024-12-23 07:23:47 +00:00
Fix cancel consumption
This commit is contained in:
parent
fb95d78102
commit
3f970fe199
1 changed files with 33 additions and 9 deletions
|
@ -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}))
|
||||||
|
|
Loading…
Reference in a new issue