Add quantity in reserve_gift_item endpoint
This commit is contained in:
@@ -87,9 +87,9 @@ class CRUDGiftItem(CRUDBase[GiftItem, GiftItemCreate, GiftItemUpdate]):
|
||||
return gift
|
||||
|
||||
def reserve_gift(
|
||||
self, db: Session, *, gift_id: UUID, guest_id: UUID, notes: Optional[str] = None
|
||||
self, db: Session, *, gift_id: UUID, guest_id: UUID, quantity: int = 1, notes: Optional[str] = None
|
||||
) -> GiftItem:
|
||||
"""Reserve a gift for a guest"""
|
||||
"""Reserve a gift for a guest with specified quantity"""
|
||||
|
||||
gift = self.get(db, gift_id)
|
||||
if gift and gift.status == GiftStatus.AVAILABLE:
|
||||
@@ -104,10 +104,18 @@ class CRUDGiftItem(CRUDBase[GiftItem, GiftItemCreate, GiftItemUpdate]):
|
||||
)
|
||||
db.execute(stmt)
|
||||
|
||||
# Update gift status
|
||||
# Update gift status and quantity
|
||||
gift.status = GiftStatus.RESERVED
|
||||
gift.last_status_change = datetime.now(timezone.utc)
|
||||
|
||||
# Record the reservation quantity by updating quantity_received
|
||||
# This effectively reduces the remaining_quantity
|
||||
gift.quantity_received += quantity
|
||||
|
||||
# If fully received, ensure status reflects that
|
||||
if gift.quantity_received >= gift.quantity_requested:
|
||||
gift.status = GiftStatus.RECEIVED
|
||||
|
||||
db.commit()
|
||||
db.refresh(gift)
|
||||
return gift
|
||||
@@ -159,7 +167,7 @@ class CRUDEventGiftCategory:
|
||||
).first()
|
||||
|
||||
def update(
|
||||
self, db: Session, *, db_obj: EventGiftCategory, obj_in: Union[EventGiftCategoryUpdate, Dict[str, Any]]
|
||||
self, db: Session, *, db_obj: EventGiftCategory, obj_in: Union[EventGiftCategoryUpdate, Dict[str, Any]]
|
||||
) -> EventGiftCategory:
|
||||
"""Update an event-category association"""
|
||||
if isinstance(obj_in, dict):
|
||||
|
||||
Reference in New Issue
Block a user