Basic fonctionnality of Vente done
This commit is contained in:
parent
eb5b459294
commit
f4115d2868
4 changed files with 114 additions and 11 deletions
|
@ -45,7 +45,7 @@ class Produit(models.Model):
|
||||||
price = models.FloatField("Prix")
|
price = models.FloatField("Prix")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
name = str(self.Produit) + " " + self.option_1_value + " " + self.option_2_value + " " + self.option_3_value + " " + self.option_4_value + " " + self.option_5_value + str(self.price) +"€"
|
name = str(self.Produit) + " " + self.option_1_value + " " + self.option_2_value + " " + self.option_3_value + " " + self.option_4_value + " " + self.option_5_value
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,18 +9,31 @@
|
||||||
<button id="button_option" value="Produit:{{ product }}:1">{{ product }}</button>
|
<button id="button_option" value="Produit:{{ product }}:1">{{ product }}</button>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
<div id="ligne-jdc"></div>
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
var data_received = null
|
||||||
function addButton(elem, index, option, option_int){
|
function addButton(elem, index, option, option_int){
|
||||||
|
|
||||||
var r = $('<button id="button_option" value="'+option+':'+elem+':'+option_int+'">'+ elem + '</button>');
|
var r = $('<button id="button_option" value="'+option+':'+elem+':'+option_int+'">'+ elem + '</button>');
|
||||||
$("#lol").append(r)
|
$("#lol").append(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runAllfunction(){
|
||||||
|
display_jdc()
|
||||||
|
button_handler()
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(runAllfunction);
|
||||||
|
|
||||||
|
|
||||||
|
function button_handler(){
|
||||||
$(document).on("click", "#button_option", function () {
|
$(document).on("click", "#button_option", function () {
|
||||||
$(this).css('background', 'yellow');
|
$(this).css('background', 'yellow');
|
||||||
$("[id=button_option]").prop("disabled", true);
|
$("[id=button_option]").prop("disabled", true);
|
||||||
|
@ -34,21 +47,78 @@ $(document).ready(function() {
|
||||||
},
|
},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
data_received = data
|
||||||
console.log(data);
|
console.log(data);
|
||||||
var r = $('<br>');
|
var r = $('<br>');
|
||||||
$("#lol").append(r);
|
$("#lol").append(r);
|
||||||
data.options.forEach(function (item, index) {
|
data.options.forEach(function (item, index) {
|
||||||
addButton(item, index, data.field, data.options_int)
|
addButton(item, index, data.field, data.options_int)
|
||||||
});
|
});
|
||||||
if (data.options[0] === ""){
|
|
||||||
console.log("lol")
|
if (data.elem_selected != null){
|
||||||
|
var r = $("<p>Produit Sélectionné : "+ data.elem_selected+" Prix : "+ data.price+"€ Stock : "+ data.stock+"</p>");
|
||||||
|
$("#lol").append(r)
|
||||||
|
|
||||||
|
var r = $('<p>Acheteur :</p> <input type="text" id="acheteur"> <br>');
|
||||||
|
$("#lol").append(r)
|
||||||
|
var r = $('<select name="pets" id="pet-select">\n' +
|
||||||
|
' <option value="0">CB</option>\n' +
|
||||||
|
' <option value="1">Espèces</option>\n' +
|
||||||
|
' <option value="2">Chèque</option>\n' +
|
||||||
|
'</select>\n');
|
||||||
|
$("#lol").append(r)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});});
|
});}
|
||||||
|
|
||||||
|
|
||||||
|
function display_jdc() {
|
||||||
|
$(document).on('input', "#acheteur", function () {
|
||||||
|
|
||||||
|
var r = $("<div id='ligne-jdc'> <p>Ligne JDC : "+data_received.name+" - "+ data_received.elem_selected + " - "+ $("#acheteur").val() +" - "+ $("#pet-select option:selected").text()+"</p><button id='confirm'>Confirmer transaction</button></div>");
|
||||||
|
$("#ligne-jdc").replaceWith(r)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('input', "#pet-select", function () {
|
||||||
|
|
||||||
|
var r = $("<div id='ligne-jdc'> <p>Ligne JDC : "+data_received.name+" - "+ data_received.elem_selected + " - "+ $("#acheteur").val() +" - "+ $("#pet-select option:selected").text()+"</p><button id='confirm'>Confirmer transaction</button></div>");
|
||||||
|
$("#ligne-jdc").replaceWith(r)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('click', "#confirm", function () {
|
||||||
|
$.ajax({
|
||||||
|
url: 'ajax/submit_entry/',
|
||||||
|
data: {
|
||||||
|
'buyer': $("#acheteur").val(),
|
||||||
|
'payment': $("#pet-select option:selected").text()
|
||||||
|
},
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (data) {
|
||||||
|
// Simulate an HTTP redirect:
|
||||||
|
window.location.replace("/journaldecaisse");
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
path('vente.html', views.vente, name='vente'),
|
path('vente.html', views.vente, name='vente'),
|
||||||
url(r'^ajax/iterate_options/$', views.iterate_options, name='iterate_options'),
|
url(r'^ajax/iterate_options/$', views.iterate_options, name='iterate_options'),
|
||||||
|
url(r'^ajax/submit_entry/$', views.submit_entry, name='submit_entry'),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from .models import JournalEntry, Produit
|
from .models import JournalEntry, Produit, ProduitStock
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
global_filter = None
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
entry_list = JournalEntry.objects.order_by('entry_date')
|
entry_list = JournalEntry.objects.order_by('entry_date')
|
||||||
|
@ -9,7 +12,11 @@ def index(request):
|
||||||
return render(request, 'journaldecaisse/index.html', context)
|
return render(request, 'journaldecaisse/index.html', context)
|
||||||
|
|
||||||
def vente(request):
|
def vente(request):
|
||||||
product_list = Produit.objects.all().values_list()
|
print(request.user.first_name)
|
||||||
|
global global_filter
|
||||||
|
product_list = Produit.objects.all()
|
||||||
|
global_filter = product_list
|
||||||
|
product_list = product_list.values_list()
|
||||||
products = []
|
products = []
|
||||||
for elem in product_list:
|
for elem in product_list:
|
||||||
products.append(elem[1])
|
products.append(elem[1])
|
||||||
|
@ -24,21 +31,45 @@ def vente(request):
|
||||||
|
|
||||||
def iterate_options(request):
|
def iterate_options(request):
|
||||||
|
|
||||||
|
global global_filter
|
||||||
|
elem_selected = None
|
||||||
|
elem_price = None
|
||||||
|
elem_stock = None
|
||||||
options_selected = request.GET.get('option', None)
|
options_selected = request.GET.get('option', None)
|
||||||
options_selected = options_selected.split(":")
|
options_selected = options_selected.split(":")
|
||||||
print(options_selected)
|
|
||||||
field = str(Produit._meta.get_fields()[int(options_selected[2])+3]).split(".")[-1]
|
field = str(Produit._meta.get_fields()[int(options_selected[2])+3]).split(".")[-1]
|
||||||
print(field)
|
elems = global_filter.filter(**{options_selected[0]: options_selected[1]})
|
||||||
elems = Produit.objects.filter(**{options_selected[0]: options_selected[1]})
|
global_filter = elems
|
||||||
elems = elems.values_list()
|
elems = elems.values_list()
|
||||||
options = []
|
options = []
|
||||||
for elem in elems:
|
for elem in elems:
|
||||||
options.append(elem[int(options_selected[2])+2])
|
options.append(elem[int(options_selected[2])+2])
|
||||||
options = list(set(options))
|
options = list(set(options))
|
||||||
|
if global_filter.count() == 1:
|
||||||
|
elem_selected = str(global_filter.first())
|
||||||
|
elem_price = global_filter.first().price
|
||||||
|
elem_stock = ProduitStock.objects.get(ProduitTaille=global_filter.first()).Amount
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'options': options,
|
'options': options,
|
||||||
'options_int': int(options_selected[2])+2,
|
'options_int': int(options_selected[2])+2,
|
||||||
'field': field
|
'field': field,
|
||||||
|
'elem_selected': elem_selected,
|
||||||
|
'price': elem_price,
|
||||||
|
'stock': elem_stock,
|
||||||
|
'name': request.user.first_name
|
||||||
}
|
}
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def submit_entry(request):
|
||||||
|
product = global_filter.first()
|
||||||
|
buyer = request.GET.get('buyer', None)
|
||||||
|
payment = request.GET.get('payment', None)
|
||||||
|
author = request.user.first_name
|
||||||
|
JournalEntry.objects.create(entry_date=datetime.datetime.now(), entry_text=str(product) + " " + buyer, cofeux_id=author, entry_amount=product.price, payment_type=payment)
|
||||||
|
return JsonResponse({"success":"True"})
|
||||||
|
|
Loading…
Add table
Reference in a new issue