Commit cd2cb866 authored by HEVELINE Thomas's avatar HEVELINE Thomas Committed by HEVELINE Thomas

(44): delivery refactor

parent 107327be
This diff is collapsed.
......@@ -11,10 +11,10 @@
{% endblock %}
{% block main %}
<div class="delivery">
var url = new URL(window.location.href);
function applyFilter() {
......@@ -25,28 +25,28 @@
<form onchange="generateTable()">
<label for="delivered">Déjà remis</label>
<label for="delivered">Déjà remis :</label>
<select id="delivered"
<option value="both">Tous</option>
<option value="true">Oui</option>
<option value="false">Non</option>
<label for="beeing_delivered">Distribution en cours</label>
<label for="beeing_delivered">Distribution en cours :</label>
<select id="beeing_delivered"
<option value="true">Oui</option>
<option value="false">Non</option>
<option value="both">Tous</option>
<label for="hidden">Produits cachés</label>
<label for="hidden">Produits cachés :</label>
<select id="hidden"
<option value="true">Oui</option>
<option value="false">Non</option>
<option selected value="false">Non</option>
<option value="both">Tous</option>
<label for="paid">Payé</label>
<label for="paid">Payé :</label>
<select id="paid"
<option value="true">Oui</option>
......@@ -54,25 +54,25 @@
<option value="both">Tous</option>
<label for="sort">Tri</label>
<label for="sort">Tri :</label>
<select id="sort">
<option value="true"> --</option>
<option value="none"> --</option>
<option value="false">Personalisation</option>
<option value="both">Acheteur</option>
<option value="both">Date de commande</option>
<option value="both">Option 1</option>
<option value="both">Option 2</option>
<option value="date">Date de commande</option>
<option value="option">Option 1</option>
<option value="second_option">Option 2</option>
<form onblur="generateTable()"
<input placeholder="Email"
<input placeholder="Produit"
<input placeholder="Email"
<input placeholder="Option (valeur exacte)"
......@@ -108,6 +108,7 @@
{% endblock %}
......@@ -15,32 +15,63 @@
{% block main %}
<h1>Gestion des Produits</h1>
<a href="{% url 'boutique:item_create' %}"><button>Ajouter un produit</button></a>
<a href="{% url 'boutique:delivery' %}" ><button>Livraison</button></a>
<a href="{% url 'boutique:item_sell' %}"><button>Vente pour autrui</button></a>
<a href="{% url 'boutique:manage_category' %}"><button>Ajouter une catégorie</button></a>
<a href="{% url 'boutique:item_create' %}">
<button>Ajouter un produit</button>
<a href="{% url 'boutique:delivery' %}">
<a href="{% url 'boutique:item_sell' %}">
<button>Vente en directe</button>
<a href="{% url 'boutique:manage_category' %}">
<button>Ajouter une catégorie</button>
<section class="item-manage-list">
{% for item in object_list %}
<article data-id="{{ }}"
data-pk="{{ }}"
data-customization="{{ item.customization }}"
data-optionLabel="{{ item.option_label }}"
data-optionChoices="{{ item.option }}"
data-secondOptionLabel="{{ item.second_option_label }}"
data-secondOptionChoices="{{ item.second_option }}"
data-customizable="{{ item.customizable }}"
data-special="{{ item.special }}"
{% if item.hidden %}
<article data-id="{{ }}" class="hidden">
{% else %}
<article data-id="{{ }}">
{% endif %}
<img class="image" src="{{ item.get_image_url }}" alt="">
<h2>{{ }}</h2>
<p class="numcommands">{{ item.order_items.count }} commandes</p>
<p class="numcommands">Total commandé: {{ item.total_quantity }} </p>
<p class="numcommands">[{{ item.quantity_delivered }}/{{ item.quantity_to_deliver }} distribué(s)]</p>
<a href="{% url 'boutique:item_edit' %}" class="delivery_list button tooltip">
<i class="fas fa-edit"><span class="tooltiptext">Modifier</span></i>
<button class="delivery_list tooltip begin-delivery"><i class="fas fa-paper-plane"></i> <span
class="tooltiptext">Commencer la livraison</span>
class="tooltiptext">Commencer la distribution des articles commandés</span>
<button class="delivery_list tooltip stop-delivery"><i class="fas fa-ban"></i> <span
class="tooltiptext">Arrêter la distribution des articles</span>
<button class="delivery_list tooltip see-orders"><i class="fas fa-eye"></i> <span
class="tooltiptext">Voir les commandes</span>
<button class="delivery_list tooltip see-orders"><i class="fas fa-eye"></i> <span class="tooltiptext">Voir les commandes</span>
<button class="delivery_list tooltip dl-orders"
onclick="window.location.href = '{% url 'boutique:csvexport' %}'"><i
class="fas fa-download"></i> <span class="tooltiptext">Exporter les commandes</span>
<button class="delivery_list tooltip dl-orders" onclick="window.location.href = '{% url 'boutique:csvexport' %}'"><i class="fas fa-download"></i> <span class="tooltiptext">Voir les commandes</span>
{% if %}
<button class="delivery_list tooltip" onclick="sell(event)"><i class="fas fa-hand-holding-usd"></i> <span
class="tooltiptext">Vente en direct</span>
{% endif %}
......@@ -52,5 +83,6 @@
{% block scripts %}
<script src="{% static 'js/json_request.js' %}"></script>
<script src="{% static 'js/popup.js' %}"></script>
<script src="{% static 'js/table_list.js' %}"></script>
<script src="{% static 'boutique/js/item_manage.js' %}"></script>
{% endblock %}
......@@ -12,9 +12,11 @@ from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.models import User
from django.core.exceptions import SuspiciousOperation
from django.core.exceptions import ValidationError
from django.db.models import F
from django.db.models import F, Value
from django.db.models import Q
from django.db.models import QuerySet
from django.db.models.aggregates import Sum
from django.db.models.functions import Coalesce
from django.forms import BaseForm
from django.forms import BaseInlineFormSet
from django.forms import BaseModelForm
......@@ -210,7 +212,7 @@ class ItemManageView(PermissionRequiredMixin, ListView):
template_name = "boutique/item_manage.html"
permission_required = ""
def post(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
def options(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
req = json.loads(
pk = req.get("id")
......@@ -221,8 +223,12 @@ class ItemManageView(PermissionRequiredMixin, ListView):
message = req.get("message")
if message == "begin-delivery":
return JsonResponse({"status": "success", "data": "Bien reçu"})
return JsonResponse({"status": "success", "data": "Début des livraisons des articles déjà commandé"})
if message == "stop-delivery":
return JsonResponse({"status": "success", "data": "Arrêt des livraisons des articles"})
elif message == "see-orders":
item = item_qs.prefetch_related(
......@@ -233,15 +239,22 @@ class ItemManageView(PermissionRequiredMixin, ListView):
"status": "success",
"data": [
"user": str(oi.order.user.profile),
"display_name": str(oi.order.user.profile),
"email": str(,
"quantity": oi.quantity,
"paid": oi.order.paid,
"customization": oi.customization,
"quantity_delivered": oi.quantity_delivered,
"option_label": oi.item.option_label,
"option": oi.option,
"second_option_label": oi.item.second_option_label,
"second_option": oi.second_option,
"quantity_delivered": oi.quantity_delivered,
"customization": oi.customization,
"paid": oi.order.paid,
"ordered_date": oi.order.ordered_date,
"mean": oi.order.mean,
for oi in item.order_items.all()
for oi in item.order_items.all().order_by("-order__ordered_date")
......@@ -249,7 +262,13 @@ class ItemManageView(PermissionRequiredMixin, ListView):
raise SuspiciousOperation()
def get_queryset(self) -> "QuerySet[Item]":
return Item.objects.order_by("hidden").prefetch_related("order_items")
return Item.objects.annotate(
total_quantity=Coalesce(Sum('order_items__quantity', filter=Q(order_items__order__payment__paid=True)),
quantity_delivered=Coalesce(Sum('order_items__quantity_delivered'), Value(0)),
quantity_to_deliver=Coalesce(Sum('order_items__quantity', filter=Q(order_items__beeing_delivered=True)),
Value(0))) \
class ItemSellView(PermissionRequiredMixin, CreateView):
......@@ -511,7 +530,8 @@ class DeliveryView(PermissionRequiredMixin, ListView):
).select_related("order__user__profile", "order__user", "item")
def boolQueryParam(self, param):
if param == 'true': return True
if param == 'true':
return True
if param == 'false':
return False
......@@ -531,6 +551,10 @@ class DeliveryView(PermissionRequiredMixin, ListView):
if beeing_delivered is not None:
itemList = itemList.filter(beeing_delivered=beeing_delivered)
hidden = self.boolQueryParam(request.GET["hidden"])
if hidden is not None:
itemList = itemList.filter(item__hidden=hidden)
paid = self.boolQueryParam(request.GET["paid"])
if paid is True:
itemList = itemList.filter(order__payment__paid=True)
......@@ -548,7 +572,7 @@ class DeliveryView(PermissionRequiredMixin, ListView):
orderedItems = [
"item": str(orderItem.item),
"image": str(orderItem.item.image),
"image": orderItem.item.get_image_url(),
"display_name": str(orderItem.order.user.profile),
"email": str(,
"quantity": orderItem.quantity,
......@@ -126,6 +126,7 @@
<section id="main_container">
<div id='messages'></div>
{% block messages %} {% endblock messages %}
{% if request.user.is_active and not request.user.profile.is_valid %}
add_message("error", "Veuillez remplir les informations de votre profil svp. (Nom, prénom et/ou surnom)", 0);
This diff is collapsed.
This diff is collapsed.
......@@ -30,7 +30,7 @@
var pictureContainer = document.createElement('div');
pictureContainer.setAttribute('class', 'picture_container');
.setAttribute('src', '/medias/' + item['image']);
.setAttribute('src', item['image']);
var actionContainer = document.createElement('div');
actionContainer.setAttribute('class', 'action_container');
......@@ -123,6 +123,7 @@ function DeliverPopup(item, callback) {
quantityInput.setAttribute('style', 'font-size: larger');
quantityInput.addEventListener('change', is_valid)
quantityInput = body.appendChild(quantityInput);
let button = document.createElement('button');
......@@ -169,7 +170,7 @@ DeliverPopup.prototype.constructor = DeliverPopup;
function CustomizationPopup(title, item, callback) {, title);
this.baseClass = 'selection_popup';
this.baseClass = 'customization_popup';
this.callback = callback;
let button = document.createElement('button');
......@@ -111,11 +111,33 @@
color: $orange
align-content: center
padding: 8px
margin: 0 5px
margin: 5px
background-color: $orange
align-items: center
display: flex
flex-wrap: wrap
flex-direction: row
margin-bottom: 5px
margin-right: 5px
margin-right: 15px
width: 24%
margin-right: 1%
marginright: 0
display: block
......@@ -218,10 +240,7 @@
@supports (grid-template-columns: subgrid)
grid-template-columns: subgrid
align-items: center
border-bottom: solid 1px transparent
&:hover, &:focus-within
border-bottom-color: black
@media screen and (max-width: $mobile-view_treshold)
grid-row: 1/-1
......@@ -15,7 +15,11 @@ button, .button
margin: 5px 2px
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1)
min-height: 40px !important
border-radius: 20px
background: #ddd !important
pointer-events: none
cursor: not-allowed
@keyframes slideDown
height: 0
height: auto
position: sticky
top: 0
z-index: 2
height: auto
@media screen and (max-width: $mobile_view_treshold)
top: 70px
padding: 1em 2em
font-weight: bold
color: white
animation-delay: 0.2s
animation-timing-function: ease-out
animation-duration: 5s
animation-iteration-count: 1
vertical-align: middle
font-size: 3em
@keyframes fadeIn
opacity: 0
opacity: 1
background-color: hsla(0,0,0,0.5)
width: 100%
......@@ -6,6 +15,8 @@
z-index: 10
display: none
padding: 2em
animation-name: fadeIn
animation-duration: 0.5s
& > div
background-color: white
......@@ -54,6 +65,39 @@
background-color: white
max-height: 100%
@extend .popup
display: block
width: 100%
margin: 1em 0
border-radius: 18px
background-color: white
color: #333
border: 1px solid #bbb
background-color: #eaeaea
color: #333 !important
&:active, &.toggled
background-color: #ddd
background: #ddd !important
pointer-events: none
cursor: not-allowed
color: #777
input, select
width: 100%
margin-bottom: 15px
@extend .popup
......@@ -69,10 +113,17 @@
background-color: #eaeaea
color: #333 !important
&:active, &.toggled
background-color: #ddd
background: #ddd !important
pointer-events: none
cursor: not-allowed
color: #777
@extend .selection_popup
$cell-padding: 1em
@media screen and (max-width: $mobile_view_treshold)
display: block
overflow-x: auto
white-space: nowrap
width: 100%
border-collapse: collapse
......@@ -6,25 +15,27 @@ table:not(.rd-days)
background-color: white
padding: 0.5em 0
padding: 0.5em $cell-padding
text-align: left
background-color: #eee
transition: background-color 0.25s
background-color: #f5f5f5
background-color: #dfdfdf
$cell-padding: 1em
padding: $cell-padding
padding-left: $cell-padding
padding-right: $cell-padding
......@@ -41,6 +52,7 @@ table:not(.rd-days)
border-radius: 3px 0 0 3px
border-radius: 0 3px 3px 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment