mirror of
https://github.com/nanoy42/coope
synced 2024-12-23 23:43:47 +00:00
Demande du numéro de pinte lors de la commande et allocation de la pinte
This commit is contained in:
parent
00b0e8e0a0
commit
3ea5f0322a
2 changed files with 73 additions and 12 deletions
|
@ -14,7 +14,7 @@ from dal import autocomplete
|
|||
from decimal import *
|
||||
|
||||
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm
|
||||
from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory
|
||||
from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte
|
||||
from preferences.models import PaymentMethod
|
||||
|
||||
@active_required
|
||||
|
@ -107,6 +107,7 @@ def order(request):
|
|||
amount = Decimal(request.POST['amount'])
|
||||
order = json.loads(request.POST["order"])
|
||||
menus = json.loads(request.POST["menus"])
|
||||
listPintes = json.loads(request.POST["listPintes"])
|
||||
if (not order) and (not menus):
|
||||
return HttpResponse("Pas de commande")
|
||||
adherentRequired = False
|
||||
|
@ -124,6 +125,8 @@ def order(request):
|
|||
else:
|
||||
user.profile.debit += amount
|
||||
user.save()
|
||||
for pinte in listPintes:
|
||||
allocate(pinte, user)
|
||||
for o in order:
|
||||
product = get_object_or_404(Product, pk=o["pk"])
|
||||
quantity = int(o["quantity"])
|
||||
|
@ -418,7 +421,11 @@ def getProduct(request, barcode):
|
|||
The requested barcode
|
||||
"""
|
||||
product = Product.objects.get(barcode=barcode)
|
||||
data = json.dumps({"pk": product.pk, "barcode" : product.barcode, "name": product.name, "amount" : product.amount})
|
||||
if product.category == Product.P_PRESSION:
|
||||
nb_pintes = 1
|
||||
else:
|
||||
nb_pintes = 0
|
||||
data = json.dumps({"pk": product.pk, "barcode" : product.barcode, "name": product.name, "amount": product.amount, "needQuantityButton": product.needQuantityButton, "nb_pintes": nb_pintes})
|
||||
return HttpResponse(data, content_type='application/json')
|
||||
|
||||
@active_required
|
||||
|
@ -845,7 +852,11 @@ def get_menu(request, barcode):
|
|||
The requested barcode
|
||||
"""
|
||||
menu = get_object_or_404(Menu, barcode=barcode)
|
||||
data = json.dumps({"pk": menu.pk, "barcode" : menu.barcode, "name": menu.name, "amount" : menu.amount})
|
||||
nb_pintes = 0
|
||||
for article in menu.articles:
|
||||
if article.category == Product.P_PRESSION:
|
||||
nb_pintes +=1
|
||||
data = json.dumps({"pk": menu.pk, "barcode" : menu.barcode, "name": menu.name, "amount" : menu.amount, needQuantityButton: False, "nb_pintes": nb_pintes})
|
||||
return HttpResponse(data, content_type='application/json')
|
||||
|
||||
class MenusAutocomplete(autocomplete.Select2QuerySetView):
|
||||
|
@ -886,3 +897,19 @@ def ranking(request):
|
|||
list.append([customer, alcohol])
|
||||
bestDrinkers = sorted(list, key=lambda x: x[1], reverse=True)[:25]
|
||||
return render(request, "gestion/ranking.html", {"bestBuyers": bestBuyers, "bestDrinkers": bestDrinkers})
|
||||
|
||||
########## Pinte monitoring ##########
|
||||
|
||||
def allocate(pinte_pk, user):
|
||||
"""
|
||||
Allocate a pinte to a user or release the pinte if user is None
|
||||
"""
|
||||
try:
|
||||
pinte = Pinte.objects.get(pk=pinte_pk)
|
||||
if pinte.current_owner is not None:
|
||||
pinte.previous_owner = pinte.current_owner
|
||||
pinte.current_owner = user
|
||||
pinte.save()
|
||||
return True
|
||||
except Pinte.DoesNotExist:
|
||||
return False
|
|
@ -5,20 +5,29 @@ paymentMethod = null
|
|||
balance = 0
|
||||
username = ""
|
||||
id = 0
|
||||
listPintes = []
|
||||
nbPintes = 0;
|
||||
use_pinte_monitoring = false;
|
||||
|
||||
function get_config(){
|
||||
use_pinte_monitoring = true;
|
||||
}
|
||||
|
||||
function get_product(barcode){
|
||||
res = $.get("getProduct/" + barcode, function(data){
|
||||
add_product(data.pk, data.barcode, data.name, data.amount);
|
||||
nbPintes += data.nb_pintes;
|
||||
add_product(data.pk, data.barcode, data.name, data.amount, data.needQuantityButton);
|
||||
});
|
||||
}
|
||||
|
||||
function get_menu(barcode){
|
||||
res = $.get("getMenu/" + barcode, function(data){
|
||||
add_menu(data.pk, data.barcode, data.name, data.amount);
|
||||
nbPintes += data.nb_pintes;
|
||||
add_menu(data.pk, data.barcode, data.name, data.amount, data.needQuantityButton);
|
||||
});
|
||||
}
|
||||
|
||||
function add_product(pk, barcode, name, amount){
|
||||
function add_product(pk, barcode, name, amount, needQuantityButton){
|
||||
exist = false
|
||||
index = -1
|
||||
for(k=0;k < products.length; k++){
|
||||
|
@ -27,10 +36,18 @@ function add_product(pk, barcode, name, amount){
|
|||
index = k
|
||||
}
|
||||
}
|
||||
if(exist){
|
||||
products[index].quantity += 1;
|
||||
if(needQuantityButton){
|
||||
quantity = parseInt(window.prompt("Quantité ?",""));
|
||||
}else{
|
||||
products.push({"pk": pk, "barcode": barcode, "name": name, "amount": amount, "quantity": 1});
|
||||
quantity = 1;
|
||||
}
|
||||
if(quantity == null || !Number.isInteger(quantity)){
|
||||
quantity = 1;
|
||||
}
|
||||
if(exist){
|
||||
products[index].quantity += quantity;
|
||||
}else{
|
||||
products.push({"pk": pk, "barcode": barcode, "name": name, "amount": amount, "quantity": quantity});
|
||||
}
|
||||
generate_html()
|
||||
}
|
||||
|
@ -53,7 +70,7 @@ function add_menu(pk, barcode, name, amount){
|
|||
}
|
||||
|
||||
function generate_html(){
|
||||
html =""
|
||||
html = "";
|
||||
for(k=0;k<products.length;k++){
|
||||
product = products[k]
|
||||
html += '<tr><td>' + product.barcode + '</td><td>' + product.name + '</td><td>' + String(product.amount) + '</td><td><input type="number" data-target="' + String(k) + '" onChange="updateInput(this)" value="' + String(product.quantity) + '"/></td><td>' + String(Number((product.quantity * product.amount).toFixed(2))) + '</td></tr>';
|
||||
|
@ -94,6 +111,7 @@ function updateMenuInput(a){
|
|||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
get_config();
|
||||
$(".product").click(function(){
|
||||
product = get_product($(this).attr('target'));
|
||||
});
|
||||
|
@ -113,7 +131,23 @@ $(document).ready(function(){
|
|||
});
|
||||
});
|
||||
$(".pay_button").click(function(){
|
||||
$.post("order", {"user":id, "paymentMethod": $(this).attr('data-payment'), "order_length": products.length + menus.length, "order": JSON.stringify(products), "amount": total, "menus": JSON.stringify(menus)}, function(data){
|
||||
message = "Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?"
|
||||
while(nbPintes > 0){
|
||||
id_pinte = window.prompt(message,"");
|
||||
if(id_pinte == null){
|
||||
return;
|
||||
}else{
|
||||
id_pinte = parseInt(id_pinte);
|
||||
if(!Number.isInteger(id_pinte) || id_pinte < 0){
|
||||
message = "Numéro incorrect. Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?";
|
||||
}else{
|
||||
listPintes.push(id_pinte)
|
||||
nbPintes -= 1;
|
||||
message = "Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?"
|
||||
}
|
||||
}
|
||||
}
|
||||
$.post("order", {"user":id, "paymentMethod": $(this).attr('data-payment'), "order_length": products.length + menus.length, "order": JSON.stringify(products), "amount": total, "menus": JSON.stringify(menus), "listPintes": JSON.stringify(listPintes)}, function(data){
|
||||
alert(data);
|
||||
location.reload();
|
||||
}).fail(function(data){
|
||||
|
|
Loading…
Reference in a new issue