def custcare_shops(shop_state): if shop_state == "all": restuarants = Resturant.read_all_rests() return render_template('restaurants/customer_care_restaurants.html', restuarants=restuarants, shop_state=shop_state)
def dashboard(): product_sales_today = Sales.read_sales_sum( Sales.amount, Sales.sales_day == DateUtil().current_date.day, Sales.sales_month == DateUtil().current_date.month, Sales.sales_year == DateUtil().current_date.year, ) commission_sales_today = Sales.read_sales_sum( Sales.commision_amount, Sales.sales_day == DateUtil().current_date.day, Sales.sales_month == DateUtil().current_date.month, Sales.sales_year == DateUtil().current_date.year, ) customer_count = Customer.read_customer_count() vendors_count = Resturant.read_restaurants_count() products_count = Products.read_products_count() orders_count = Order.read_orders_count() total_revenue = Sales.read_sales_sum(Sales.amount) context = dict(product_sales_today=product_sales_today, commission_sales_today=commission_sales_today, total_revenue=total_revenue, shipping_sales_today=0, standard_shipping_sales_td=0, pickup_station_sales_td=0, vendors_count=vendors_count, customer_count=customer_count, products_count=products_count, orders_count=orders_count) return render_template('dashboard.html', **context)
def add_product(): form = AddProductForm() brands = Brand.read_all_bandss_filter_by("brand_id", "name") if request.method == "GET": form.restaurant.choices = Resturant.read_all_restaurants_filter_by( "id", "business_name") form.brand.choices = brands form.sub_cat.choices = SubCategory.read_all_subcategories_filter_by( "sub_category_id", "name") form.price.data = 0 form.buying_price.data = 0 form.selling_price.data = 0 form.served_with.data = "none" form.commission_fee.data = 0.0 form.headsup.data = "clickEat" if form.validate_on_submit(): try: product_picture = save_picture(form.product_picture.data, None, "static/product_images", 500, 500) price = form.price.data rest_id = form.restaurant.data brand_name = [ brand for brand in brands if brand[0] == form.brand.data ][0][1] if (Products()(name=form.name.data, product_picture=product_picture, description=form.description.data, price=form.price.data, resturant_id=form.restaurant.data, brand=brand_name, sub_category_id=form.sub_cat.data, buying_price=form.buying_price.data, selling_price=form.selling_price.data, served_with=form.served_with.data, commission_fee=form.commission_fee.data, headsup=form.headsup.data)): flash("Product added successfully", "success") return redirect(url_for("customer_care.add_product")) except Exception as e: print("Error while trying to save product: ", e) session.rollback() flash("Error while trying to save product", "danger") return render_template('restaurants/restaurant/product/add_product.html', form=form)
def shop_detail(shop_id, state): restuarant = Resturant.read_restaurant(id=shop_id) if state == "all_products": products = restuarant.read_all_rest_products elif state == "approved": products = restuarant.read_all_approved_products elif state == "not_approved": products = restuarant.read_all_non_approved_products elif state == "suspended": products = restuarant.read_all_suspended_products return render_template('restaurants/restaurant/restuarant_details.html', restuarant=restuarant, shop_id=shop_id, products=products, state=state)
def rest_product_detail(product_id): product = Products.read_product(product_id) top_selling_status = TopSellingProducts.read_top_most_selling_product( product_id) comments = Comments.product_comments(product_id) product_rating = Rate.read_product_rate(product_id) restuarant = Resturant.read_restaurant(id=product.resturant_id) form = ProductsVerificationForm() promotional_price_form = SetPromotionForm() suspend_form = SuspendProductForm() suspend_form.product_id.data = product_id if request.method == "GET": form = ProductsVerificationForm(obj=product) form.sub_category.choices = SubCategory.read_all_subcategories_filter_by( "sub_category_id", "name", category_id=product.sub_category.category_id) # form.category.choices = Category.read_all_categories_by_attr("category_id","name") if form.validate_on_submit(): if form.product_picture.data: try: product_pic = save_picture(form.product_picture.data, product.product_picture, "static/product_images", 500, 500) # product.sub_category_id = form.sub_category.data product.name = form.name.data product.product_picture = product_pic product.price = form.price.data product.description = form.description.data product.product = form.price.data product.buying_price = form.buying_price.data product.selling_price = form.selling_price.data product.served_with = form.served_with.data product.commission_fee = form.commission_fee.data product.headsup = form.headsup.data product.free_delivery = form.free_delivery.data session.commit() flash("Product updated successfully", "success") return redirect( url_for("customer_care.rest_product_detail", product_id=product_id)) except Exception as e: print("Customer care updating product error:", e) session.rollback() flash("Internal server error failed to update product.", "danger") else: try: # product.sub_category_id = form.sub_category.data product.name = form.name.data product.price = form.price.data product.description = form.description.data product.product = form.price.data product.buying_price = form.buying_price.data product.selling_price = form.selling_price.data product.served_with = form.served_with.data product.commission_fee = form.commission_fee.data product.headsup = form.headsup.data product.free_delivery = form.free_delivery.data session.commit() flash("Product updated successfully", "success") except Exception as e: print("Customer care updating product error:", e) session.rollback() flash("Internal server error failed to update product.", "danger") return redirect( url_for("customer_care.rest_product_detail", product_id=product_id)) return render_template( 'restaurants/restaurant/product/product_details.html', shop=restuarant, product=product, product_rating=product_rating, comments=comments, form=form, promo_form=promotional_price_form, suspend_form=suspend_form, top_selling_status=top_selling_status)
def get(self, id): rest = Resturant.read_restaurant(id) return rest.serialize()
def get(self): return jsonify(restaurants = list(rest_generator(Resturant.read_restaurants())))