Пример #1
0
def premade():
    f = open("stock.pickle", "rb")
    inventory = pickle.load(f)
    f.close()

    if request.method == 'POST':
        f = open("temp_order.pickle", "rb")
        order = pickle.load(f)

        premade_ingredients = {}
        for food in inventory.food_list:
            if food.name == 'Classic Burger' and request.form.get(
                    food.name) != '0':
                premade_ingredients[food.name] = int(
                    request.form.get(food.name))
            elif food.name == 'Classic Wrap' and request.form.get(
                    food.name) != '0':
                premade_ingredients[food.name] = int(
                    request.form.get(food.name))

        errors = check_order_error(None, 'temp', premade_ingredients,
                                   inventory)
        if len(premade_ingredients) == 0:
            errors["Please add item to cart"] = "Nothing added"

        temp = {}
        for food_dict in order[0]:
            temp = merge_dictonaries(temp, food_dict)
        temp = merge_dictonaries(temp, premade_ingredients)

        for key in temp:
            stock = inventory.get_ingredient(key)
            if temp[key] * stock.ingredient_size > inventory.get_stock_quantity(
                    key):
                errors[
                    "Order exceeds inventory: Only {0} of {1} left in inventory"
                    .format(inventory.get_stock_quantity(key), key, temp[key] *
                            stock.ingredient_size)] = "item out of stock"
        if errors:
            return render_template('premade.html',
                                   error=errors,
                                   ingredients=premade_ingredients,
                                   list=inventory.food_list)
        else:
            order[0].append(premade_ingredients)
            f = open("temp_order.pickle", "wb")
            pickle.dump(order, f)
            return redirect(url_for('sides'))
    return render_template('premade.html', list=inventory.food_list)
Пример #2
0
def drinks():
    f = open("stock.pickle", "rb")
    inventory = pickle.load(f)

    if request.method == 'POST':
        f = open("temp_order.pickle", "rb")
        order = pickle.load(f)
        f.close()

        drink_ingredients = {}
        for food in inventory.food_list:
            if food.classification == 'drink' and request.form.get(
                    food.name) != '0':
                drink_ingredients[food.name] = int(request.form.get(food.name))

        errors = check_order_error(None, 'temp', drink_ingredients, inventory)

        temp = {}
        temp = merge_dictonaries(temp, order[2])
        temp = merge_dictonaries(temp, drink_ingredients)

        for key in temp:
            stock = inventory.get_ingredient(key)
            if temp[key] * stock.ingredient_size > inventory.get_stock_quantity(
                    key):
                errors[
                    "Order exceeds inventory: Only {0} of {1} left in inventory, t"
                    .format(inventory.get_stock_quantity(key), key, temp[key] *
                            stock.ingredient_size)] = "item out of stock"

        if errors:
            return render_template('drinks.html',
                                   error=errors,
                                   ingredients=drink_ingredients,
                                   list=inventory.food_list)
        else:
            order[2] = merge_dictonaries(order[2], drink_ingredients)
            f = open("temp_order.pickle", "wb")
            pickle.dump(order, f)
            return redirect(url_for('myCart'))

    return render_template('drinks.html', list=inventory.food_list)