fix i18n add help page
This commit is contained in:
@@ -19,10 +19,10 @@ def compute_recurrent_prices(products_quantities: list[dict], nb_shipment: int):
|
||||
result += compute_product_price(product, quantity, nb_shipment)
|
||||
return result
|
||||
|
||||
def compute_planned_prices(planneds: list[dict]):
|
||||
def compute_occasional_prices(occasionals: list[dict]):
|
||||
result = 0
|
||||
for planned in planneds:
|
||||
result += planned['price']
|
||||
for occasional in occasionals:
|
||||
result += occasional['price']
|
||||
return result
|
||||
|
||||
def compute_product_price(product: models.Product, quantity: int, nb_shipment: int = 1):
|
||||
@@ -37,7 +37,7 @@ def find_dict_in_list(lst, key, value):
|
||||
return i
|
||||
return -1
|
||||
|
||||
def create_planned_dict(contract_products: list[models.ContractProduct]):
|
||||
def create_occasional_dict(contract_products: list[models.ContractProduct]):
|
||||
result = []
|
||||
for contract_product in contract_products:
|
||||
existing_id = find_dict_in_list(
|
||||
@@ -74,18 +74,18 @@ async def create_contract(
|
||||
session: Session = Depends(get_session)
|
||||
):
|
||||
new_contract = service.create_one(session, contract)
|
||||
planned_contract_products = list(filter(lambda contract_product: contract_product.product.type == models.ProductType.PLANNED, new_contract.products))
|
||||
planneds = create_planned_dict(planned_contract_products)
|
||||
occasional_contract_products = list(filter(lambda contract_product: contract_product.product.type == models.ProductType.OCCASIONAL, new_contract.products))
|
||||
occasionals = create_occasional_dict(occasional_contract_products)
|
||||
recurrents = list(map(lambda x: {"product": x.product, "quantity": x.quantity}, filter(lambda contract_product: contract_product.product.type == models.ProductType.RECCURENT, new_contract.products)))
|
||||
recurrent_price = compute_recurrent_prices(recurrents, len(new_contract.form.shipments))
|
||||
total_price = '{:10.2f}'.format(recurrent_price + compute_planned_prices(planneds))
|
||||
total_price = '{:10.2f}'.format(recurrent_price + compute_occasional_prices(occasionals))
|
||||
cheques = list(map(lambda x: {"name": x.name, "value": x.value}, new_contract.cheques))
|
||||
# TODO: send contract to referer
|
||||
try:
|
||||
pdf_bytes = generate_html_contract(
|
||||
new_contract,
|
||||
cheques,
|
||||
planneds,
|
||||
occasionals,
|
||||
recurrents,
|
||||
recurrent_price,
|
||||
total_price
|
||||
|
||||
@@ -7,7 +7,7 @@ from weasyprint import HTML
|
||||
def generate_html_contract(
|
||||
contract: models.Contract,
|
||||
cheques: list[dict],
|
||||
planneds: list[dict],
|
||||
occasionals: list[dict],
|
||||
reccurents: list[dict],
|
||||
recurrent_price: float,
|
||||
total_price: float
|
||||
@@ -32,7 +32,7 @@ def generate_html_contract(
|
||||
member_phone=html.escape(contract.phone),
|
||||
contract_start_date=contract.form.start,
|
||||
contract_end_date=contract.form.end,
|
||||
planneds=planneds,
|
||||
occasionals=occasionals,
|
||||
recurrents=reccurents,
|
||||
recurrent_price=recurrent_price,
|
||||
total_price=total_price,
|
||||
|
||||
@@ -290,11 +290,11 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %} {% if planneds|length > 0 %}
|
||||
{% endif %} {% if occasionals|length > 0 %}
|
||||
<div class="container">
|
||||
<h4>Produits planifiés (par livraison)</h4>
|
||||
{% for plan in planneds %}
|
||||
<h5>{{plan.shipment.name}} {{plan.shipment.date}}</h5>
|
||||
<h4>Produits occasionnels (par livraison)</h4>
|
||||
{% for occasional in occasionals %}
|
||||
<h5>{{occasional.shipment.name}} {{occasional.shipment.date}}</h5>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -306,7 +306,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for product in plan.products %}
|
||||
{% for product in occasional.products %}
|
||||
<tr>
|
||||
<td>{{product.product.name}}</td>
|
||||
<td>
|
||||
@@ -328,7 +328,7 @@
|
||||
{% endfor%}
|
||||
<tr>
|
||||
<th scope="row" colspan="4">Total</th>
|
||||
<td>{{plan.price}}€</td>
|
||||
<td>{{occasional.price}}€</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -74,7 +74,7 @@ class Unit(StrEnum):
|
||||
PIECE = "3"
|
||||
|
||||
class ProductType(StrEnum):
|
||||
PLANNED = "1"
|
||||
OCCASIONAL = "1"
|
||||
RECCURENT = "2"
|
||||
|
||||
class ShipmentProductLink(SQLModel, table=True):
|
||||
|
||||
Reference in New Issue
Block a user