add contract pdf generation
This commit is contained in:
@@ -13,8 +13,16 @@ def get_one(session: Session, productor_id: int) -> models.ProductorPublic:
|
||||
return session.get(models.Productor, productor_id)
|
||||
|
||||
def create_one(session: Session, productor: models.ProductorCreate) -> models.ProductorPublic:
|
||||
productor_create = productor.model_dump(exclude_unset=True)
|
||||
productor_create = productor.model_dump(exclude_unset=True, exclude="payment_methods")
|
||||
new_productor = models.Productor(**productor_create)
|
||||
|
||||
new_productor.payment_methods = [
|
||||
models.PaymentMethod(
|
||||
name=pm.name,
|
||||
details=pm.details
|
||||
) for pm in productor.payment_methods
|
||||
]
|
||||
|
||||
session.add(new_productor)
|
||||
session.commit()
|
||||
session.refresh(new_productor)
|
||||
@@ -26,7 +34,20 @@ def update_one(session: Session, id: int, productor: models.ProductorUpdate) ->
|
||||
new_productor = result.first()
|
||||
if not new_productor:
|
||||
return None
|
||||
|
||||
productor_updates = productor.model_dump(exclude_unset=True)
|
||||
if "payment_methods" in productor_updates:
|
||||
new_productor.payment_methods.clear()
|
||||
for pm in productor_updates["payment_methods"]:
|
||||
new_productor.payment_methods.append(
|
||||
models.PaymentMethod(
|
||||
name=pm["name"],
|
||||
details=pm["details"],
|
||||
productor_id=id
|
||||
)
|
||||
)
|
||||
del productor_updates["payment_methods"]
|
||||
|
||||
for key, value in productor_updates.items():
|
||||
setattr(new_productor, key, value)
|
||||
session.add(new_productor)
|
||||
|
||||
Reference in New Issue
Block a user