예제 #1
0
def edit_stock(pk_id, stock_id, description, quantity, category, price):
    """Takes all stock arguments and save it in the selected stock record. (EDIT THE STOCK)
    pk_id: primary key id, or stock to be edited.
    The rest of the arguments are going to be the new data to the specified record.
    """
    stock = Stock.update(
        stock_id=stock_id, description=description,
        quantity=quantity, category=category, price=price
    ).where(
        Stock.id == pk_id
    )
    return stock.execute()
예제 #2
0
def add_existing_stock(pk_id, to_add):
    """Increase quantity for a specified record by pk_id.
    pk_id: primary key id
    """
    stock = Stock.get(
        Stock.id == pk_id
    )
    current_quantity = stock.quantity
    new_quantity = current_quantity + to_add
    query = Stock.update(
        quantity=new_quantity
    ).where(
        Stock.id == pk_id
    )
    return query.execute()