[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 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"]) @pricelist_bp.route("/users/<userid>/pricecalc_columns", methods=["GET", "PUT"])
@login_required() @login_required()
def get_columns(userid, current_session: Session): def get_columns(userid, current_session: Session):

View File

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