From 21578d0c81ec498d91692876593ce809708b2763 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sun, 31 Mar 2019 19:46:18 +0200 Subject: [PATCH] Allow to mark orders as paid And display in orange unpaid colmuns --- copanier/__init__.py | 2 +- copanier/config.py | 2 -- copanier/models.py | 5 +++++ copanier/static/app.css | 9 +++++++++ copanier/templates/delivery.html | 2 +- copanier/templates/place_order.html | 5 ++++- tests/test_views.py | 13 +++++++++++++ 7 files changed, 33 insertions(+), 5 deletions(-) diff --git a/copanier/__init__.py b/copanier/__init__.py index 758727e..f9b720b 100644 --- a/copanier/__init__.py +++ b/copanier/__init__.py @@ -237,7 +237,7 @@ async def place_order(request, response, id): return if request.method == "POST": form = request.form - order = Order() + order = Order(paid=form.bool("paid", False)) for product in delivery.products: quantity = form.int(product.ref, 0) if quantity: diff --git a/copanier/config.py b/copanier/config.py index 3acddf4..ae79482 100644 --- a/copanier/config.py +++ b/copanier/config.py @@ -1,8 +1,6 @@ import os from pathlib import Path -getenv = os.environ.get - DATA_ROOT = Path(__file__).parent.parent / "db" SECRET = "sikretfordevonly" JWT_ALGORITHM = "HS256" diff --git a/copanier/models.py b/copanier/models.py index 5a8d364..b98c259 100644 --- a/copanier/models.py +++ b/copanier/models.py @@ -107,6 +107,7 @@ class ProductOrder(Base): @dataclass class Order(Base): products: Dict[str, ProductOrder] = field(default_factory=lambda *a, **k: {}) + paid: bool = False def get_quantity(self, product): choice = self.products.get(product.ref) @@ -147,6 +148,10 @@ class Delivery(Base): def is_foreseen(self): return datetime.now().date() <= self.from_date.date() + @property + def is_passed(self): + return not self.is_foreseen + @classmethod def init_fs(cls): cls.get_root().mkdir(parents=True, exist_ok=True) diff --git a/copanier/static/app.css b/copanier/static/app.css index e419d06..f925cf0 100644 --- a/copanier/static/app.css +++ b/copanier/static/app.css @@ -263,6 +263,12 @@ select { display: flex; } +input[type=checkbox] { + height: 1rem; + padding: 0; + vertical-align: bottom; +} + input:focus, select:focus { box-shadow: 0 0 .1rem var(--primary-color); @@ -393,6 +399,9 @@ hr { .notification i { font-size: 2rem; } +.not-paid { + background-color: #db7734; +} .toggle { display: none; } diff --git a/copanier/templates/delivery.html b/copanier/templates/delivery.html index 06cfd05..b5bb6d8 100644 --- a/copanier/templates/delivery.html +++ b/copanier/templates/delivery.html @@ -12,7 +12,7 @@ Prix Total {% for email, order in delivery.orders.items() %} - + {% if request.user and request.user.is_staff %} {{ email }} {% else %} diff --git a/copanier/templates/place_order.html b/copanier/templates/place_order.html index 928c05d..c9d5138 100644 --- a/copanier/templates/place_order.html +++ b/copanier/templates/place_order.html @@ -20,8 +20,11 @@ {% endfor %}

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

+ {% if delivery.is_passed %} +

Commande soldée:

+ {% endif %} - + Envoyer par courriel diff --git a/tests/test_views.py b/tests/test_views.py index 84dd048..33d7224 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -74,3 +74,16 @@ async def test_place_empty_order_should_delete_previous(client, delivery): assert resp.status == 302 delivery = Delivery.load(delivery.id) assert not delivery.orders + + +async def test_change_paid_status_when_placing_order(client, delivery): + delivery.persist() + body = { + "123": "3", + "paid": 1 + } + resp = await client.post(f"/livraison/{delivery.id}/commander", body=body) + assert resp.status == 302 + delivery = Delivery.load(id=delivery.id) + assert delivery.orders["foo@bar.org"] + assert delivery.orders["foo@bar.org"].paid is True