Allow to resend order by email

This commit is contained in:
Yohan Boniface 2019-03-24 22:05:26 +01:00
parent 24d278f04d
commit bc802cae42
4 changed files with 43 additions and 19 deletions

View file

@ -255,27 +255,35 @@ async def place_order(request, response, id):
delivery.persist()
if user and user.email == email:
# Only send email if order has been placed by the user itself.
html = env.get_template("emails/order_summary.html").render(
order=order, delivery=delivery
)
txt = env.get_template("emails/order_summary.txt").render(
order=order, delivery=delivery
)
emails.send(
email,
f"Copanier: résumé de la commande {delivery.producer}",
body=txt,
html=html,
emails.send_order(
env, person=Person(email=email), delivery=delivery, order=order
)
response.message(f"La commande pour «{email}» a bien été prise en compte!")
response.redirect = f"/livraison/{delivery.id}"
else:
order = delivery.orders.get(email) or Order()
response.html(
"place_order.html", {"delivery": delivery, "person": email, "order": order}
"place_order.html",
{"delivery": delivery, "person": Person(email=email), "order": order},
)
@app.route("/livraison/{id}/courriel", methods=["GET"])
@auth_required
async def send_order(request, response, id):
delivery = Delivery.load(id)
email = request.query.get("email")
order = delivery.orders.get(email)
if not order:
response.message(f"Aucune commande pour «{email}»", status="warning")
else:
emails.send_order(
env, person=Person(email=email), delivery=delivery, order=order
)
response.message(f"Commande envoyée à «{email}»")
response.redirect = f"/livraison/{delivery.id}"
@app.route("/livraison/{id}/émargement", methods=["GET"])
@auth_required
async def signing_sheet(request, response, id):

View file

@ -21,7 +21,7 @@ def send(to, subject, body, html=None):
msg["From"] = config.FROM_EMAIL
msg["To"] = to
if html:
msg.add_alternative(html, subtype='html')
msg.add_alternative(html, subtype="html")
if not config.SEND_EMAILS:
return print("Sending email", str(msg))
try:
@ -32,3 +32,18 @@ def send(to, subject, body, html=None):
raise RuntimeError
finally:
server.quit()
def send_order(env, person, delivery, order):
html = env.get_template("emails/order_summary.html").render(
order=order, delivery=delivery
)
txt = env.get_template("emails/order_summary.txt").render(
order=order, delivery=delivery
)
send(
person.email,
f"Copanier: résumé de la commande {delivery.producer}",
body=txt,
html=html,
)

View file

@ -114,7 +114,7 @@ h4,
h5,
legend {
/*margin: 0;*/
color: var(--primary-color);
color: #444;
line-height: 1;
font-weight: 300;
}
@ -376,7 +376,7 @@ hr {
.notification {
width: 100%;
text-align: center;
color: #f1f1f1;
color: white;
line-height: 3rem;
height: 3rem;
vertical-align: middle;
@ -387,8 +387,8 @@ hr {
.notification.error {
background-color: #e10055;
}
.notification.error {
background-color: #8c5a2d;
.notification.warning {
background-color: #f9b42d;
}
.notification i {
font-size: 2rem;

View file

@ -2,7 +2,7 @@
{% block body %}
<article class="order">
<h3>{{ delivery.producer }} — Commande de «{{ person }}»</h3>
<h3>{{ delivery.producer }} — Commande de «{{ person.email }}»</h3>
{% include "includes/delivery_head.html" %}
<form method="post">
<table class="order">
@ -20,8 +20,9 @@
{% endfor %}
</table>
<p>Total: {{ order.total(delivery.products) if order else 0 }} €</p>
<input type="hidden" name="email" value="{{ person }}">
<input type="hidden" name="email" value="{{ person.email }}">
<input type="submit" value="Valider la commande">
<a class="button" href="/livraison/{{ delivery.id }}/courriel?email={{ person.email }}">Envoyer par courriel</a>
</form>
</article>
{% endblock body %}