3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-26 06:32:27 +00:00

Fix order

This commit is contained in:
Yoann Pétri 2019-01-26 17:02:23 +01:00
parent 320022adf1
commit c6f45b4407

View file

@ -205,21 +205,23 @@ 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()
if(user.profile.balance >= Decimal(product.amount*quantity)): if(paymentMethod.affect_balance):
user.profile.debit += Decimal(product.amount*quantity) if(user.profile.balance >= Decimal(product.amount*quantity)):
else: user.profile.debit += Decimal(product.amount*quantity)
error_message = "Solde insuffisant" else:
raise Exception(error_message) error_message = "Solde insuffisant"
raise Exception(error_message)
for m in menus: for m in menus:
menu = get_object_or_404(Menu, pk=m["pk"]) menu = get_object_or_404(Menu, pk=m["pk"])
quantity = int(m["quantity"]) quantity = int(m["quantity"])
mh = MenuHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, menu=menu, amount=int(quantity*menu.amount), coopeman=request.user) mh = MenuHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, menu=menu, amount=int(quantity*menu.amount), coopeman=request.user)
mh.save() mh.save()
if(user.profile.balance >= Decimal(menu.amount*quantity)): if(paymentMethod.affect_balance):
user.profile.debit += Decimal(menu.amount*quantity) if(user.profile.balance >= Decimal(product.amount*quantity)):
else: user.profile.debit += Decimal(product.amount*quantity)
error_message = "Solde insuffisant" else:
raise Exception(error_message) error_message = "Solde insuffisant"
raise Exception(error_message)
for article in menu.articles.all(): for article in menu.articles.all():
consumption, _ = Consumption.objects.get_or_create(customer=user, product=article) consumption, _ = Consumption.objects.get_or_create(customer=user, product=article)
consumption.quantity += quantity consumption.quantity += quantity