Allow to mark orders as paid

And display in orange unpaid colmuns
This commit is contained in:
Yohan Boniface 2019-03-31 19:46:18 +02:00
parent bc802cae42
commit 21578d0c81
7 changed files with 33 additions and 5 deletions

View file

@ -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:

View file

@ -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"

View file

@ -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)

View file

@ -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;
}

View file

@ -12,7 +12,7 @@
<th class="price">Prix</th>
<th class="amount">Total</th>
{% for email, order in delivery.orders.items() %}
<th class="person">
<th class="person{% if delivery.is_passed and not order.paid %} not-paid{% endif %}">
{% if request.user and request.user.is_staff %}
<a href="/livraison/{{ delivery.id }}/commander?email={{ email }}" title="{{ email }}">{{ email }}</a>
{% else %}

View file

@ -20,8 +20,11 @@
{% endfor %}
</table>
<p>Total: {{ order.total(delivery.products) if order else 0 }} €</p>
{% if delivery.is_passed %}
<p>Commande soldée: <input type="checkbox" name="paid" {% if order.paid %}checked{% endif %}></p>
{% endif %}
<input type="hidden" name="email" value="{{ person.email }}">
<input type="submit" value="Valider la commande">
<input type="submit" value="Enregistrer la commande">
<a class="button" href="/livraison/{{ delivery.id }}/courriel?email={{ person.email }}">Envoyer par courriel</a>
</form>
</article>

View file

@ -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