Beispiel #1
0
def orders_change_status_cn(id: int, status: int, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        order_data = db.query(Orders).filter(Orders.id == id).update(
            {Orders.status_id: status})
        db.commit()
        db.flush()
        status_str = 'En Preparacion' if status == 2 else 'Finalizado' if status == 3 else 'Cancelado'
        served = datetime.now() if status == 3 else None
        order_detail = db.query(OrdersDetail).filter(
            and_(OrdersDetail.orders_id == id,
                 OrdersDetail.served == None)).update({
                     OrdersDetail.status:
                     status_str,
                     OrdersDetail.served:
                     served
                 })
        db.commit()
        db.flush()
        arsene.status = True if order_data else False
        arsene.result = 'success' if order_data else 'order does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #2
0
def create_fp_cn(food_plate: FoodPlateCreate, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        fp_data = FoodPlate(name=food_plate.name,
                            price=food_plate.price,
                            creation=datetime.now())
        db.add(fp_data)
        db.commit()
        db.refresh(fp_data)
        arsene.status = True if fp_data.id else False
        arsene.result = 'success'
        for sp in food_plate.supplies:
            if db.query(Supplies).filter(Supplies.id == sp.id).first():
                sp_date = SuppliesPlate(
                    quantity=sp.quantity,
                    food_plate_id=fp_data.id,
                    supplies_id=sp.id,
                )
                db.add(sp_date)
                db.commit()
                db.refresh(sp_date)
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #3
0
def delete_reservation_cn(id: int, db: Session):
    arsene = Response_SM(status = False, result= '...')
    try:
        reservation_delete = db.query(Reservation).filter(Reservation.id == id).delete()
        db.commit()
        db.flush()
        arsene.status = True if reservation_delete else False
        arsene.result = 'success' if reservation_delete else 'reservation does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #4
0
def delete_fp_cn(id: int, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        food_delete = db.query(FoodPlate).filter(FoodPlate.id == id).delete()
        db.commit()
        db.flush()
        arsene.status = True if food_delete else False
        arsene.result = 'success' if food_delete else 'food plate does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #5
0
def delete_user_cn(id: int, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        user = db.query(User).filter(User.id == id).delete()
        db.commit()
        db.flush()
        arsene.status = True if user else False
        arsene.result = 'success' if user else 'user does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #6
0
def update_rol_cn(rol: Rol_Update, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        rol_data = db.query(Rol).filter(Rol.id == rol.id).update(
            {Rol.name: rol.name})
        db.commit()
        db.flush()
        arsene.status = True if rol_data else False
        arsene.result = 'success' if rol_data else 'rol does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #7
0
def update_orders_status(id: int, status: int, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        order_data = db.query(Orders).filter(Orders.id == id).update(
            {Orders.status_id: status})
        db.commit()
        db.flush()
        arsene.status = True if order_data else False
        arsene.result = 'success' if order_data else 'order does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #8
0
def delete_orders_detail_completed_cn(id: int, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        detail_completed_delete = db.query(OrdersDetailCompleted).filter(
            OrdersDetailCompleted.id == id).delete()
        db.commit()
        db.flush()
        arsene.status = True if detail_completed_delete else False
        arsene.result = 'success' if detail_completed_delete else 'order detail completed does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #9
0
def create_rol_cn(rol: RolBase, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        rol_data = Rol(name=rol.name)
        db.add(rol_data)
        db.commit()
        db.refresh(rol_data)
        arsene.status = True if rol_data.id else False
        arsene.result = 'success'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #10
0
def create_orders_completed(completed: OrdersCompletedBase, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        completed_data = OrdersCompleted(status=completed.status,
                                         creation=completed.creation)
        db.add(completed_data)
        db.commit()
        db.refresh(completed_data)
        arsene.status = True if completed_data.id else False
        arsene.result = 'success' if completed_data else 'order completed cant create'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #11
0
def update_reservation_cn(reservation: UpdateReservation, db: Session):
    arsene = Response_SM(status=False,result= '...')
    try:
        reservation_data = db.query(Reservation).filter(Reservation.id == reservation.id).update({
            Reservation.status_id: reservation.status_id
        })
        db.commit()
        db.flush()
        arsene.status = True if reservation_data else False
        arsene.result = 'success' if reservation_data else 'reservation does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #12
0
def update_reservation_status_cn(status: ResStatus, db: Session):
    arsene = Response_SM(status=False,result= '...')
    try:
        status_data = db.query(ReservationStatus).filter(ReservationStatus.id == status.id).update({
            ReservationStatus.name: status.name,
        })
        db.commit()
        db.flush()
        arsene.status = True if status_data else False
        arsene.result = 'success' if status_data else 'reservation status does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #13
0
def create_tables(tables: TablesBase, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        table_data = Tables(number=tables.number,
                            status=tables.status,
                            user_id=tables.user_id)
        db.add(table_data)
        db.commit()
        db.refresh(table_data)
        arsene.status = True if table_data.id else False
        arsene.result = 'create table successfully' if table_data else 'table cant create'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #14
0
def create_reservation_status(status: ResStatus, db:Session):
    arsene =  Response_SM(status=False,result= '...')
    try:
        status_data = ReservationStatus(
            name = status.name
        )
        db.add(status_data)
        db.commit()
        db.refresh(status_data)
        arsene.status = True if status_data.id else False
        arsene.result = 'success'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #15
0
def create_orders(order: OrdersBase, db: Session):
    arsene = Response_SM(status=False, result='...')
    logger.info(f'status {order.status_id}')
    try:
        orders_data = Orders(table_id=order.table_id,
                             status_id=order.status_id,
                             creation=order.creation)
        db.add(orders_data)
        db.commit()
        db.refresh(orders_data)
        arsene.status = True if orders_data.id else False
        arsene.result = 'success' if orders_data else 'order cant create'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #16
0
def create_user(db: Session, obj_in: UserCreate):
    arsene = Response_SM(status=False, result='...')
    try:
        db_obj = User(email=obj_in.email,
                      name=obj_in.name,
                      password=get_password_hash(obj_in.password),
                      rol_id=obj_in.rol_id)
        db.add(db_obj)
        db.commit()
        db.refresh(db_obj)
        arsene.status = True if db_obj.id else False
        arsene.result = 'success'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #17
0
def create_orders_detail(detail: OrdersDetailBase, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        detail_data = OrdersDetail(orders_id=detail.orders_id,
                                   food_plate_id=detail.food_plate_id,
                                   status=detail.status,
                                   quantity=detail.quantity,
                                   served=detail.served)
        db.add(detail_data)
        db.commit()
        db.refresh(detail_data)
        arsene.status = True if detail_data.id else False
        arsene.result = 'success' if detail_data else 'order detail cant create'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #18
0
def update_sps_cn(sps:Supplies,db:Session):
    arsene =  Response_SM(status=False,result= '...')
    try:
        sps_data = db.query(Supplies).filter(Supplies.id == sps.id).update({
            Supplies.name: sps.name,
            Supplies.description: sps.description,
            Supplies.quantity: sps.quantity,
            Supplies.modicum: sps.modicum,
            Supplies.on_hold: sps.on_hold
        })
        db.commit()
        db.flush()
        arsene.status = True if sps_data else False
        arsene.result = 'success' if sps_data else 'supplies does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #19
0
def update_orders_completed_cn(completed: OrdersCompletedUpdate, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        completed_data = db.query(OrdersCompleted).filter(
            OrdersCompleted.id == completed.id).update({
                OrdersCompleted.status:
                completed.status,
                OrdersCompleted.creation:
                completed.creation
            })
        db.commit()
        db.flush()
        arsene.status = True if completed_data else False
        arsene.result = 'success' if completed_data else 'order completed does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #20
0
def update_orders_cn(order: OrdersUpdate, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        order_data = db.query(Orders).filter(Orders.id == order.id).update({
            Orders.table_id:
            order.table_id,
            Orders.status_id:
            order.status_id,
            Orders.creation:
            order.creation
        })
        db.commit()
        db.flush()
        arsene.status = True if order_data else False
        arsene.result = 'success' if order_data else 'order does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #21
0
def update_table_cn(table: TablesUpdate, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        tables_data = db.query(Tables).filter(Tables.id == table.id).update({
            Tables.number:
            table.number,
            Tables.status:
            table.status,
            Tables.user_id:
            table.user_id
        })
        db.commit()
        db.flush()
        arsene.status = True if tables_data else False
        arsene.result = 'success' if tables_data else 'table does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #22
0
def update_user_cn(upd_user: UserList, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        user = db.query(User).filter(User.id == upd_user.id).update({
            User.rol_id:
            upd_user.rol_id,
            User.password:
            get_password_hash(upd_user.password),
            User.email:
            upd_user.email
        })
        db.commit()
        db.flush()
        arsene.status = True if user else False
        arsene.result = 'success' if user else 'user does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #23
0
def create_sps_cn(sps:SuppliesBase,db:Session):
    arsene =  Response_SM(status=False,result= '...')
    try:
        sps_data = Supplies(
            name=sps.name,
            description = sps.description,
            quantity = sps.quantity,
            modicum = sps.modicum,
            on_hold = sps.on_hold
        )
        db.add(sps_data)
        db.commit()
        db.refresh(sps_data)
        arsene.status = True if sps_data.id else False
        arsene.result = 'success'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #24
0
def create_sp_fp_cn(supplies_fp: List[SuppliesPlateCreate], db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        for sp in supplies_fp:
            if db.query(Supplies).filter(
                    Supplies.id == sp.supplies_id).first():
                sp_date = SuppliesPlate(
                    quantity=sp.quantity,
                    food_plate_id=sp.food_plate_id,
                    supplies_id=sp.supplies_id,
                )
                db.add(sp_date)
                db.commit()
                db.refresh(sp_date)
        arsene.status = True
        arsene.result = 'success'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #25
0
def update_orders_detail_completed_cn(
        detail_completed: OrdersDetailCompletedUpdate, db: Session):
    arsene = Response_SM(status=False, result='...')
    try:
        detail_completed_data = db.query(OrdersDetailCompleted).filter(
            OrdersDetailCompleted.id == detail_completed.id).update({
                OrdersDetailCompleted.orders_id:
                detail_completed.orders_id,
                OrdersDetailCompleted.food_plate_id:
                detail_completed.food_plate_id,
                OrdersDetailCompleted.quantity:
                detail_completed.quantity,
                OrdersDetailCompleted.served:
                detail_completed.served
            })
        db.commit()
        db.flush()
        arsene.status = True if detail_completed_data else False
        arsene.result = 'success' if detail_completed_data else 'order detail completed does not exist'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene
Beispiel #26
0
def update_user_cn(upd_user: UserUpdate, db: Session):
    response = Response_SM(status=False, result='...')
    try:
        user = db.query(User).filter(User.id == upd_user.id).update({
            User.rol_id:
            upd_user.rol_id,
            User.username:
            upd_user.username,
            User.email:
            upd_user.email
        })
        db.commit()
        db.flush()
        response.status = True if user else False
        response.result = 'success' if user else 'user does not exist'
        if upd_user.password and user:
            reset_password(user_id=upd_user.id,
                           password=upd_user.password,
                           db=db)
    except Exception as e:
        response.result = f'error {e}'
        logger.error(f'error {e}')
    return response
Beispiel #27
0
def create_reservation(rsvt: ReservationBase, db:Session):
    arsene = Response_SM(status = False, result = '...')
    try:
    
        prms = permission_reservation(rsvt.date_applied,db)
        if prms >= 1:
            reservation_data = Reservation(
                user_id = rsvt.user_id,
                date_applied = rsvt.date_applied,
                status_id = 1
            )
            db.add(reservation_data)
            db.commit()
            db.refresh(reservation_data)
            arsene.status = True if reservation_data.id else False
            arsene.result = 'success' if reservation_data else 'reservation cant create'
        else:
            arsene.result = 'Day without reservations available'
    except Exception as e:
        arsene.result = f'error {e}'
        logger.error(f'error {e}')
    return arsene