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:
parent
3cc7966bbc
commit
fb95d78102
1 changed files with 21 additions and 0 deletions
|
@ -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}))
|
||||
|
|
Loading…
Reference in a new issue