[pricelist] add modify settings, fixed update drinks

This commit is contained in:
Tim Gröger 2021-03-21 22:06:24 +01:00
parent b60c405f76
commit b98bae337d
2 changed files with 22 additions and 10 deletions

View File

@ -179,6 +179,19 @@ def delete_extra_ingredient(identifier):
return "", NO_CONTENT
@pricelist_bp.route("/settings/min_prices", methods=["POST", "GET"])
def pricelist_settings_min_prices():
if request.method == "GET":
return jsonify(PriceListPlugin.get_setting(PriceListPlugin, "min_prices"))
else:
data = request.get_json()
if not isinstance(data, list) or not all(isinstance(n, int) for n in data):
raise BadRequest
data.sort()
PriceListPlugin.set_setting(PriceListPlugin, "min_prices", data)
return no_content()
@pricelist_bp.route("/users/<userid>/pricecalc_columns", methods=["GET", "PUT"])
@login_required()
def get_columns(userid, current_session: Session):

View File

@ -128,25 +128,24 @@ def update_drink(identifier, data):
allowedKeys = Drink().serialize().keys()
if "id" in data:
data.pop("id")
values = {key: value for key, value in data.items() if key in allowedKeys}
volumes = None
if "volumes" in values:
volumes = values.pop("volumes")
if "tags" in values:
values.pop("tags")
if "volumes" in data:
volumes = data.pop("volumes")
if "tags" in data:
data.pop("tags")
type = None
if "type" in values:
_type = values.pop("type")
if "type" in data:
_type = data.pop("type")
if isinstance(_type, dict) and "id" in _type:
type = get_drink_type(_type.get("id"))
if identifier == -1:
drink = Drink(**values)
drink = Drink()
db.session.add(drink)
else:
drink = get_drink(identifier)
if not drink:
raise NotFound
for key, value in values.items():
for key, value in data.items():
if hasattr(drink, key):
setattr(drink, key, value if value != "" else None)
if type: