inventorymgr/borrowstates.py
def checkin() -> Response:
    """API endpoint for checkin of borrowed items."""
    checkin_request = api.CheckinRequest.parse_obj(request.json)
    now = _utcnow()
    returning_user = User.query.get(checkin_request.user_id)
    returned_items = [
        BorrowableItem.query.get(item_id) for item_id in checkin_request.item_ids
    ]
    borrowstates = []
    for item in returned_items:
        for borrow_state in open_borrowstates_for_item(item):
            borrow_state.returned_at = now
            borrowstates.append(borrow_state)
    db.session.add(
        LogEntry(
            action="checkin",
            timestamp=now,
            subject=returning_user,
            items=returned_items,
        )
    )
    for transfer_request in TransferRequest.query.filter(
        TransferRequest.borrowstate_id.in_(bs.id for bs in borrowstates)
    ).all():
        db.session.delete(transfer_request)
    db.session.commit()
    response = make_response(
        api.BorrowStateCollection(borrowstates=borrowstates).json()
    )
    response.headers["Content-Type"] = "application/json; encoding=utf-8"
    return response
API endpoint for checkin of borrowed items.
API endpoint for checkin of borrowed items.
API endpoint for checkin of borrowed items .
def checkin() -> Response:
    checkin_request = api.CheckinRequest.parse_obj(request.json)
    now = _utcnow()
    returning_user = User.query.get(checkin_request.user_id)
    returned_items = [
        BorrowableItem.query.get(item_id) for item_id in checkin_request.item_ids
    ]
    borrowstates = []
    for item in returned_items:
        for borrow_state in open_borrowstates_for_item(item):
            borrow_state.returned_at = now
            borrowstates.append(borrow_state)
    db.session.add(
        LogEntry(
            action="checkin",
            timestamp=now,
            subject=returning_user,
            items=returned_items,
        )
    )
    for transfer_request in TransferRequest.query.filter(
        TransferRequest.borrowstate_id.in_(bs.id for bs in borrowstates)
    ).all():
        db.session.delete(transfer_request)
    db.session.commit()
    response = make_response(
        api.BorrowStateCollection(borrowstates=borrowstates).json()
    )
    response.headers["Content-Type"] = "application/json; encoding=utf-8"
    return response
def checkin ( ) -> Response : checkin_request = api . CheckinRequest . parse_obj ( request . json ) now = _utcnow ( ) returning_user = User . query . get ( checkin_request . user_id ) returned_items = [ BorrowableItem . query . get ( item_id ) for item_id in checkin_request . item_ids ] borrowstates = [ ] for item in returned_items : for borrow_state in open_borrowstates_for_item ( item ) : borrow_state . returned_at = now borrowstates . append ( borrow_state ) db . session . add ( LogEntry ( action = "checkin" , timestamp = now , subject = returning_user , items = returned_items , ) ) for transfer_request in TransferRequest . query . filter ( TransferRequest . borrowstate_id . in_ ( bs . id for bs in borrowstates ) ) . all ( ) : db . session . delete ( transfer_request ) db . session . commit ( ) response = make_response ( api . BorrowStateCollection ( borrowstates = borrowstates ) . json ( ) ) response . headers [ "Content-Type" ] = "application/json; encoding=utf-8" return response
API endpoint for checkin of borrowed items.
API endpoint for checkin of borrowed items .
"""API endpoint for checkin of borrowed items."""