mirror of
https://github.com/almet/copanier.git
synced 2025-04-29 12:02:37 +02:00
Basic email with order summary
This commit is contained in:
parent
4cb3e10e93
commit
aa33599391
7 changed files with 51 additions and 14 deletions
|
@ -244,6 +244,18 @@ async def place_order(request, response, id):
|
||||||
delivery.orders = {}
|
delivery.orders = {}
|
||||||
delivery.orders[email] = order
|
delivery.orders[email] = order
|
||||||
delivery.persist()
|
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.message("Jour de fête! Votre commande a bien été prise en compte!")
|
||||||
response.redirect = request.path
|
response.redirect = request.path
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -14,12 +14,14 @@ Les gentils copains d'Épinamap
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def send(to, subject, body):
|
def send(to, subject, body, html=None):
|
||||||
msg = EmailMessage()
|
msg = EmailMessage()
|
||||||
msg.set_content(body)
|
msg.set_content(body)
|
||||||
msg["Subject"] = subject
|
msg["Subject"] = subject
|
||||||
msg["From"] = config.FROM_EMAIL
|
msg["From"] = config.FROM_EMAIL
|
||||||
msg["To"] = to
|
msg["To"] = to
|
||||||
|
if html:
|
||||||
|
msg.add_alternative(html, subtype='html')
|
||||||
if not config.SEND_EMAILS:
|
if not config.SEND_EMAILS:
|
||||||
return print("Sending email", str(msg))
|
return print("Sending email", str(msg))
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% 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" %}
|
{% include "includes/delivery_head.html" %}
|
||||||
<table class="delivery">
|
<table class="delivery">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
5
copanier/templates/emails/order_summary.html
Normal file
5
copanier/templates/emails/order_summary.html
Normal 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>
|
17
copanier/templates/emails/order_summary.txt
Normal file
17
copanier/templates/emails/order_summary.txt
Normal 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!
|
12
copanier/templates/includes/order_summary.html
Normal file
12
copanier/templates/includes/order_summary.html
Normal 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>
|
|
@ -5,17 +5,6 @@
|
||||||
<h2>{{ delivery.producer }} {{ delivery.from_date.date() }} - liste d'émargement</h2>
|
<h2>{{ delivery.producer }} {{ delivery.from_date.date() }} - liste d'émargement</h2>
|
||||||
{% for email, order in delivery.orders.items() %}
|
{% for email, order in delivery.orders.items() %}
|
||||||
<h3>{{ email }}</h3>
|
<h3>{{ email }}</h3>
|
||||||
<table class="order">
|
{% include "includes/order_summary.html" %}
|
||||||
<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>
|
|
||||||
<hr>
|
<hr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue