add base template for manual fill
Some checks failed
Deploy Amap / deploy (push) Failing after 15s

This commit is contained in:
Julien Aldon
2026-02-20 15:42:15 +01:00
parent 12be0e5650
commit b662a6a1f0
7 changed files with 118 additions and 9 deletions

View File

@@ -105,6 +105,46 @@ async def create_contract(
}
)
@router.get('/{form_id}/base')
async def get_base_contract_template(
form_id: int,
session: Session = Depends(get_session),
):
form = form_service.get_one(session, form_id)
recurrents = [pr for pr in form.productor.products if pr.type == models.ProductType.RECCURENT]
occasionals = [{
'shipment': sh,
'price': None,
'products': [{'product': pr, 'quantity': None} for pr in sh.products]
} for sh in form.shipments]
empty_contract = models.Contract(
firstname="",
form=form,
lastname="",
email="",
phone="",
payment_method="cheque"
)
cheques = [{"name": None, "value": None}, {"name": None, "value": None}, {"name": None, "value": None}]
try:
pdf_bytes = generate_html_contract(
empty_contract,
cheques,
occasionals,
recurrents,
)
pdf_file = io.BytesIO(pdf_bytes)
contract_id = f'{empty_contract.form.productor.type}_{empty_contract.form.season}'
except Exception:
raise HTTPException(status_code=400, detail=messages.pdferror)
return StreamingResponse(
pdf_file,
media_type='application/pdf',
headers={
'Content-Disposition': f'attachment; filename=contract_{contract_id}.pdf'
}
)
@router.get('', response_model=list[models.ContractPublic])
def get_contracts(
forms: list[str] = Query([]),

View File

@@ -12,8 +12,8 @@ def generate_html_contract(
cheques: list[dict],
occasionals: list[dict],
reccurents: list[dict],
recurrent_price: float,
total_price: float
recurrent_price: float | None = None,
total_price: float | None = None
):
template_dir = pathlib.Path("./src/contracts/templates").resolve()
template_loader = jinja2.FileSystemLoader(searchpath=template_dir)

View File

@@ -281,7 +281,7 @@
{% endfor %}
<tr>
<th scope="row" colspan="4">Total</th>
<td>{{recurrent_price}}€</td>
<td>{{recurrent_price if recurrent_price else ""}}€</td>
</tr>
</tbody>
</table>
@@ -317,14 +317,15 @@
product.product.quantity_unit != None else ""}}
</td>
<td>
{{product.quantity}}{{"g" if product.product.unit == "1" else
{{product.product.quantity if product.product.quantity != None
else ""}}{{"g" if product.product.unit == "1" else
"kg" if product.product.unit == "2" else "p" }}
</td>
</tr>
{% endfor%}
<tr>
<th scope="row" colspan="4">Total</th>
<td>{{occasional.price}}€</td>
<td>{{occasional.price if occasional.price else ""}}€</td>
</tr>
</tbody>
</table>
@@ -333,7 +334,7 @@
{% endif %}
<div class="total-box">
<div class="total-label">Prix Total :</div>
<div class="total-price">{{total_price}}€</div>
<div class="total-price">{{total_price if total_price else ""}}€</div>
</div>
<h4>Paiement par {{contract_payment_method}}</h4>
{% if contract_payment_method == "chèque" %}
@@ -342,14 +343,14 @@
<thead>
<tr>
{% for cheque in cheques %}
<th>Cheque n°{{cheque.name}}</th>
<th>Cheque n°{{cheque.name if cheque.name else ""}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
<tr>
{% for cheque in cheques %}
<td>{{cheque.value}}€</td>
<td>{{cheque.value if cheque.value else ""}}€</td>
{% endfor %}
</tr>
</tbody>