From 165427bf8f0861e16bc46121aaa1522e99d0514d Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 13 Apr 2019 11:14:59 +0200 Subject: [PATCH] WIP: deal with product packing --- copanier/models.py | 15 ++++++++++++++- copanier/static/app.css | 4 ++++ copanier/templates/delivery.html | 13 +++++++++++-- copanier/templates/edit_delivery.html | 2 ++ copanier/templates/place_order.html | 6 ++++-- tests/test_views.py | 4 ++-- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/copanier/models.py b/copanier/models.py index 1b32c12..ceef0f1 100644 --- a/copanier/models.py +++ b/copanier/models.py @@ -44,7 +44,8 @@ class Base: for name, field_ in self.__dataclass_fields__.items(): value = getattr(self, name) type_ = field_.type - if not isinstance(value, Base): # Do not recast our classes. + # Do not recast our classes. + if not isinstance(value, Base) and value is not None: try: setattr(self, name, self.cast(type_, value)) except (TypeError, ValueError): @@ -95,6 +96,7 @@ class Product(Base): description: str = "" url: str = "" img: str = "" + packing: int = None @property def label(self): @@ -159,6 +161,10 @@ class Delivery(Base): def is_passed(self): return not self.is_foreseen + @property + def has_packing(self): + return any(p.packing for p in self.products) + @classmethod def init_fs(cls): cls.get_root().mkdir(parents=True, exist_ok=True) @@ -198,3 +204,10 @@ class Delivery(Base): if product.ref in order.products: total += order.products[product.ref].wanted return total + + def product_missing(self, product): + if not product.packing: + return 0 + wanted = self.product_wanted(product) + orphan = wanted % product.packing + return product.packing - orphan if orphan else 0 diff --git a/copanier/static/app.css b/copanier/static/app.css index 19c9731..087f87d 100644 --- a/copanier/static/app.css +++ b/copanier/static/app.css @@ -363,6 +363,10 @@ article.delivery { article.delivery th.person { max-width: 7rem; } +td.missing, +th.missing { + background-color: #db7734; +} hr { background-color: #dbdbdb; border: none; diff --git a/copanier/templates/delivery.html b/copanier/templates/delivery.html index bde0e29..0133af1 100644 --- a/copanier/templates/delivery.html +++ b/copanier/templates/delivery.html @@ -10,6 +10,9 @@ Référence Produit Prix + {% if delivery.has_packing %} + Lot + {% endif %} Total {% for email, order in delivery.orders.items() %} @@ -26,7 +29,10 @@ {{ product.ref }} {{ product.label }} {{ product.price }} € - {{ delivery.product_wanted(product) }} + {% if delivery.has_packing %} + {{ product.packing or '—'}} + {% endif %} + {{ delivery.product_wanted(product) }}{% if delivery.product_missing(product) %} ({{ delivery.product_missing(product) }}){% endif %} {% for email, order in delivery.orders.items() %} {% if product.ref in order.products %} {{ order.products[product.ref].wanted }} @@ -37,7 +43,10 @@ {% endfor %} Total—— - {{ delivery.total }} € + {% if delivery.has_packing %} + — + {% endif %} + {{ delivery.total }} € {% for email, order in delivery.orders.items() %} {{ order.total(delivery.products) }} € {% endfor %} diff --git a/copanier/templates/edit_delivery.html b/copanier/templates/edit_delivery.html index 456da85..cd3dd31 100644 --- a/copanier/templates/edit_delivery.html +++ b/copanier/templates/edit_delivery.html @@ -52,6 +52,8 @@
Conditionnement d'une unité: 1kg, 33cl…
description
Plus de détails sur le produit.
+
packing
+
Contionnement final pour grouper les commandes, le cas échéant, en nombre d'unités.
url
Une URL éventuelle pointant sur une page présentant le produit.
img
diff --git a/copanier/templates/place_order.html b/copanier/templates/place_order.html index dd56c10..468445c 100644 --- a/copanier/templates/place_order.html +++ b/copanier/templates/place_order.html @@ -6,7 +6,7 @@ {% include "includes/delivery_head.html" %}
- + {% for product in delivery.products %} - + + {{ product.packing or "—" }}{% if delivery.product_missing(product) %} (manque {{ delivery.product_missing(product) }}){% endif %} + {% endfor %}
ProduitPrixQuantité
ProduitPrixLotQuantité
{{ product.label }} @@ -16,7 +16,9 @@ {% endwith %} {% endif %}

{{ product.price }} €
{{ product.price }} €

Total: {{ order.total(delivery.products) if order else 0 }} €

diff --git a/tests/test_views.py b/tests/test_views.py index 98e4aac..24a3ff2 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -101,6 +101,6 @@ async def test_export_products(client, delivery): resp = await client.get(f"/livraison/{delivery.id}/exporter/produits") wb = load_workbook(filename=BytesIO(resp.body)) assert list(wb.active.values) == [ - ("name", "ref", "price", "unit", "description", "url", "img"), - ("Lait", "123", 1.5, None, None, None, None), + ("name", "ref", "price", "unit", "description", "url", "img", "packing"), + ("Lait", "123", 1.5, None, None, None, None, None), ]