def reduce_kitchen_stock(): if request.method == "POST": quantity = request.form['quantity'] stock_id = request.form['stock'] stock = KitchenStock.read_one(KitchenStock, stock_id) try: if int(quantity) < 1: flash("Invalid Input!", 'danger') else: stock.add_quantity(0 - int(quantity)) flash( "Reduced " + quantity + " units of " + stock.name + " from kitchen stock", 'info') session.close() return redirect(url_for('kitchen_stock.get_kitchen_stock')) except Exception as e: flash("Invalid Input!", 'danger') return redirect( url_for('kitchen_stock.reduce_stock') + '?kitchen-stock=' + stock_id) else: stock_id = request.args['kitchen-stock'] stock = KitchenStock.read_one(KitchenStock, stock_id) return render_template("manager/reduce-kitchen-stock.html", mod=module, stock=stock)
def delete_kitchen_stock(): if request.method == "POST": kitchen_stock_id = request.form["kitchen-stock"] stock = KitchenStock.read_one(KitchenStock, kitchen_stock_id) KitchenStock.delete(stock) flash("Item has been deleted", "info") session.close() return redirect(url_for('kitchen_stock.get_kitchen_stock'))
def add_kitchen_stock(): if request.method == "POST": name = request.form["kitchen-item"] usage_unit = request.form["usage-unit"] KitchenStock(name, usage_unit) session.close() flash(name + " has been registered as Kitchen Stock", "success") return redirect(url_for('kitchen_stock.get_kitchen_stock'))
def get_purchases(): kitchen_purchases = KitchenStockPurchase.read(KitchenStockPurchase) kitchen_items = KitchenStock.read(KitchenStock) drink_items = Brand.read(Brand) brand_purchases = Purchase.read(Purchase) total_purchases = KitchenStockPurchase.get_total_price(KitchenStockPurchase) + Purchase.get_total_price(Purchase) return render_template("manager/purchases.html", mod=module, total_purchases=total_purchases, kitchen_purchases=kitchen_purchases, kitchen_items=kitchen_items, drink_items=drink_items, brand_purchases=brand_purchases)
def get_kitchen_stock(): all_kitchen_stock = KitchenStock.read(KitchenStock) if current_user.manager: return render_template("manager/kitchen-stock.html", mod=module, all_kitchen_stock=all_kitchen_stock) elif current_user.chef: return render_template("chef/kitchen-stock.html", mod=module, all_kitchen_stock=all_kitchen_stock)
def add_stock(): if request.method == "POST": added_stock_quantity = request.form['added-stock-quantity'] stock_id = request.form['stock'] stock = KitchenStock.read_one(KitchenStock, stock_id) try: if int(added_stock_quantity) < 1: flash("Invalid Stock Added!", 'danger') return redirect( url_for('kitchen_stock.add_stock') + '?kitchen-stock=' + stock_id) else: # record purchase purchase_unit = request.form['purchase-unit'] unit_price = request.form['unit-price'] purchase_quantity = request.form['purchase-quantity'] KitchenStockPurchase(purchase_unit, unit_price, purchase_quantity, added_stock_quantity, stock.usage_unit, current_user, stock) flash("Registered Purchase of " + stock.name + " successfully", 'success') session.close() return redirect(url_for('kitchen_stock.get_kitchen_stock')) except ValueError: flash("Invalid Stock Added!", 'danger') return redirect( url_for('kitchen_stock.add_stock') + '?kitchen-stock=' + stock_id) elif request.method == "GET": stock_id = request.args['kitchen-stock'] stock = KitchenStock.read_one(KitchenStock, stock_id) if current_user.manager: return render_template("manager/add-kitchen-stock.html", mod=module, stock=stock) elif current_user.chef: return render_template("chef/add-kitchen-stock.html", mod=module, stock=stock)
def edit_kitchen_stock(): if request.method == "POST": kitchen_stock_id = request.form["kitchen-stock"] name = request.form["kitchen-item"] usage_unit = request.form["usage-unit"] stock = KitchenStock.read_one(KitchenStock, kitchen_stock_id) stock.update(name, usage_unit) session.close() flash("Item has been edited", "success") return redirect(url_for('kitchen_stock.get_kitchen_stock')) elif request.method == "GET": kitchen_stock_id = request.args["kitchen-stock"] stock = KitchenStock.read_one(KitchenStock, kitchen_stock_id) if current_user.manager: return render_template("manager/edit-kitchen-stock.html", mod=module, stock=stock) elif current_user.chef: return render_template("chef/edit-kitchen-stock.html", mod=module, stock=stock)
def register_usage(): if request.method == "POST": kitchen_stock_id = request.form.get("kitchen-stock") quantity_used = float(request.form.get("quantity")) stock = KitchenStock.read_one(KitchenStock, kitchen_stock_id) if stock.quantity_available >= quantity_used or quantity_used < 0: chef = current_user.chef stock.kitchen_stock_usages.append( KitchenStockUsage(stock, quantity_used, chef)) stock.reduce_quantity(quantity_used) flash("Stock usage registered", "info") return redirect(url_for('kitchen_stock.get_kitchen_stock')) else: flash("Invalid input", "danger") return redirect( url_for('kitchen_stock.register_usage') + "?kitchen-stock=" + kitchen_stock_id) elif request.method == "GET": kitchen_stock_id = request.args.get("kitchen-stock") kitchen_stock = KitchenStock.read_one(KitchenStock, kitchen_stock_id) return render_template("chef/register-kitchen-stock-usage.html", mod=module, stock=kitchen_stock)
def get_kitchen_stock_purchases(): kitchen_stock_purchases = KitchenStockPurchase.read(KitchenStockPurchase) chefs = Chef.read(Chef) kitchen_items = KitchenStock.read(KitchenStock) if current_user.manager: return render_template("manager/kitchen-stock-purchase.html", mod=module, purchases=kitchen_stock_purchases, chefs=chefs, kitchen_items=kitchen_items) elif current_user.chef: return render_template("chef/kitchen-stock-purchase.html", mod=module, purchases=kitchen_stock_purchases, chefs=chefs, kitchen_items=kitchen_items)
def filter(): if request.method == "GET": item = request.args.get("item") chef = request.args.get("chef") _from = request.args.get("from") to = request.args.get("to") if not item: item = "" if not chef: chef = "" if _from: _from = utils.convert_date_from_html(_from) else: _from = datetime.datetime(2000, 1, 1) if to: to = utils.convert_date_from_html(to) else: to = datetime.datetime(3000, 1, 1) kitchen_stock_purchases = KitchenStockPurchase.filter( KitchenStockPurchase, item, chef, _from, to) chefs = Chef.read(Chef) kitchen_items = KitchenStock.read(KitchenStock) if current_user.manager: return render_template("manager/kitchen-stock-purchase.html", mod=module, purchases=kitchen_stock_purchases, chefs=chefs, kitchen_items=kitchen_items, chef_id=chef, item_id=item, today=_from, tomorrow=to) elif current_user.chef: return render_template("chef/kitchen-stock-purchase.html", mod=module, purchases=kitchen_stock_purchases, chefs=chefs, kitchen_items=kitchen_items, chef_id=chef, item_id=item, today=_from, tomorrow=to)
def filter(): if request.method == "GET": kitchen_items = KitchenStock.read(KitchenStock) drink_items = Brand.read(Brand) kitchen_purchases = [] brand_purchases = [] item = request.args.get("item") _from = request.args.get("from") to = request.args.get("to") place = request.args.get("place") filter_kitchen, filter_bar = True, True if place == "kitchen": filter_bar = False elif place == "bar": filter_kitchen = False if _from: _from = utils.convert_date_from_html(_from) else: _from = datetime.datetime(2000, 1, 1) if to: to = utils.convert_date_from_html(to) else: to = datetime.datetime(3000, 1, 1) if item: item_type, id = item.split("-") if item_type == "kitchen": kitchen_purchases = KitchenStockPurchase.filter2(KitchenStockPurchase, id, _from, to, filter_kitchen) elif item_type == "drink": brand_purchases = Purchase.filter(Purchase, id, _from, to, filter_bar) else: kitchen_purchases = KitchenStockPurchase.filter2(KitchenStockPurchase, "", _from, to, filter_kitchen) brand_purchases = Purchase.filter(Purchase, "", _from, to, filter_bar) print(">>>>>>>>>>>>>>>>>", kitchen_purchases, brand_purchases) total_purchases = KitchenStockPurchase.get_total_price(KitchenStockPurchase, purchases=kitchen_purchases) + Purchase.get_total_price(Purchase, purchases=brand_purchases) return render_template("manager/purchases.html", mod=module, kitchen_purchases=kitchen_purchases, total_purchases=total_purchases, kitchen_items=kitchen_items, drink_items=drink_items, item_id=item, brand_purchases=brand_purchases, tomorrow=to, today=_from)