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

Implementing alcohol

This commit is contained in:
Yoann Pétri 2019-06-12 23:53:01 +02:00
parent 8308eac31f
commit de38610fd8

View file

@ -163,6 +163,7 @@ def order(request):
consumption.save() consumption.save()
ch = ConsumptionHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, product=product, amount=Decimal(quantity*product.amount), coopeman=request.user) ch = ConsumptionHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, product=product, amount=Decimal(quantity*product.amount), coopeman=request.user)
ch.save() ch.save()
user.profile.alcohol += Decimal(quantity * float(product.deg) * product.volume * 0.79 /10 /1000)
if(paymentMethod.affect_balance): if(paymentMethod.affect_balance):
if(user.profile.balance >= Decimal(product.amount*quantity)): if(user.profile.balance >= Decimal(product.amount*quantity)):
user.profile.debit += Decimal(product.amount*quantity) user.profile.debit += Decimal(product.amount*quantity)
@ -187,11 +188,10 @@ def order(request):
if(article.stockHold > 0): if(article.stockHold > 0):
article.stockHold -= 1 article.stockHold -= 1
article.save() article.save()
user.profile.alcohol += Decimal(quantity * float(product.deg) * product.volume * 0.79 /10 /1000)
user.save() user.save()
return HttpResponse("La commande a bien été effectuée") return HttpResponse("La commande a bien été effectuée")
except Exception as e: except Exception as e:
print(e)
print("test")
return HttpResponse(error_message) return HttpResponse(error_message)
@active_required @active_required
@ -274,7 +274,8 @@ def cancel_consumption(request, pk):
user = consumption.customer user = consumption.customer
if consumption.paymentMethod.affect_balance: if consumption.paymentMethod.affect_balance:
user.profile.debit -= consumption.amount user.profile.debit -= consumption.amount
user.save() user.profile.alcohol -= Decimal(consumption.quantity * float(consumption.product.deg) * consumption.product.volume * 0.79 /10 /1000)
user.save()
consumptionT = Consumption.objects.get(customer=user, product=consumption.product) consumptionT = Consumption.objects.get(customer=user, product=consumption.product)
consumptionT.quantity -= consumption.quantity consumptionT.quantity -= consumption.quantity
consumptionT.save() consumptionT.save()
@ -301,6 +302,8 @@ def cancel_menu(request, pk):
consumptionT = Consumption.objects.get(customer=user, product=product) consumptionT = Consumption.objects.get(customer=user, product=product)
consumptionT -= menu_history.quantity consumptionT -= menu_history.quantity
consumptionT.save() consumptionT.save()
user.profile.alcohol -= Decimal(menu_history.quantity * float(menu_history.product.deg) * menu_history.product.volume * 0.79 /10 /1000)
user.save()
menu_history.delete() menu_history.delete()
messages.success(request, "La consommation du menu a bien été annulée") messages.success(request, "La consommation du menu a bien été annulée")
return redirect(reverse('users:profile', kwargs={'pk': user.pk})) return redirect(reverse('users:profile', kwargs={'pk': user.pk}))
@ -715,12 +718,6 @@ def ranking(request):
Displays the ranking page. Displays the ranking page.
""" """
bestBuyers = User.objects.order_by('-profile__debit')[:25] bestBuyers = User.objects.order_by('-profile__debit')[:25]
#customers = User.objects.all()
#list = []
#for customer in customers:
# alcohol = customer.profile.alcohol
# list.append([customer, alcohol])
#bestDrinkers = sorted(list, key=lambda x: x[1], reverse=True)[:25]
bestDrinkers = User.objects.order_by('-profile__alcohol')[:25] bestDrinkers = User.objects.order_by('-profile__alcohol')[:25]
form = SearchProductForm(request.POST or None) form = SearchProductForm(request.POST or None)
if(form.is_valid()): if(form.is_valid()):