WIP contract recap
This commit is contained in:
@@ -60,19 +60,57 @@ def generate_html_contract(
|
||||
base_url=template_dir
|
||||
).write_pdf()
|
||||
|
||||
from odfdo import Document, Table, Row, Cell
|
||||
def flatten(xss):
|
||||
return [x for xs in xss for x in xs]
|
||||
|
||||
from odfdo import Document, Table, Row, Cell
|
||||
from odfdo.element import Element
|
||||
def generate_recap(
|
||||
contracts: list[models.Contract],
|
||||
form: models.Form,
|
||||
):
|
||||
print(form.productor.products)
|
||||
recurrents = [pr.name for pr in form.productor.products if pr.type == models.ProductType.RECCURENT]
|
||||
recurrents.sort()
|
||||
occasionnals = [pr.name for pr in form.productor.products if pr.type == models.ProductType.OCCASIONAL]
|
||||
occasionnals.sort()
|
||||
shipments = form.shipments
|
||||
occasionnals_header = [occ for shipment in shipments for occ in occasionnals]
|
||||
shipment_header = flatten([[shipment.name] + ["" * len(occasionnals)] for shipment in shipments])
|
||||
|
||||
product_unit_map = {
|
||||
"1": "g",
|
||||
"2": "kg",
|
||||
"3": "p"
|
||||
}
|
||||
|
||||
data = [
|
||||
["nom", "email"],
|
||||
["", ""] + ["" * len(recurrents)] + shipment_header,
|
||||
["nom", "email"] + recurrents + occasionnals_header + ["remarques", "name"],
|
||||
*[
|
||||
[
|
||||
f'{contract.firstname} {contract.lastname}',
|
||||
f'{contract.email}',
|
||||
*[f'{pr.quantity} {product_unit_map[pr.product.unit]}' for pr in sorted(contract.products, key=lambda x: x.product.name) if pr.product.type == models.ProductType.RECCURENT],
|
||||
*[f'{pr.quantity} {product_unit_map[pr.product.unit]}' for pr in sorted(contract.products, key=lambda x: x.product.name) if pr.product.type == models.ProductType.OCCASIONAL],
|
||||
"",
|
||||
f'{contract.firstname} {contract.lastname}',
|
||||
] for contract in contracts
|
||||
]
|
||||
]
|
||||
|
||||
doc = Document("spreadsheet")
|
||||
sheet = Table(name="Recap")
|
||||
sheet.set_values(data)
|
||||
|
||||
offset = 0
|
||||
index = 2 + len(recurrents)
|
||||
for i in range(len(shipments)):
|
||||
index = index + offset
|
||||
print(index, index+len(occasionnals) - 1)
|
||||
sheet.set_span((index, 0, index+len(occasionnals) - 1, 0), merge=True)
|
||||
offset += len(occasionnals)
|
||||
|
||||
doc.body.append(sheet)
|
||||
|
||||
buffer = io.BytesIO()
|
||||
|
||||
Reference in New Issue
Block a user