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">
<h1>Livraison</h1>
<script>
var url = new URL(window.location.href);
console.log(url.searchParams)
function applyFilter() {
......@@ -25,28 +25,28 @@
</script>
<form onchange="generateTable()">
<label for="delivered">Déjà remis</label>
<label for="delivered">Déjà remis :</label>
<select id="delivered"
onchange="generateTable()">
<option value="both">Tous</option>
<option value="true">Oui</option>
<option value="false">Non</option>
</select>
<label for="beeing_delivered">Distribution en cours</label>
<label for="beeing_delivered">Distribution en cours :</label>
<select id="beeing_delivered"
onchange="generateTable()">
<option value="true">Oui</option>
<option value="false">Non</option>
<option value="both">Tous</option>
</select>
<label for="hidden">Produits cachés</label>
<label for="hidden">Produits cachés :</label>
<select id="hidden"
onchange="generateTable()">
<option value="true">Oui</option>
<option value="false">Non</option>
<option selected value="false">Non</option>
<option value="both">Tous</option>
</select>
<label for="paid">Payé</label>
<label for="paid">Payé :</label>
<select id="paid"
onchange="generateTable()">
<option value="true">Oui</option>
......@@ -54,25 +54,25 @@
<option value="both">Tous</option>
</select>
<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>
</select>
</form>
<form onblur="generateTable()"
onkeypress="onEnter(event)">
<input placeholder="Email"
type="search"
id="emailContains">
<input placeholder="Produit"
type="search"
id="productContains">
<input placeholder="Email"
type="search"
id="emailContains">
<input placeholder="Option (valeur exacte)"
type="search"
id="optionContains">
......@@ -108,6 +108,7 @@
}
</script>
</div>
{% 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>
<a href="{% url 'boutique:delivery' %}">
<button>Distribution</button>
</a>
<a href="{% url 'boutique:item_sell' %}">
<button>Vente en directe</button>
</a>
<a href="{% url 'boutique:manage_category' %}">
<button>Ajouter une catégorie</button>
</a>
<br/>
<section class="item-manage-list">
{% for item in object_list %}
<article data-id="{{ item.id }}"
data-pk="{{ item.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="{{ item.id }}" class="hidden">
{% else %}
<article data-id="{{ item.id }}">
class="hidden"
{% endif %}
>
<img class="image" src="{{ item.get_image_url }}" alt="">
<h2>{{ item.name }}</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>
<div>
<a href="{% url 'boutique:item_edit' pk=item.pk %}" class="delivery_list button tooltip">
<i class="fas fa-edit"><span class="tooltiptext">Modifier</span></i>
</a>
<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>
<button class="delivery_list tooltip stop-delivery"><i class="fas fa-ban"></i> <span
class="tooltiptext">Arrêter la distribution des articles</span>
</button>
<button class="delivery_list tooltip see-orders"><i class="fas fa-eye"></i> <span
class="tooltiptext">Voir les commandes</span>
</button>
<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' pk=item.id %}'"><i
class="fas fa-download"></i> <span class="tooltiptext">Exporter les commandes</span>
</button>
<button class="delivery_list tooltip dl-orders" onclick="window.location.href = '{% url 'boutique:csvexport' pk=item.id %}'"><i class="fas fa-download"></i> <span class="tooltiptext">Voir les commandes</span>
{% if perms.boutique.sell %}
<button class="delivery_list tooltip" onclick="sell(event)"><i class="fas fa-hand-holding-usd"></i> <span
class="tooltiptext">Vente en direct</span>
</button>
{% endif %}
</div>
</article>
......@@ -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 = "boutique.management"
def post(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
def options(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
req = json.loads(request.read().decode())
pk = req.get("id")
......@@ -221,8 +223,12 @@ class ItemManageView(PermissionRequiredMixin, ListView):
message = req.get("message")
if message == "begin-delivery":
item_qs.get().order_items.update(beeing_delivered=True)
return JsonResponse({"status": "success", "data": "Bien reçu"})
item_qs.get().order_items.filter(order__payment__paid=True).update(beeing_delivered=True)
return JsonResponse({"status": "success", "data": "Début des livraisons des articles déjà commandé"})
if message == "stop-delivery":
item_qs.get().order_items.update(beeing_delivered=False)
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(oi.order.user.email),
"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)),
Value(0)),
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))) \
.order_by("hidden").prefetch_related("order_items")
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
else:
......@@ -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 = [
{"id": orderItem.id,
"item": str(orderItem.item),
"image": str(orderItem.item.image),
"image": orderItem.item.get_image_url(),
"display_name": str(orderItem.order.user.profile),
"email": str(orderItem.order.user.email),
"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 %}
<script>
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');
pictureContainer.appendChild(document.createElement('img'))
.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);
this.main.appendChild(body);
let button = document.createElement('button');
......@@ -169,7 +170,7 @@ DeliverPopup.prototype.constructor = DeliverPopup;
function CustomizationPopup(title, item, callback) {
Popup.call(this, 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
&:hover
background-color: $orange
.delivery
form
align-items: center
display: flex
flex-wrap: wrap
flex-direction: row
margin-bottom: 5px
label
margin-right: 5px
select
margin-right: 15px
input
width: 24%
margin-right: 1%
&:last-child
marginright: 0
.basket_table
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
&:disabled
background: #ddd !important
pointer-events: none
cursor: not-allowed
i
......
@keyframes slideDown
from
height: 0
to
height: auto
#messages
position: sticky
top: 0
z-index: 2
height: auto
@media screen and (max-width: $mobile_view_treshold)
#messages
top: 70px
.message
padding: 1em 2em
font-weight: bold
color: white
animation-delay: 0.2s
animation-timing-function: ease-out
animation-duration: 5s
animation-iteration-count: 1
i
vertical-align: middle
font-size: 3em
......
@keyframes fadeIn
0%
opacity: 0
100%
opacity: 1
.popup
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%
.customization_popup
@extend .popup
main
button
display: block
width: 100%
margin: 1em 0
border-radius: 18px
background-color: white
color: #333
border: 1px solid #bbb
&:hover
background-color: #eaeaea
color: #333 !important
&:active, &.toggled
background-color: #ddd
&:disabled
background: #ddd !important
pointer-events: none
cursor: not-allowed
color: #777
input, select
width: 100%
margin-bottom: 15px
.selection_popup
@extend .popup
......@@ -69,10 +113,17 @@
&:hover
background-color: #eaeaea
color: #333 !important
&:active, &.toggled
background-color: #ddd
&:disabled
background: #ddd !important
pointer-events: none
cursor: not-allowed
color: #777
.user_selection_popup
@extend .selection_popup
......
$cell-padding: 1em
@media screen and (max-width: $mobile_view_treshold)
table
display: block
overflow-x: auto
white-space: nowrap
table:not(.rd-days)
width: 100%
border-collapse: collapse
......@@ -6,25 +15,27 @@ table:not(.rd-days)
background-color: white
th
padding: 0.5em 0
padding: 0.5em $cell-padding
text-align: left
tbody
tr
background-color: #eee
transition: background-color 0.25s
&:nth-child(2n)
background-color: #f5f5f5
&:hover
background-color: #dfdfdf
$cell-padding: 1em
td
padding: $cell-padding
&:first-child
padding-left: $cell-padding
&:last-child
padding-right: $cell-padding
......@@ -41,6 +52,7 @@ table:not(.rd-days)
&:first-child
border-radius: 3px 0 0 3px
&:last-child
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