Fix a few bugs in the reports

This commit is contained in:
Alexis M 2019-09-24 01:30:36 +02:00
parent 911f327106
commit c89f1d9466
10 changed files with 48 additions and 36 deletions

View file

@ -192,7 +192,11 @@ async def home(request, response):
if not request['user'].group_id: if not request['user'].group_id:
response.redirect = "/groupes" response.redirect = "/groupes"
return return
response.html("home.html", incoming=Delivery.incoming(), former=Delivery.former()) response.html(
"home.html",
incoming=Delivery.incoming(),
former=Delivery.former(),
archives=list(Delivery.all(is_archived=True)))
@app.route("/groupes", methods=["GET"]) @app.route("/groupes", methods=["GET"])
@ -516,13 +520,15 @@ async def import_multiple_commands(request, response, id):
@app.route("/livraison/{id}/bon-de-commande.xlsx", methods=["GET"]) @app.route("/livraison/{id}/bon-de-commande.xlsx", methods=["GET"])
async def xls_report(request, response, id): async def xls_report(request, response, id):
delivery = Delivery.load(id) delivery = Delivery.load(id)
response.xlsx(reports.summary(delivery)) date = delivery.to_date.strftime("%Y-%m-%d")
response.xlsx(reports.summary(delivery), filename=f"{config.SITE_NAME}-{date}-bon-de-commande.xlsx")
@app.route("/livraison/{id}/rapport-complet.xlsx", methods=["GET"]) @app.route("/livraison/{id}/rapport-complet.xlsx", methods=["GET"])
async def xls_full_report(request, response, id): async def xls_full_report(request, response, id):
delivery = Delivery.load(id) delivery = Delivery.load(id)
response.xlsx(reports.full(delivery)) date = delivery.to_date.strftime("%Y-%m-%d")
response.xlsx(reports.full(delivery), filename=f"{config.SITE_NAME}-{date}-rapport-complet.xlsx")
@app.route("/livraison/{id}/ajuster/{ref}", methods=["GET", "POST"]) @app.route("/livraison/{id}/ajuster/{ref}", methods=["GET", "POST"])

View file

@ -38,6 +38,7 @@ def send_order(request, env, person, delivery, order):
"order_summary", "order_summary",
person.email, person.email,
f"{config.SITE_NAME} : résumé de la commande {delivery.name}", f"{config.SITE_NAME} : résumé de la commande {delivery.name}",
display_prices=True,
order=order, order=order,
delivery=delivery, delivery=delivery,
request=request request=request

View file

@ -39,7 +39,6 @@ def summary_for_products(wb, title, delivery, total=None, products=None):
def summary(delivery): def summary(delivery):
wb = Workbook() wb = Workbook()
wb.remove(wb.active) wb.remove(wb.active)
if delivery.has_multiple_producers:
for producer in delivery.producers: for producer in delivery.producers:
summary_for_products( summary_for_products(
wb, wb,
@ -48,8 +47,6 @@ def summary(delivery):
total=delivery.total_for_producer(producer), total=delivery.total_for_producer(producer),
products=delivery.get_products_by(producer) products=delivery.get_products_by(producer)
) )
else:
summary_for_products(wb, f"{delivery.name} {delivery.from_date.date()}", delivery)
return save_virtual_workbook(wb) return save_virtual_workbook(wb)
@ -59,12 +56,10 @@ def full(delivery):
ws = wb.active ws = wb.active
ws.title = f"{delivery.name} {delivery.from_date.date()}" ws.title = f"{delivery.name} {delivery.from_date.date()}"
headers = ["ref", "produit", "prix"] + [e for e in delivery.orders] + ["total"] headers = ["ref", "produit", "prix"] + [e for e in delivery.orders] + ["total"]
if delivery.has_multiple_producers:
headers.insert(1, "producer") headers.insert(1, "producer")
ws.append(headers) ws.append(headers)
for product in delivery.products: for product in delivery.products:
row = [product.ref, str(product), product.price] row = [product.ref, str(product), product.price]
if delivery.has_multiple_producers:
row.insert(1, product.producer) row.insert(1, product.producer)
for order in delivery.orders.values(): for order in delivery.orders.values():
wanted = order.products.get(product.ref) wanted = order.products.get(product.ref)
@ -76,7 +71,6 @@ def full(delivery):
+ [round(o.total(delivery.products),2) for o in delivery.orders.values()] + [round(o.total(delivery.products),2) for o in delivery.orders.values()]
+ [round(delivery.total, 2)] + [round(delivery.total, 2)]
) )
if delivery.has_multiple_producers:
footer.insert(1, "") footer.insert(1, "")
ws.append(footer) ws.append(footer)

