mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Create multiple tabs for full delivery reports
This commit is contained in:
parent
ec291e4c85
commit
1794913997
2 changed files with 50 additions and 22 deletions
|
@ -188,9 +188,13 @@ class Delivery(Base):
|
|||
def total(self):
|
||||
return round(sum(o.total(self.products) for o in self.orders.values()), 2)
|
||||
|
||||
@property
|
||||
def producers(self):
|
||||
return list(set([p.producer for p in self.products]))
|
||||
|
||||
@property
|
||||
def has_multiple_producers(self):
|
||||
return len(set([p.producer for p in self.products])) > 1
|
||||
return len(self.producers) > 1
|
||||
|
||||
@property
|
||||
def is_open(self):
|
||||
|
|
|
@ -5,35 +5,52 @@ from openpyxl.writer.excel import save_virtual_workbook
|
|||
|
||||
from .models import Product
|
||||
|
||||
def summary_for_products(wb, title, delivery, total=None, products=None):
|
||||
if products == None:
|
||||
products = delivery.products
|
||||
if total == None:
|
||||
total = delivery.total
|
||||
|
||||
def summary(delivery):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = f"{delivery.name} {delivery.from_date.date()}"
|
||||
headers = [
|
||||
ws = wb.create_sheet(title)
|
||||
ws.append([
|
||||
"ref",
|
||||
"produit",
|
||||
"prix unitaire",
|
||||
"quantité commandée",
|
||||
"unité",
|
||||
"total",
|
||||
]
|
||||
ws.append(headers)
|
||||
for product in delivery.products:
|
||||
])
|
||||
for product in products:
|
||||
wanted = delivery.product_wanted(product)
|
||||
if not wanted:
|
||||
continue
|
||||
ws.append(
|
||||
[
|
||||
product.ref,
|
||||
str(product),
|
||||
product.price,
|
||||
wanted,
|
||||
product.unit,
|
||||
round(product.price * wanted, 2),
|
||||
]
|
||||
)
|
||||
ws.append(["", "", "", "", "Total", delivery.total])
|
||||
ws.append([
|
||||
product.ref,
|
||||
str(product),
|
||||
product.price,
|
||||
wanted,
|
||||
product.unit,
|
||||
round(product.price * wanted, 2),
|
||||
])
|
||||
ws.append(["", "", "", "", "Total", total])
|
||||
|
||||
|
||||
|
||||
def summary(delivery):
|
||||
wb = Workbook()
|
||||
wb.remove(wb.active)
|
||||
if delivery.has_multiple_producers:
|
||||
for producer in delivery.producers:
|
||||
summary_for_products(
|
||||
wb,
|
||||
producer,
|
||||
delivery,
|
||||
total=delivery.total_for_producer(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)
|
||||
|
||||
|
||||
|
@ -41,10 +58,14 @@ def full(delivery):
|
|||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = f"{delivery.name} {delivery.from_date.date()}"
|
||||
headers = ["ref", "produit", "prix", "producer"] + [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")
|
||||
ws.append(headers)
|
||||
for product in delivery.products:
|
||||
row = [product.ref, str(product), product.price, product.producer]
|
||||
row = [product.ref, str(product), product.price]
|
||||
if delivery.has_multiple_producers:
|
||||
row.insert(1, product.producer)
|
||||
for order in delivery.orders.values():
|
||||
wanted = order.products.get(product.ref)
|
||||
row.append(wanted.quantity if wanted else 0)
|
||||
|
@ -55,6 +76,9 @@ def full(delivery):
|
|||
+ [round(o.total(delivery.products),2) for o in delivery.orders.values()]
|
||||
+ [round(delivery.total, 2)]
|
||||
)
|
||||
if delivery.has_multiple_producers:
|
||||
footer.insert(1, "")
|
||||
|
||||
ws.append(footer)
|
||||
return save_virtual_workbook(wb)
|
||||
|
||||
|
|
Loading…
Reference in a new issue