feature/pricelist #15

Merged
ferfissimo merged 11 commits from feature/pricelist into develop 2021-11-15 09:55:11 +00:00
2 changed files with 9 additions and 1 deletions
Showing only changes of commit e4b937991b - Show all commits

View File

@ -221,6 +221,7 @@ def get_drinks(identifier=None):
search_name = request.args.get("search_name") search_name = request.args.get("search_name")
search_key = request.args.get("search_key") search_key = request.args.get("search_key")
ingredient = request.args.get("ingredient", type=bool) ingredient = request.args.get("ingredient", type=bool)
receipt = request.args.get("receipt", type=bool)
try: try:
if limit is not None: if limit is not None:
limit = int(limit) limit = int(limit)
@ -228,6 +229,8 @@ def get_drinks(identifier=None):
offset = int(offset) offset = int(offset)
if ingredient is not None: if ingredient is not None:
ingredient = bool(ingredient) ingredient = bool(ingredient)
if receipt is not None:
receipt = bool(receipt)
except ValueError: except ValueError:
raise BadRequest raise BadRequest
drinks, count = pricelist_controller.get_drinks( drinks, count = pricelist_controller.get_drinks(
@ -237,6 +240,7 @@ def get_drinks(identifier=None):
search_name=search_name, search_name=search_name,
search_key=search_key, search_key=search_key,
ingredient=ingredient, ingredient=ingredient,
receipt=receipt,
) )
logger.debug(f"GET drink {drinks}, {count}") logger.debug(f"GET drink {drinks}, {count}")
# return jsonify({"drinks": drinks, "count": count}) # return jsonify({"drinks": drinks, "count": count})

View File

@ -131,7 +131,9 @@ def _create_public_drink(drink):
return None return None
def get_drinks(name=None, public=False, limit=None, offset=None, search_name=None, search_key=None, ingredient=False): def get_drinks(
name=None, public=False, limit=None, offset=None, search_name=None, search_key=None, ingredient=False, receipt=None
):
count = None count = None
if name: if name:
query = Drink.query.filter(Drink.name.contains(name)) query = Drink.query.filter(Drink.name.contains(name))
@ -139,6 +141,8 @@ def get_drinks(name=None, public=False, limit=None, offset=None, search_name=Non
query = Drink.query query = Drink.query
if ingredient: if ingredient:
query = query.filter(Drink.cost_per_volume >= 0) query = query.filter(Drink.cost_per_volume >= 0)
if receipt:
query = query.filter(Drink.volumes.any(DrinkPriceVolume.ingredients != None))
if search_name: if search_name:
if search_key == "name": if search_key == "name":
query = query.filter(Drink.name.contains(search_name)) query = query.filter(Drink.name.contains(search_name))