View file

@ -4,7 +4,7 @@ Voici le résumé de votre commande «{{ delivery.name }}» pour « {{ request['
Produit | Prix unitaire | Quantité Produit | Prix unitaire | Quantité
{% for product in delivery.products %}{% if order[product].quantity %}{{ product.name }} | {{ product.price }} € | {{ order[product].quantity }} {% for product in delivery.products %}{% if order[product].quantity %}{{ product.name }} | {{ product.price }} € | {{ order[product].quantity }} x {{ product.unit }}
{% endif %}{% endfor %} {% endif %}{% endfor %}
Total: {{ order.total(delivery.products) if order else 0 }} € Total: {{ order.total(delivery.products) if order else 0 }} €

View file

@ -4,12 +4,16 @@
{% with deliveries=incoming %} {% with deliveries=incoming %}
{% include "includes/delivery_list.html" %} {% include "includes/delivery_list.html" %}
{% endwith %} {% endwith %}
{% if former %}
<h2>Livraisons passées</h2> <h2>Livraisons passées</h2>
{% with deliveries=former %} {% with deliveries=former %}
{% include "includes/delivery_list.html" %} {% include "includes/delivery_list.html" %}
{% endwith %} {% endwith %}
{% endif %}
{% if archives %}
<a href="/archives">Voir les livraisons archivées</a> <a href="/archives">Voir les livraisons archivées</a>
<hr> <hr>
{% endif %}
<ul class="toolbox"> <ul class="toolbox">
<li> <li>
<a href="/groupes" class="button"><i class="icon-globe"></i>&nbsp;Gérer les groupes</a> <a href="/groupes" class="button"><i class="icon-globe"></i>&nbsp;Gérer les groupes</a>

View file

@ -2,8 +2,8 @@
{% if delivery.description %}<li><i class="icon-basket"></i> <strong>Produits</strong> {{ delivery.description }}</li>{% endif %} {% if delivery.description %}<li><i class="icon-basket"></i> <strong>Produits</strong> {{ delivery.description }}</li>{% endif %}
<li><i class="icon-streetsign"></i> <strong>Lieu</strong> {{ delivery.where }}</li> <li><i class="icon-streetsign"></i> <strong>Lieu</strong> {{ delivery.where }}</li>
<li><i class="icon-strategy"></i> <strong>Référent⋅e</strong> <a href="mailto:{{ delivery.contact }}">{{ delivery.contact }}</a></li> <li><i class="icon-strategy"></i> <strong>Référent⋅e</strong> <a href="mailto:{{ delivery.contact }}">{{ delivery.contact }}</a></li>
<li><i class="icon-clock"></i> <strong>Date de livraison</strong> <time datetime="{{ delivery.from_date }}">{{ delivery.from_date|date }} de {{ delivery.from_date|time }} à {{ delivery.to_date|time }}</time></li> <li><i class="icon-clock"></i> <strong>Date de livraison</strong> <time datetime="{{ delivery.from_date }}">{{ delivery.from_date|date|capitalize }} de {{ delivery.from_date|time }} à {{ delivery.to_date|time }}</time></li>
<li><i class="icon-hourglass"></i> {% if delivery.status == delivery.OPEN %}<strong>Date limite de commande</strong> <time datetime="{{ delivery.order_before.date() }}">{{ delivery.order_before|date }}</time>{% elif delivery.status == delivery.ADJUSTMENT %}<strong>Ajustement en cours</strong>{% elif delivery.status == delivery.CLOSED %}<strong>Fermée</strong>{% else %}<strong>Archivée</strong>{% endif %}</li> <li><i class="icon-hourglass"></i> {% if delivery.status == delivery.OPEN %}<strong>Date limite de commande</strong> <time datetime="{{ delivery.order_before.date() }}">{{ delivery.order_before|date|capitalize }}</time>{% elif delivery.status == delivery.ADJUSTMENT %}<strong>Ajustement en cours</strong>{% elif delivery.status == delivery.CLOSED %}<strong>Fermée</strong>{% else %}<strong>Archivée</strong>{% endif %}</li>
{% if delivery.instructions %}<li><i class="icon-lightbulb"></i> <strong>À savoir</strong> {{ delivery.instructions }}</li>{% endif %} {% if delivery.instructions %}<li><i class="icon-lightbulb"></i> <strong>À savoir</strong> {{ delivery.instructions }}</li>{% endif %}
{% if delivery.infos_url %}<li><i class="icon-global"></i><strong>Plus d'infos</strong> <a href="{{ delivery.infos_url }}" title="{{ delivery.infos_url }}">{{ delivery.infos_url|truncate(20)}}</a></li>{% endif %} {% if delivery.infos_url %}<li><i class="icon-global"></i><strong>Plus d'infos</strong> <a href="{{ delivery.infos_url }}" title="{{ delivery.infos_url }}">{{ delivery.infos_url|truncate(20)}}</a></li>{% endif %}
</ul> </ul>

View file

@ -1,5 +1,6 @@
{% for producer in delivery.producers %} {% for producer in delivery.producers %}
<h2>{{ producer }}</h2> <h2>{{ producer }}</h2>
<h4>Référent⋅e : {{ delivery.producers[producer].referent }} / {{ delivery.producers[producer].tel_referent }}</h4>
<table class="delivery"> <table class="delivery">
<thead> <thead>
<tr> <tr>

View file

@ -1,10 +1,10 @@
<table class="order"> <table class="order">
<tr><th class="product">Produit</th><th class="price">Prix unitaire</th><th class="amount">Quantité</th></tr> <tr><th class="product">Produit</th>{% if display_prices %}<th class="price">Prix unitaire</th>{% endif %}<th class="amount">Quantité</th></tr>
{% for product in delivery.products %} {% for product in delivery.products %}
{% if order[product].quantity %} {% if order[product].quantity %}
<tr> <tr>
<th class="product" style="text-align: left;">{{ product }}</th> <th class="product" style="text-align: left;">{{ product }}</th>
<td>{{ product.price | round(2) }} €</td><td>{{ order[product].quantity }}</td> {% if display_prices %}<td>{{ product.price | round(2) }} €</td>{% endif %}<td>{{ order[product].quantity }} x {{ product.unit }}</td>
</tr> </tr>
{% endif %} {% endif %}
{% endfor %} {% endfor %}

View file

@ -34,7 +34,7 @@
</th> </th>
<td>{{ product.price | round(2) }} €</td> <td>{{ product.price | round(2) }} €</td>
{% if delivery.has_packing %} {% if delivery.has_packing %}
<td {% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} class="missing" title="Les commandes individuelles ne correspondent pas aux conditionnements"{% endif %}>{{ product.packing or "—" }}{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} ({{ delivery.product_missing(product) }}){% endif %}</td> <td {% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} class="missing" title="Les commandes individuelles ne correspondent pas aux conditionnements"{% endif %}>{{ product.packing or "—" }}{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} (manque {{ delivery.product_missing(product) }}){% endif %}</td>
{% endif %} {% endif %}
<td class="with-input"><input {% if delivery.status != delivery.OPEN %}type="text" readonly{% else%}type="number"{% endif%} min=0 name="wanted:{{ product.ref }}" value="{{ order[product].wanted }}"> x {{ product.unit }}</td> <td class="with-input"><input {% if delivery.status != delivery.OPEN %}type="text" readonly{% else%}type="number"{% endif%} min=0 name="wanted:{{ product.ref }}" value="{{ order[product].wanted }}"> x {{ product.unit }}</td>
{% if delivery.status == delivery.ADJUSTMENT or order.has_adjustments %} {% if delivery.status == delivery.ADJUSTMENT or order.has_adjustments %}

View file

@ -1,10 +1,16 @@
<title>{% if title %}{{ title }} - {% endif %}{{ config.SITE_NAME }}</title> <!DOCTYPE html>
<meta charset="utf-8" /> <html>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <head>
<title>{% if title %}{{ title }} - {% endif %}{{ config.SITE_NAME }}</title>
<h2>{{ delivery.name }} {{ delivery.from_date.date() }} - liste d'émargement</h2> <meta charset="utf-8" />
{% for email, order in delivery.orders.items() %} <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/static/signing-sheet.css">
</head>
<body>
<h2>{{ delivery.name }} {{ delivery.from_date.date() }} - liste d'émargement</h2>
{% for email, order in delivery.orders.items() %}
<h3>{{ email }}</h3> <h3>{{ email }}</h3>
{% include "includes/order_summary.html" %} {% include "includes/order_summary.html" %}
<hr> <hr>
{% endfor %} {% endfor %}
</body>