Merci de mettre à jour les prix pour « {{ producer.name }} ».
+ {% endif %} + {% endfor %} {% include "includes/delivery_table.html" %} {% else %}diff --git a/TODO b/TODO index 52fd8b3..2ef347a 100644 --- a/TODO +++ b/TODO @@ -12,8 +12,11 @@ x Faciliter la duplication de distribution x Si un produit est en rupture de stock, alors il n'est pas compté dans les totaux x Permettre la supression des produits x Permettre la suppression de producteurs +x Ajouter une info « prix mis à jour » pour les référent⋅e⋅s + +Gérer le souci d'URL pour l'édition d'Apiluly +Rendre le formulaire d'édition producteur plus compact -Ajouter une info « prix mis à jour » pour les référent⋅e⋅s Gérer les frais de livraison Rendre plus visible l'action de modifier une commande diff --git a/copanier/models.py b/copanier/models.py index a86f2e2..6a2837c 100644 --- a/copanier/models.py +++ b/copanier/models.py @@ -1,7 +1,7 @@ import inspect import threading import uuid -from datetime import datetime +from datetime import datetime, timedelta from dataclasses import dataclass, field, asdict from pathlib import Path from typing import List, Dict @@ -174,6 +174,10 @@ class Producer(Base): products = delivery.get_products_by(self.id) return any([not 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) + @dataclass class Product(Base): @@ -258,9 +262,10 @@ class Delivery(PersistedBase): __lock__ = threading.Lock() EMPTY = -1 CLOSED = 0 - OPEN = 1 - ADJUSTMENT = 2 - ARCHIVED = 3 + NEED_PRICE_UPDATE = 1 + OPEN = 2 + ADJUSTMENT = 3 + ARCHIVED = 4 name: str from_date: datetime_field @@ -283,12 +288,19 @@ class Delivery(PersistedBase): return self.EMPTY if self.is_archived: return self.ARCHIVED + if self.products_need_price_update(): + return self.NEED_PRICE_UPDATE if self.is_open: return self.OPEN if self.needs_adjustment: return self.ADJUSTMENT return self.CLOSED + 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]) + @property def has_products(self): return len(self.products) > 0 diff --git a/copanier/templates/delivery/show.html b/copanier/templates/delivery/show.html index 2886e0d..afd7138 100644 --- a/copanier/templates/delivery/show.html +++ b/copanier/templates/delivery/show.html @@ -3,7 +3,13 @@
Merci de mettre à jour les prix pour « {{ producer.name }} ».
+ {% endif %} + {% endfor %} {% include "includes/delivery_table.html" %} {% else %}Les prix pour {{ producer.name }} ont besoin d'être validés.
+{% endif %} {% if products %} -Vous pouvez éditer les produits en cliquant sur leur nom.