Basic email with order summary

This commit is contained in:
Yohan Boniface 2019-03-24 17:49:54 +01:00
parent 4cb3e10e93
commit aa33599391
7 changed files with 51 additions and 14 deletions

View file

@ -244,6 +244,18 @@ async def place_order(request, response, id):
delivery.orders = {}
delivery.orders[email] = order
delivery.persist()
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,
)
response.message("Jour de fête! Votre commande a bien été prise en compte!")
response.redirect = request.path
else:

View file

@ -14,12 +14,14 @@ Les gentils copains d'Épinamap
"""
def send(to, subject, body):
def send(to, subject, body, html=None):
msg = EmailMessage()
msg.set_content(body)
msg["Subject"] = subject
msg["From"] = config.FROM_EMAIL
msg["To"] = to
if html:
msg.add_alternative(html, subtype='html')
if not config.SEND_EMAILS:
return print("Sending email", str(msg))
try:

View file

@ -1,7 +1,7 @@
{% extends "base.html" %}
{% block body %}
<h3>{{ delivery.producer }} <a class="button" href="/livraison/{{ delivery.id }}/commander">Ma commande</a></h3>
<h3>{{ delivery.producer }} {% if delivery.is_open %}<a class="button" href="/livraison/{{ delivery.id }}/commander">Ma commande</a>{% endif %}</h3>
{% include "includes/delivery_head.html" %}
<table class="delivery">
<tbody>

View file

@ -0,0 +1,5 @@
<p>Bonjour,</p>
<p>Voici le résumé de la commande «{{ delivery.producer }}»</p>
{% include "includes/order_summary.html" %}
<p>Livraison: {{ delivery.where }}, le {{ delivery.from_date|date }} de {{ delivery.from_date|time }} à {{ delivery.to_date|time }}</p>
<p>Bonne journée!</p>

View file

@ -0,0 +1,17 @@
Salut salut,
Voici le résumé de la commande «{{ delivery.producer }}»
Produit | Prix unitaire | Quantité
{% for product in delivery.products %}
{% if order.get_quantity(product) %}
{{ product.name }} | {{ product.price }} € | {{ order.get_quantity(product) }}
{% endif %}
{% endfor %}
Total: {{ order.total(delivery.products) if order else 0 }} €
Livraison: {{ delivery.where }}, le {{ delivery.from_date|date }} de {{ delivery.from_date|time }} à {{ delivery.to_date|time }}
Bonne journée!

View file

@ -0,0 +1,12 @@
<table class="order">
<tr><th class="product">Produit</th><th class="price">Prix unitaire</th><th class="amount">Quantité</th></tr>
{% for product in delivery.products %}
{% if order.get_quantity(product) %}
<tr>
<th class="product">{{ product.name }}</th>
<td>{{ product.price }} €</td><td>{{ order.get_quantity(product) }}</td>
</tr>
{% endif %}
{% endfor %}
</table>
<p>Total: {{ order.total(delivery.products) if order else 0 }} €</p>

View file

@ -5,17 +5,6 @@
<h2>{{ delivery.producer }} {{ delivery.from_date.date() }} - liste d'émargement</h2>
{% for email, order in delivery.orders.items() %}
<h3>{{ email }}</h3>
<table class="order">
<tr><th class="product">Produit</th><th class="price">Prix unitaire</th><th class="amount">Quantité</th></tr>
{% for product in delivery.products %}
{% if order.get_quantity(product) %}
<tr>
<th class="product">{{ product.name }}</th>
<td>{{ product.price }} €</td><td>{{ order.get_quantity(product) }}</td>
</tr>
{% endif %}
{% endfor %}
</table>
<p>Total: {{ order.total(delivery.products) if order else 0 }} €</p>
{% include "includes/order_summary.html" %}
<hr>
{% endfor %}