Automatically hide out of stock products and producers with only out of stock products.

Fixes #15 #16.
This commit is contained in:
Daniel Atwood 2020-06-07 18:23:34 +02:00
parent 38ef1bb374
commit 1b5e07c897
4 changed files with 137 additions and 118 deletions

View file

@ -177,6 +177,10 @@ class Producer(Base):
products = delivery.get_products_by(self.id) products = delivery.get_products_by(self.id)
return any([not p.rupture for p in products]) return any([not p.rupture for p in products])
def has_rupture_products(self, delivery):
products = delivery.get_products_by(self.id)
return any([p.rupture for p in products])
def needs_price_update(self, delivery): def needs_price_update(self, delivery):
products = delivery.get_products_by(self.id) products = delivery.get_products_by(self.id)
return delivery.products_need_price_update(products) return delivery.products_need_price_update(products)
@ -312,7 +316,9 @@ class Delivery(PersistedBase):
def products_need_price_update(self, products=None): def products_need_price_update(self, products=None):
products = products or self.products products = products or self.products
max_age = self.from_date.date() - timedelta(days=60) max_age = self.from_date.date() - timedelta(days=60)
return any([product.last_update.date() < max_age for product in products]) return any([product.last_update.date() < max_age
for product in products
if product.producer in self.producers])
@property @property
def dates(self): def dates(self):

View file

@ -15,43 +15,47 @@
<form method="post"> <form method="post">
{% for producer in delivery.producers.values() %} {% for producer in delivery.producers.values() %}
<h2>{{ producer.name }}</h2> {% if producer.has_active_products(delivery) %}
<table class="order pure-table"> <h2>{{ producer.name }}</h2>
<thead> <table class="order pure-table">
<tr> <thead>
<th class="product">Produit</th> <tr>
<th class="price">Prix</th> <th class="product">Produit</th>
{% if delivery.has_packing %} <th class="price">Prix</th>
<th class="packing">Conditionnement</th> {% if delivery.has_packing %}
{% endif %} <th class="packing">Conditionnement</th>
<th class="amount">Commande</th>
{% if delivery.status == delivery.ADJUSTMENT or force_adjustment %}
<th class="amount">Ajustement +/</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for product in delivery.get_products_by(producer.id) %}
<tr>
<th class="product {% if product.rupture %}rupture{% endif %}">{{ product }} {% if product.rupture %}(RUPTURE !){% endif %}
{% if product.description or product.img %}
{% endif %} {% endif %}
</th> <th class="amount">Commande</th>
<td>{{ product.price | round(2) }} €</td> {% if delivery.status == delivery.ADJUSTMENT or force_adjustment %}
{% if delivery.has_packing %} <th class="amount">Ajustement +/</th>
<td {% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} class="missing" title="Les commandes individuelles ne correspondent pas aux conditionnements"{% endif %}>{{ product.packing or "—" }}{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} (manque {{ delivery.product_missing(product) }}){% endif %}</td> {% endif %}
{% endif %} </tr>
<td class="with-input"><input {% if not request.user.is_referent(delivery) and delivery.status != delivery.OPEN or product.rupture %}type="text" readonly{% else%}type="number"{% endif%} min=0 name="wanted:{{ product.ref }}" value="{{ order[product].wanted }}">{% if not (delivery.status == delivery.ADJUSTMENT or force_adjustments) %} x {{ product.unit }}{% endif %}</td> </thead>
{% if delivery.status == delivery.ADJUSTMENT or force_adjustments %} <tbody>
<td class="with-input"><input type="number" name="adjustment:{{ product.ref }}" value="{{ order[product].adjustment }}" min="{{ order[product].wanted * -1 }}" {% if not (delivery.product_missing(product) or force_adjustment) %}readonly{% endif %}> x {{ product.unit }}</td> {% for product in delivery.get_products_by(producer.id) %}
{% endif %} {% if not product.rupture %}
</tr> <tr>
{% endfor %} <th class="product {% if product.rupture %}rupture{% endif %}">{{ product }} {% if product.rupture %}(RUPTURE !){% endif %}
</tbody> {% if product.description or product.img %}
</table> {% endif %}
</th>
<td>{{ product.price | round(2) }} €</td>
{% if delivery.has_packing %}
<td {% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} class="missing" title="Les commandes individuelles ne correspondent pas aux conditionnements"{% endif %}>{{ product.packing or "—" }}{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} (manque {{ delivery.product_missing(product) }}){% endif %}</td>
{% endif %}
<td class="with-input"><input {% if not request.user.is_referent(delivery) and delivery.status != delivery.OPEN or product.rupture %}type="text" readonly{% else%}type="number"{% endif%} min=0 name="wanted:{{ product.ref }}" value="{{ order[product].wanted }}">{% if not (delivery.status == delivery.ADJUSTMENT or force_adjustments) %} x {{ product.unit }}{% endif %}</td>
{% if delivery.status == delivery.ADJUSTMENT or force_adjustments %}
<td class="with-input"><input type="number" name="adjustment:{{ product.ref }}" value="{{ order[product].adjustment }}" min="{{ order[product].wanted * -1 }}" {% if not (delivery.product_missing(product) or force_adjustment) %}readonly{% endif %}> x {{ product.unit }}</td>
{% endif %}
</tr>
{%- endif %}
{% endfor %}
</tbody>
</table>
{%- endif %}
{% endfor %} {% endfor %}
<p>On y est presque ! Est-ce que tu peux entrer un numéro de téléphone au cas où on ait besoin de vous joindre ?</p> <p>On y est presque ! Est-ce que tu peux entrer un numéro de téléphone au cas où on ait besoin de vous joindre ?</p>
<input type="text" name="phone_number" value="{{ order.phone_number }}" placeholder="06 12 34 56 78"> <input type="text" name="phone_number" value="{{ order.phone_number }}" placeholder="Ton numéro de téléphone" required>
<input type="hidden" name="email" value="{{ person.email }}"> <input type="hidden" name="email" value="{{ person.email }}">
{% if delivery.status != delivery.CLOSED or request.user.is_staff %} {% if delivery.status != delivery.CLOSED or request.user.is_staff %}
<input type="submit" value="Enregistrer la commande" class="primary"> <input type="submit" value="Enregistrer la commande" class="primary">

