diff --git a/app/models/order.py b/app/models/order.py index 360604c..d4f3fcf 100644 --- a/app/models/order.py +++ b/app/models/order.py @@ -56,15 +56,19 @@ class Order(db.Model): return group - def group_by_dish(self) -> typing.Dict[str, typing.Any]: + def group_by_dish(self, sort_comments=False) -> typing.Dict[str, typing.Dict[str, typing.Any]]: "Group items of an Order by dish" - group: typing.Dict[str, typing.Any] = dict() + group: typing.Dict[str, typing.Dict[str, typing.Any]] = dict() for item in self.items: dish = group.get(item.dish_name, dict()) dish["count"] = dish.get("count", 0) + 1 dish["comments"] = dish.get("comments", []) + [item.comment] group[item.dish_name] = dish + if sort_comments: + for _dish_name, dish_props in group.items(): + dish_props["comments"].sort() + return group def is_closed(self) -> bool: diff --git a/app/templates/order_items.html b/app/templates/order_items.html index 12b0231..917c4aa 100644 --- a/app/templates/order_items.html +++ b/app/templates/order_items.html @@ -33,7 +33,7 @@ Haldis - Order {{ order.id }} {% endif %} - {% for key, value in order.group_by_dish().items() -%} + {% for key, value in order.group_by_dish(True).items() -%}