def tab_dispatch_order(tab_id, order_id): user = req_helper.force_session_get_user() if not user.is_staff(): req_helper.throw_not_allowed() # Look for tab and abort if not found tab = Tab.tab_from_id(tab_id) if not tab: req_helper.throw_not_found("Specified tab could not be found!") order = tab.get_order(order_id) if order is None: req_helper.throw_not_found("The order id was not found in this tab.") if order['status'] == Tab.Order.SERVED: req_helper.throw_operation_failed("This order has already reached the last status.") if user.is_cook(): if order['status'] == 0: result = tab.dispatch(order_id) else: req_helper.throw_operation_failed("A cook cannot do this.") elif user.is_waiter(): if order['status'] == 1: result = tab.dispatch(order_id) else: req_helper.throw_operation_failed("A cook cannot do this.") else: result = tab.dispatch(order_id) if result: return jsonify(message='Ok!', new_status=order['status']+1) else: req_helper.throw_operation_failed("Failed to dispatch order!")
def get_by_id(recipe_id): req_helper.force_session_get_user() result = Recipe.query_id(recipe_id) if result is not None: return jsonify(result.__dict__) else: req_helper.throw_not_found()
def tab_close(tab_id): user = req_helper.force_session_get_user() if not user.is_staff(): req_helper.throw_not_allowed() tab = Tab.tab_from_id(tab_id) if not tab: req_helper.throw_not_found("Specified tab could not be found!") tab.close()
def tab_preview(tab_id): user = req_helper.force_session_get_user() tab = Tab.tab_from_id(tab_id) if not tab: req_helper.throw_not_found("Specified tab could not be found!") if not user.canEditTabs() and (user.id not in [val['id'] for val in tab.customers]): req_helper.throw_not_allowed(f"You're not allowed to view tab {tab_id}.") return jsonify(tab.toDict())
def material_find(): req_helper.force_session_get_user() data = req_helper.force_json_key_list('material-id') mat = Material.get_from_id(data['material-id']) if mat: return jsonify(mat.__dict__) else: req_helper.throw_not_found("Material not found!")
def inventory_checkout(): user = req_helper.force_session_get_user() if not user.canEditInventory(): req_helper.throw_not_allowed() data = req_helper.force_json_key_list('inventory-id') item = Item.get_from_id(data['inventory-id']) if not item: req_helper.throw_not_found("Item not found!") if item.destroy() == 1: return jsonify(message="Ok!") else: req_helper.throw_operation_failed()
def tab_add_customer(tab_id): user = req_helper.force_session_get_user() tab = Tab.tab_from_id(tab_id) data = req_helper.force_json_key_list('username') if not tab: req_helper.throw_not_found("Specified tab could not be found!") if not user.canEditTabs() and (user.id not in [val['id'] for val in tab.customers]): req_helper.throw_not_allowed(f"You're not allowed to add costumers to tab {tab_id}.") if tab.addCustomer(data['username']): return jsonify(message="Ok!") else: req_helper.throw_operation_failed("Failed to add user!")
def user_delete(): usr = req_helper.force_session_get_user() if not usr.canEditUsers(): req_helper.throw_not_allowed() data = req_helper.force_json_key_list('user-id') user = User.get_from_id(data['user-id']) if not user: req_helper.throw_not_found("User not found!") user.logout() if user.destroy() == 1: return jsonify(message="Ok!") else: req_helper.throw_operation_failed()
def tab_add_order(tab_id): user = req_helper.force_session_get_user() tab = Tab.tab_from_id(tab_id) data = req_helper.force_json_key_list('recipe-id') if not tab: req_helper.throw_not_found("Specified tab could not be found!") if not user.canEditTabs() and (user.id not in [val['id'] for val in tab.customers]): req_helper.throw_not_allowed(f"You're not allowed to add orders to tab {tab_id}.") out = tab.addOrder(data['recipe-id']) # Weird thing to make sure it catches only a False and not a 0 if not(out is False): return jsonify(message="Ok!", time=out) else: req_helper.throw_operation_failed("Failed to add order!")