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

Fixes #15 #16.
This commit is contained in:
Alexis MÃtaireau 2020-06-07 18:23:34 +02:00
parent 3767620205
commit a4865563fa
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)
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):
products = delivery.get_products_by(self.id)
return delivery.products_need_price_update(products)
@ -312,7 +316,9 @@ class Delivery(PersistedBase):
def products_need_price_update(self, products=None):
products = products or self.products
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
def dates(self):

View file

@ -15,43 +15,47 @@
<form method="post">
{% for producer in delivery.producers.values() %}
<h2>{{ producer.name }}</h2>
<table class="order pure-table">
<thead>
<tr>
<th class="product">Produit</th>
<th class="price">Prix</th>
{% if delivery.has_packing %}
<th class="packing">Conditionnement</th>
{% endif %}
<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 %}
{% if producer.has_active_products(delivery) %}
<h2>{{ producer.name }}</h2>
<table class="order pure-table">
<thead>
<tr>
<th class="product">Produit</th>
<th class="price">Prix</th>
{% if delivery.has_packing %}
<th class="packing">Conditionnement</th>
{% 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>
{% endfor %}
</tbody>
</table>
<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) %}
{% if not product.rupture %}
<tr>
<th class="product {% if product.rupture %}rupture{% endif %}">{{ product }} {% if product.rupture %}(RUPTURE !){% endif %}
{% if product.description or product.img %}
{% 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 %}
<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 }}">
{% if delivery.status != delivery.CLOSED or request.user.is_staff %}
<input type="submit" value="Enregistrer la commande" class="primary">

View file

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

View file

@ -5,92 +5,100 @@
{% endif %}
{% for producer in producers %}
{% set producer_obj = delivery.producers[producer] %}
<h2>{{ producer_obj.name }}
{% if producer_obj.needs_price_update(delivery) %}*{% endif %}
{% if edit_mode or request.user.is_staff or producer_obj.referent == request.user.email %}
<span class="edit">
<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>
{% endif %}
</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>
{% if edit_mode or producer_obj.has_active_products(delivery) %}
<h2>{{ producer_obj.name }}
{% if producer_obj.needs_price_update(delivery) %}*{% endif %}
{% if edit_mode or request.user.is_staff or producer_obj.referent == request.user.email %}
<span class="edit">
<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>
{% endif %}
<th class="amount">Total</th>
{% if not list_only %}
{% for orderer, order in delivery.orders.items() %}
{% set orderer_name = request.groups.groups[orderer].name %}
<th class="person">
{% if request.user and (request.user.is_staff or request.user.is_referent(delivery)) %}
<a class="underline" href="{{ url_for('place_order', id=delivery.id) }}?orderer={{ orderer }}" title="{{ orderer }}">{{ orderer_name }} <i class="icon-pencil"></i></a>
{% else %}
<span title="{{ orderer }}">{{ orderer_name }}</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 }}.
{% if not edit_mode and producer_obj.has_rupture_products(delivery) %}
<p><em>Certains produits sont en rupture de stock.</em></p>
{% endif %}
</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 %}
</th>
{% endfor %}
{% endif %}
</tr>
</thead>
<tbody>
{% for product in delivery.get_products_by(producer) %}
<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 %}
<th class="amount">Total</th>
{% if not list_only %}
{% for orderer, order in delivery.orders.items() %}
{% set orderer_name = request.groups.groups[orderer].name %}
<th class="person">
{% if request.user and (request.user.is_staff or request.user.is_referent(delivery)) %}
<a class="underline" href="{{ url_for('place_order', id=delivery.id) }}?orderer={{ orderer }}" title="{{ orderer }}">{{ orderer_name }} <i class="icon-pencil"></i></a>
{% else %}
<span title="{{ orderer }}">{{ orderer_name }}</span>
{% endif %}
</th>
{% endfor %}
{% endif %}
</tr>
</thead>
<tbody>
{% 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 %}
</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 %}
{% endif %}
</tr>
{% endif %}
<tr>
<th class="total"><i class="icon-pricetags"></i> Total</th><td></td>
{% if delivery.has_packing %}
<td></td>
{% endif %}
{% 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 %}
{% 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 %}
<br />
<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 />
{%- endif %}
{% endfor %}