mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Automatically hide out of stock products and producers with only out of stock products.
Fixes #15 #16.
This commit is contained in:
parent
38ef1bb374
commit
1b5e07c897
4 changed files with 137 additions and 118 deletions
|
@ -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):
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
<form method="post">
|
||||
{% for producer in delivery.producers.values() %}
|
||||
{% if producer.has_active_products(delivery) %}
|
||||
<h2>{{ producer.name }}</h2>
|
||||
<table class="order pure-table">
|
||||
<thead>
|
||||
|
@ -32,6 +33,7 @@
|
|||
</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 %}
|
||||
|
@ -46,12 +48,14 @@
|
|||
<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">
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
{% endif %}
|
||||
{% for producer in producers %}
|
||||
{% set producer_obj = delivery.producers[producer] %}
|
||||
{% 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 %}
|
||||
|
@ -13,7 +14,11 @@
|
|||
</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>
|
||||
<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 %}
|
||||
|
@ -42,6 +47,7 @@
|
|||
</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> {% endif %}{% if product.rupture %} (rupture){% endif %} {{ product }}{% if edit_mode %}</a>{% endif %}
|
||||
<td>{{ product.price | round(2) }} €</td>
|
||||
|
@ -60,6 +66,7 @@
|
|||
{% endfor %}
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if delivery.shipping.get(producer) %}
|
||||
<tr>
|
||||
|
@ -93,4 +100,5 @@
|
|||
</table>
|
||||
{% endif %}
|
||||
<br />
|
||||
{%- endif %}
|
||||
{% endfor %}
|
Loading…
Reference in a new issue