Ejemplo n.º 1
0
def select(id):
    product = None
    sql = "SELECT * FROM products WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        supplier = supplier_repository.select(result["supplier_id"])
        product = Product(result["name"], result["category"], result["in_stock"], result["cost_price"],result["mark_up"], result["sale_price"], result["description"], result["minimum_stock_level"], supplier, result["id"])
    return product
Ejemplo n.º 2
0
def select_all():
    products = []

    sql = "SELECT * FROM products"
    results = run_sql(sql)

    for row in results:
        supplier = supplier_repository.select(row["supplier_id"])
        product = Product(row["name"], row["category"], row["in_stock"], row["cost_price"],row["mark_up"], row["sale_price"], row["description"], row["minimum_stock_level"], supplier, row["id"])
        products.append(product)
    return products
def update_product(id):
    name = request.form["name"]
    category = request.form["category"]
    in_stock = request.form["in_stock"]
    cost_price = request.form["cost_price"]
    mark_up = request.form["mark_up"]
    description = request.form["description"]
    minimum_stock_level = request.form["minimum_stock_level"]
    supplier = supplier_repository.select(request.form['supplier_id'])
    sale_price = Product.set_markup(cost_price, mark_up)
    product = Product(name, category, in_stock, cost_price, mark_up,
                      sale_price, description, minimum_stock_level, supplier,
                      id)
    product_repository.update(product)
    return redirect("/products")
def edit_supplier(id):
    supplier = supplier_repository.select(id)
    return render_template("suppliers/edit.html",
                           supplier=supplier,
                           title="Inn-Ventory - Edit Supplier")
def show_supplier(id):
    supplier = supplier_repository.select(id)
    return render_template("/suppliers/show.html",
                           supplier=supplier,
                           title="Inn-Ventory - Supplier")