fix sort order for contract recap
All checks were successful
Deploy Amap / deploy (push) Successful in 15s
All checks were successful
Deploy Amap / deploy (push) Successful in 15s
This commit is contained in:
@@ -268,8 +268,11 @@ def get_contract_recap(
|
|||||||
form = form_service.get_one(session, form_id=form_id)
|
form = form_service.get_one(session, form_id=form_id)
|
||||||
contracts = service.get_all(session, user, forms=[form.name])
|
contracts = service.get_all(session, user, forms=[form.name])
|
||||||
filename = f'{form.name}_recapitulatif_contrats.ods'
|
filename = f'{form.name}_recapitulatif_contrats.ods'
|
||||||
|
recap = generate_recap(contracts, form)
|
||||||
|
if recap is None:
|
||||||
|
raise HTTPException(status_code=404)
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
io.BytesIO(generate_recap(contracts, form)),
|
io.BytesIO(recap),
|
||||||
media_type='application/vnd.oasis.opendocument.spreadsheet',
|
media_type='application/vnd.oasis.opendocument.spreadsheet',
|
||||||
headers={
|
headers={
|
||||||
'Content-Disposition': (
|
'Content-Disposition': (
|
||||||
|
|||||||
@@ -412,20 +412,34 @@ def generate_recap(
|
|||||||
'2': 'Kg',
|
'2': 'Kg',
|
||||||
'3': 'Piece'
|
'3': 'Piece'
|
||||||
}
|
}
|
||||||
|
if len(contracts) <= 0:
|
||||||
|
# TODO: raise correct exception
|
||||||
|
return None
|
||||||
|
first_contract = contracts[0]
|
||||||
|
reccurents_sorted = sorted(
|
||||||
|
[
|
||||||
|
product for product in first_contract.products
|
||||||
|
if product.product.type == models.ProductType.RECCURENT
|
||||||
|
],
|
||||||
|
key=lambda x: x.product.name
|
||||||
|
)
|
||||||
recurrents = [
|
recurrents = [
|
||||||
f'{pr.name}{f' - {pr.quantity}{pr.quantity_unit}'
|
f'{pr.name}{f' - {pr.quantity}{pr.quantity_unit}'
|
||||||
if pr.quantity else ''} ({product_unit_map[pr.unit]})'
|
if pr.quantity else ''} ({product_unit_map[pr.unit]})'
|
||||||
for pr in form.productor.products
|
for pr in reccurents_sorted
|
||||||
if pr.type == models.ProductType.RECCURENT
|
|
||||||
]
|
]
|
||||||
recurrents.sort()
|
occasionnals_sorted = sorted(
|
||||||
|
[
|
||||||
|
product for product in first_contract.products
|
||||||
|
if product.product.type == models.ProductType.OCCASIONAL
|
||||||
|
],
|
||||||
|
key=lambda x: (x.shipment.name, x.product.name)
|
||||||
|
)
|
||||||
occasionnals = [
|
occasionnals = [
|
||||||
f'{pr.name}{f' - {pr.quantity}{pr.quantity_unit}'
|
f'{pr.name}{f' - {pr.quantity}{pr.quantity_unit}'
|
||||||
if pr.quantity else ''} ({product_unit_map[pr.unit]})'
|
if pr.quantity else ''} ({product_unit_map[pr.unit]})'
|
||||||
for pr in form.productor.products
|
for pr in occasionnals_sorted
|
||||||
if pr.type == models.ProductType.OCCASIONAL
|
|
||||||
]
|
]
|
||||||
occasionnals.sort()
|
|
||||||
shipments = form.shipments
|
shipments = form.shipments
|
||||||
occasionnals_header = [
|
occasionnals_header = [
|
||||||
occ for shipment in shipments for occ in occasionnals
|
occ for shipment in shipments for occ in occasionnals
|
||||||
|
|||||||
Reference in New Issue
Block a user