mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Add delivery full report
This commit is contained in:
parent
e7e82f2c99
commit
dc520ace5e
3 changed files with 58 additions and 22 deletions
|
@ -6,12 +6,10 @@ import ujson as json
|
||||||
import hupper
|
import hupper
|
||||||
import minicli
|
import minicli
|
||||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||||
from openpyxl import Workbook
|
|
||||||
from openpyxl.writer.excel import save_virtual_workbook
|
|
||||||
from roll import Roll, Response
|
from roll import Roll, Response
|
||||||
from roll.extensions import cors, options, traceback, simple_server, static
|
from roll.extensions import cors, options, traceback, simple_server, static
|
||||||
|
|
||||||
from . import config
|
from . import config, reports
|
||||||
from .models import Delivery, Order, Person, Product, ProductOrder
|
from .models import Delivery, Order, Person, Product, ProductOrder
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,23 +179,16 @@ async def import_commande(request, response, id):
|
||||||
@app.route("/livraison/{id}/rapport.xlsx", methods=["GET"])
|
@app.route("/livraison/{id}/rapport.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)
|
||||||
wb = Workbook()
|
response.body = reports.summary(delivery)
|
||||||
ws = wb.active
|
mimetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||||
ws.title = f"Commande Epinamap - {delivery.producer} - {delivery.when.date()}"
|
response.headers["Content-Disposition"] = f'attachment; filename="export.xlsx"'
|
||||||
ws.append(["ref", "produit", "prix", "unités", "total"])
|
response.headers["Content-Type"] = f"{mimetype}; charset=utf-8"
|
||||||
for product in delivery.products:
|
|
||||||
wanted = delivery.product_wanted(product)
|
|
||||||
ws.append(
|
@app.route("/livraison/{id}/rapport-complet.xlsx", methods=["GET"])
|
||||||
[
|
async def xls_full_report(request, response, id):
|
||||||
product.ref,
|
delivery = Delivery.load(id)
|
||||||
product.name,
|
response.body = reports.full(delivery)
|
||||||
product.price,
|
|
||||||
wanted,
|
|
||||||
round(product.price * wanted, 2),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
ws.append(["", "", "", "Total", delivery.total])
|
|
||||||
response.body = save_virtual_workbook(wb)
|
|
||||||
mimetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
mimetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||||
response.headers["Content-Disposition"] = f'attachment; filename="export.xlsx"'
|
response.headers["Content-Disposition"] = f'attachment; filename="export.xlsx"'
|
||||||
response.headers["Content-Type"] = f"{mimetype}; charset=utf-8"
|
response.headers["Content-Type"] = f"{mimetype}; charset=utf-8"
|
||||||
|
|
42
kaba/reports.py
Normal file
42
kaba/reports.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
from openpyxl import Workbook
|
||||||
|
from openpyxl.writer.excel import save_virtual_workbook
|
||||||
|
|
||||||
|
|
||||||
|
def summary(delivery):
|
||||||
|
wb = Workbook()
|
||||||
|
ws = wb.active
|
||||||
|
ws.title = f"Commande Epinamap - {delivery.producer} - {delivery.when.date()}"
|
||||||
|
ws.append(["ref", "produit", "prix", "unités", "total"])
|
||||||
|
for product in delivery.products:
|
||||||
|
wanted = delivery.product_wanted(product)
|
||||||
|
ws.append(
|
||||||
|
[
|
||||||
|
product.ref,
|
||||||
|
product.name,
|
||||||
|
product.price,
|
||||||
|
wanted,
|
||||||
|
round(product.price * wanted, 2),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
ws.append(["", "", "", "Total", delivery.total])
|
||||||
|
return save_virtual_workbook(wb)
|
||||||
|
|
||||||
|
|
||||||
|
def full(delivery):
|
||||||
|
wb = Workbook()
|
||||||
|
ws = wb.active
|
||||||
|
ws.title = f"Epinamap - {delivery.producer} - {delivery.when.date()}"
|
||||||
|
headers = ["ref", "produit", "prix"] + [e for e in delivery.orders] + ["total"]
|
||||||
|
ws.append(headers)
|
||||||
|
for product in delivery.products:
|
||||||
|
row = [product.ref, product.name, product.price]
|
||||||
|
for order in delivery.orders.values():
|
||||||
|
wanted = order.products.get(product.ref)
|
||||||
|
row.append(wanted.wanted if wanted else 0)
|
||||||
|
row.append(delivery.product_wanted(product))
|
||||||
|
ws.append(row)
|
||||||
|
footer = ["Total", "", ""] + [
|
||||||
|
o.total(delivery.products) for o in delivery.orders.values()
|
||||||
|
] + [delivery.total]
|
||||||
|
ws.append(footer)
|
||||||
|
return save_virtual_workbook(wb)
|
|
@ -27,11 +27,11 @@
|
||||||
<th>{{ delivery.product_wanted(product) }}</th>
|
<th>{{ delivery.product_wanted(product) }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<tr><th class="total"><i class="icon-pricetags"></i> Total</th><td class="total">{{ delivery.total }} €</td>
|
<tr><th class="total"><i class="icon-pricetags"></i> Total</th><td>—</td>
|
||||||
{% for email, order in delivery.orders.items() %}
|
{% for email, order in delivery.orders.items() %}
|
||||||
<td>{{ order.total(delivery.products) }} €</td>
|
<td>{{ order.total(delivery.products) }} €</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<th>—</th>
|
<td class="total">{{ delivery.total }} €</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -43,6 +43,9 @@
|
||||||
<li>
|
<li>
|
||||||
<a href="/livraison/{{ delivery.id }}/rapport.xlsx"><i class="icon-download"></i> Rapport résumé</a>
|
<a href="/livraison/{{ delivery.id }}/rapport.xlsx"><i class="icon-download"></i> Rapport résumé</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="/livraison/{{ delivery.id }}/rapport-complet.xlsx"><i class="icon-download"></i> Rapport complet</a>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="import-command" class="toggle-label"><i class="icon-paperclip"></i> Importer une commande</label>
|
<label for="import-command" class="toggle-label"><i class="icon-paperclip"></i> Importer une commande</label>
|
||||||
<input type="checkbox" id="import-command" class="toggle">
|
<input type="checkbox" id="import-command" class="toggle">
|
||||||
|
|
Loading…
Reference in a new issue