add(remaining): add a way to generate contracts only with remaining shipments
All checks were successful
Deploy Amap / deploy (push) Successful in 41s
All checks were successful
Deploy Amap / deploy (push) Successful in 41s
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
"""Router for contract resource"""
|
||||
import datetime
|
||||
import io
|
||||
import zipfile
|
||||
|
||||
import src.contracts.service as service
|
||||
import src.forms.service as form_service
|
||||
import src.shipments.service as shipment_service
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from fastapi.responses import StreamingResponse
|
||||
from sqlmodel import Session
|
||||
@@ -44,10 +46,15 @@ async def create_contract(
|
||||
)
|
||||
)
|
||||
)
|
||||
remaining_shipments = shipment_service.get_remaining_shipments(
|
||||
session,
|
||||
new_contract.form.id,
|
||||
datetime.datetime.today()
|
||||
)
|
||||
prices = service.generate_products_prices(
|
||||
occasionals,
|
||||
recurrents,
|
||||
new_contract.form.shipments
|
||||
remaining_shipments
|
||||
)
|
||||
recurrent_price = prices['recurrent']
|
||||
total_price = prices['total']
|
||||
@@ -111,7 +118,7 @@ async def get_base_contract_template(
|
||||
cheque_payment_method = list(filter(
|
||||
lambda x: x.name == "cheque", form.productor.payment_methods))
|
||||
cheque_number = cheque_payment_method[0].max if len(
|
||||
cheque_payment_method) > 0 else 3
|
||||
cheque_payment_method) > 0 and cheque_payment_method[0].max is not None else 3
|
||||
print(cheque_number, cheque_payment_method)
|
||||
empty_contract = models.ContractPublic(
|
||||
firstname='',
|
||||
|
||||
@@ -49,6 +49,19 @@ def get_one(session: Session, shipment_id: int) -> models.ShipmentPublic:
|
||||
return session.get(models.Shipment, shipment_id)
|
||||
|
||||
|
||||
def get_remaining_shipments(session: Session, form_id: int, date: datetime.date) -> list[models.ShipmentPublic]:
|
||||
statement = (
|
||||
select(models.Shipment)
|
||||
.join(
|
||||
models.Form,
|
||||
models.Shipment.form_id == models.Form.id
|
||||
)
|
||||
.where(models.Form.id == form_id)
|
||||
.where(models.Shipment.date >= date)
|
||||
)
|
||||
return session.exec(statement.order_by(models.Shipment.name)).all()
|
||||
|
||||
|
||||
def create_one(
|
||||
session: Session,
|
||||
shipment: models.ShipmentCreate) -> models.ShipmentPublic:
|
||||
|
||||
Reference in New Issue
Block a user