mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Allow to mark orders as paid
And display in orange unpaid colmuns
This commit is contained in:
parent
bc802cae42
commit
21578d0c81
7 changed files with 33 additions and 5 deletions
|
@ -237,7 +237,7 @@ async def place_order(request, response, id):
|
||||||
return
|
return
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = request.form
|
form = request.form
|
||||||
order = Order()
|
order = Order(paid=form.bool("paid", False))
|
||||||
for product in delivery.products:
|
for product in delivery.products:
|
||||||
quantity = form.int(product.ref, 0)
|
quantity = form.int(product.ref, 0)
|
||||||
if quantity:
|
if quantity:
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
getenv = os.environ.get
|
|
||||||
|
|
||||||
DATA_ROOT = Path(__file__).parent.parent / "db"
|
DATA_ROOT = Path(__file__).parent.parent / "db"
|
||||||
SECRET = "sikretfordevonly"
|
SECRET = "sikretfordevonly"
|
||||||
JWT_ALGORITHM = "HS256"
|
JWT_ALGORITHM = "HS256"
|
||||||
|
|
|
@ -107,6 +107,7 @@ class ProductOrder(Base):
|
||||||
@dataclass
|
@dataclass
|
||||||
class Order(Base):
|
class Order(Base):
|
||||||
products: Dict[str, ProductOrder] = field(default_factory=lambda *a, **k: {})
|
products: Dict[str, ProductOrder] = field(default_factory=lambda *a, **k: {})
|
||||||
|
paid: bool = False
|
||||||
|
|
||||||
def get_quantity(self, product):
|
def get_quantity(self, product):
|
||||||
choice = self.products.get(product.ref)
|
choice = self.products.get(product.ref)
|
||||||
|
@ -147,6 +148,10 @@ class Delivery(Base):
|
||||||
def is_foreseen(self):
|
def is_foreseen(self):
|
||||||
return datetime.now().date() <= self.from_date.date()
|
return datetime.now().date() <= self.from_date.date()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_passed(self):
|
||||||
|
return not self.is_foreseen
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def init_fs(cls):
|
def init_fs(cls):
|
||||||
cls.get_root().mkdir(parents=True, exist_ok=True)
|
cls.get_root().mkdir(parents=True, exist_ok=True)
|
||||||
|
|
|
@ -263,6 +263,12 @@ select {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=checkbox] {
|
||||||
|
height: 1rem;
|
||||||
|
padding: 0;
|
||||||
|
vertical-align: bottom;
|
||||||
|
}
|
||||||
|
|
||||||
input:focus,
|
input:focus,
|
||||||
select:focus {
|
select:focus {
|
||||||
box-shadow: 0 0 .1rem var(--primary-color);
|
box-shadow: 0 0 .1rem var(--primary-color);
|
||||||
|
@ -393,6 +399,9 @@ hr {
|
||||||
.notification i {
|
.notification i {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
.not-paid {
|
||||||
|
background-color: #db7734;
|
||||||
|
}
|
||||||
.toggle {
|
.toggle {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<th class="price">Prix</th>
|
<th class="price">Prix</th>
|
||||||
<th class="amount">Total</th>
|
<th class="amount">Total</th>
|
||||||
{% for email, order in delivery.orders.items() %}
|
{% 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 %}
|
{% if request.user and request.user.is_staff %}
|
||||||
<a href="/livraison/{{ delivery.id }}/commander?email={{ email }}" title="{{ email }}">{{ email }}</a>
|
<a href="/livraison/{{ delivery.id }}/commander?email={{ email }}" title="{{ email }}">{{ email }}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -20,8 +20,11 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
<p>Total: {{ order.total(delivery.products) if order else 0 }} €</p>
|
<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="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>
|
<a class="button" href="/livraison/{{ delivery.id }}/courriel?email={{ person.email }}">Envoyer par courriel</a>
|
||||||
</form>
|
</form>
|
||||||
</article>
|
</article>
|
||||||
|
|
|
@ -74,3 +74,16 @@ async def test_place_empty_order_should_delete_previous(client, delivery):
|
||||||
assert resp.status == 302
|
assert resp.status == 302
|
||||||
delivery = Delivery.load(delivery.id)
|
delivery = Delivery.load(delivery.id)
|
||||||
assert not delivery.orders
|
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
|
||||||
|
|
Loading…
Reference in a new issue