add contract page with dynamic form elements

This commit is contained in:
Julien Aldon
2026-02-13 17:46:24 +01:00
parent ef7403f213
commit 7e42fbe106
34 changed files with 540 additions and 263 deletions

View File

@@ -4,23 +4,25 @@ import src.models as models
def get_all(
session: Session,
names: list[str],
productors: list[str]
productors: list[str],
types: list[str],
) -> list[models.ProductPublic]:
statement = select(models.Product)
if len(names) > 0:
statement = statement.where(models.Product.name.in_(names))
if len(productors) > 0:
statement = statement.join(models.Productor).where(models.Productor.name.in_(productors))
return session.exec(statement).all()
if len(types) > 0:
statement = statement.where(models.Product.type.in_(types))
return session.exec(statement.order_by(models.Product.name)).all()
def get_one(session: Session, product_id: int) -> models.ProductPublic:
return session.get(models.Product, product_id)
def create_one(session: Session, product: models.ProductCreate) -> models.ProductPublic:
shipments = session.exec(select(models.Shipment).where(models.Shipment.id.in_(product.shipment_ids))).all()
product_create = product.model_dump(exclude_unset=True, exclude={'shipment_ids'})
new_product = models.Product(**product_create, shipments=shipments)
product_create = product.model_dump(exclude_unset=True)
new_product = models.Product(**product_create)
session.add(new_product)
session.commit()
session.refresh(new_product)
@@ -32,13 +34,7 @@ def update_one(session: Session, id: int, product: models.ProductUpdate) -> mode
new_product = result.first()
if not new_product:
return None
shipments_to_add = session.exec(select(models.Shipment).where(models.Shipment.id.in_(product.shipment_ids))).all()
new_product.shipments.clear()
for add in shipments_to_add:
new_product.shipments.append(add)
product_updates = product.model_dump(exclude_unset=True, exclude={"shipment_ids"})
product_updates = product.model_dump(exclude_unset=True)
for key, value in product_updates.items():
setattr(new_product, key, value)