View file

@ -62,6 +62,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% include "includes/delivery_table.html" %} {% include "includes/delivery_table.html" %}
{% else %} {% else %}
<div class="placeholder"> <div class="placeholder">
<h2>😔 Pour le moment, cette distribution est bien vide…</h2> <h2>😔 Pour le moment, cette distribution est bien vide…</h2>

View file

@ -5,92 +5,100 @@
{% endif %} {% endif %}
{% for producer in producers %} {% for producer in producers %}
{% set producer_obj = delivery.producers[producer] %} {% set producer_obj = delivery.producers[producer] %}
<h2>{{ producer_obj.name }} {% if edit_mode or producer_obj.has_active_products(delivery) %}
{% if producer_obj.needs_price_update(delivery) %}*{% endif %} <h2>{{ producer_obj.name }}
{% if edit_mode or request.user.is_staff or producer_obj.referent == request.user.email %} {% if producer_obj.needs_price_update(delivery) %}*{% endif %}
<span class="edit"> {% if edit_mode or request.user.is_staff or producer_obj.referent == request.user.email %}
<a class="button" href="{{ url_for('edit_producer', delivery_id=delivery.id, producer_id=producer_obj.id) }}"><i class="icon-ribbon"></i>&nbsp; Gérer ce⋅tte producteur⋅rice</a> <span class="edit">
</span> <a class="button" href="{{ url_for('edit_producer', delivery_id=delivery.id, producer_id=producer_obj.id) }}"><i class="icon-ribbon"></i>&nbsp; Gérer ce⋅tte producteur⋅rice</a>
{% endif %} </span>
</h2>
<h5>{% if producer_obj.description %}{{ producer_obj.description }}{% endif %}. Référent⋅e : <a href="mailto:{{ producer_obj.referent }}">{{ producer_obj.referent_name }}</a> / {{ producer_obj.referent_tel }}</h5>
{% if not delivery.get_products_by(producer) %}
😔 Ce⋅tte producteur⋅rice n'a pas encore de produits. Voulez vous <a href="{{ url_for('create_product', delivery_id=delivery.id, producer_id=producer_obj.id) }}">en rajouter un ?</a>
{% else %}
<table class="delivery pure-table">
<thead>
<tr>
<th class="product">Produit</th>
<th class="price">Prix</th>
{% if delivery.has_packing %}
<th class="packing">Conditionnement</th>
{% endif %} {% endif %}
<th class="amount">Total</th> </h2>
{% if not list_only %} <h5>{% if producer_obj.description %}{{ producer_obj.description }}{% endif %}Référent⋅e : <a href="mailto:{{ producer_obj.referent }}">{{ producer_obj.referent_name }}</a> / {{ producer_obj.referent_tel }}.
{% for orderer, order in delivery.orders.items() %} {% if not edit_mode and producer_obj.has_rupture_products(delivery) %}
{% set orderer_name = request.groups.groups[orderer].name %} <p><em>Certains produits sont en rupture de stock.</em></p>
<th class="person"> {% endif %}
{% if request.user and (request.user.is_staff or request.user.is_referent(delivery)) %} </h5>
<a class="underline" href="{{ url_for('place_order', id=delivery.id) }}?orderer={{ orderer }}" title="{{ orderer }}">{{ orderer_name }} <i class="icon-pencil"></i></a> {% if not delivery.get_products_by(producer) %}
{% else %} 😔 Ce⋅tte producteur⋅rice n'a pas encore de produits. Voulez vous <a href="{{ url_for('create_product', delivery_id=delivery.id, producer_id=producer_obj.id) }}">en rajouter un ?</a>
<span title="{{ orderer }}">{{ orderer_name }}</span> {% else %}
<table class="delivery pure-table">
<thead>
<tr>
<th class="product">Produit</th>
<th class="price">Prix</th>
{% if delivery.has_packing %}
<th class="packing">Conditionnement</th>
{% endif %} {% endif %}
</th> <th class="amount">Total</th>
{% endfor %} {% if not list_only %}
{% endif %} {% for orderer, order in delivery.orders.items() %}
</tr> {% set orderer_name = request.groups.groups[orderer].name %}
</thead> <th class="person">
<tbody> {% if request.user and (request.user.is_staff or request.user.is_referent(delivery)) %}
{% for product in delivery.get_products_by(producer) %} <a class="underline" href="{{ url_for('place_order', id=delivery.id) }}?orderer={{ orderer }}" title="{{ orderer }}">{{ orderer_name }} <i class="icon-pencil"></i></a>
<tr> {% else %}
<th class="product {% if product.rupture %}rupture{% endif %}">{% if edit_mode %}<a href="{{ url_for('edit_product', delivery_id=delivery.id, producer_id=producer_obj.id, product_ref=product.ref) }}">{% endif %}{% if edit_mode %}<i class="icon-pencil"></i>&nbsp;{% endif %}{% if product.rupture %} (rupture){% endif %} {{ product }}{% if edit_mode %}</a>{% endif %} <span title="{{ orderer }}">{{ orderer_name }}</span>
<td>{{ product.price | round(2) }} €</td> {% endif %}
{% if delivery.has_packing %} </th>
<td class="packing">{% if product.packing %}{{ product.packing }} x {% endif %} {{ product.unit }}</td> {% endfor %}
{% endif %} {% endif %}
<th{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} class="missing" title="Les commandes individuelles ne correspondent pas aux conditionnements"{% endif %}> </tr>
{{ delivery.product_wanted(product) }} </thead>
{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} ({{ delivery.product_missing(product) }}) <tbody>
{% if request.user.is_staff %}<a href="{{ url_for('adjust_product', id=delivery.id, ref=product.ref) }}" class="button" title="ajuster le produit">ajuster</a>{% endif %} {% for product in delivery.get_products_by(producer) %}
{% if edit_mode or not product.rupture %}
<tr>
<th class="product {% if product.rupture %}rupture{% endif %}">{% if edit_mode %}<a href="{{ url_for('edit_product', delivery_id=delivery.id, producer_id=producer_obj.id, product_ref=product.ref) }}">{% endif %}{% if edit_mode %}<i class="icon-pencil"></i>&nbsp;{% endif %}{% if product.rupture %} (rupture){% endif %} {{ product }}{% if edit_mode %}</a>{% endif %}
<td>{{ product.price | round(2) }} €</td>
{% if delivery.has_packing %}
<td class="packing">{% if product.packing %}{{ product.packing }} x {% endif %} {{ product.unit }}</td>
{% endif %}
<th{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} class="missing" title="Les commandes individuelles ne correspondent pas aux conditionnements"{% endif %}>
{{ delivery.product_wanted(product) }}
{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} ({{ delivery.product_missing(product) }})
{% if request.user.is_staff %}<a href="{{ url_for('adjust_product', id=delivery.id, ref=product.ref) }}" class="button" title="ajuster le produit">ajuster</a>{% endif %}
{% endif %}
</th>
{% if not list_only %}
{% for email, order in delivery.orders.items() %}
<td title="Commandé: {{ order[product.ref].wanted }} — Ajusté: {{ "%+d"|format(order[product.ref].adjustment) }}">{{ order[product.ref].quantity or "—" }}</td>
{% endfor %}
{% endif %}
</tr>
{% endif %} {% endif %}
</th>
{% if not list_only %}
{% for email, order in delivery.orders.items() %}
<td title="Commandé: {{ order[product.ref].wanted }} — Ajusté: {{ "%+d"|format(order[product.ref].adjustment) }}">{{ order[product.ref].quantity or "—" }}</td>
{% endfor %}
{% endif %}
</tr>
{% endfor %}
{% if delivery.shipping.get(producer) %}
<tr>
<th class="shipping"><i class="icon-map"></i>Frais de livraison</th>
<td></td>
{% if delivery.has_packing %}
<td></td>
{% endif %}
<th class="shipping">{{ delivery.shipping[producer] }} €</th>
{% if not list_only %}
{% for email, order in delivery.orders.items() %}
<td>{{ delivery.shipping_for(email, producer)|round(2) }} €</td>
{% endfor %} {% endfor %}
{% endif %} {% if delivery.shipping.get(producer) %}
</tr> <tr>
<th class="shipping"><i class="icon-map"></i>Frais de livraison</th>
<td></td>
{% if delivery.has_packing %}
<td></td>
{% endif %}
<th class="shipping">{{ delivery.shipping[producer] }} €</th>
{% if not list_only %}
{% for email, order in delivery.orders.items() %}
<td>{{ delivery.shipping_for(email, producer)|round(2) }} €</td>
{% endfor %}
{% endif %}
</tr>
{% endif %}
<tr>
<th class="total"><i class="icon-pricetags"></i> Total</th><td></td>
{% if delivery.has_packing %}
<td></td>
{% endif %}
<th class="total">{{ delivery.total_for_producer(producer) }} €</th>
{% if not list_only %}
{% for email, order in delivery.orders.items() %}
<td>{{ order.total(delivery.get_products_by(producer), delivery, email) }} €</td>
{% endfor %}
{% endif %}
</tr>
</tbody>
</table>
{% endif %} {% endif %}
<tr> <br />
<th class="total"><i class="icon-pricetags"></i> Total</th><td></td> {%- endif %}
{% if delivery.has_packing %}
<td></td>
{% endif %}
<th class="total">{{ delivery.total_for_producer(producer) }} €</th>
{% if not list_only %}
{% for email, order in delivery.orders.items() %}
<td>{{ order.total(delivery.get_products_by(producer), delivery, email) }} €</td>
{% endfor %}
{% endif %}
</tr>
</tbody>
</table>
{% endif %}
<br />
{% endfor %} {% endfor %}