Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions deliveries/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def new_delivery(sender, instance, created, **kwargs):
"""
Signal handler for new delivery creation.

This function is triggered when a new delivery instance is created. It checks the kitchen, bar,
and general status of the order associated with the delivery instance. If all statuses are either
2 or 4, it triggers a push notification to inform about the new delivery.
This function is triggered when a new delivery instance is created. It checks if all stations
are complete for the order associated with the delivery instance. If all statuses are complete,
it triggers a push notification to inform about the new delivery.

Args:
sender (Model): The model class that sent the signal.
Expand All @@ -22,7 +22,8 @@ def new_delivery(sender, instance, created, **kwargs):
Returns:
None
"""
if instance.order.kitchen_status in [2, 4] and instance.order.bar_status in [2, 4] and instance.order.gng_status in [2, 4]:
# Use the new all_stations_complete method for checking order readiness
if instance.order.all_stations_complete():
trigger_push_notifications(
"New delivery!",
"New order available to deliver. Check your app!",
Expand Down
12 changes: 11 additions & 1 deletion deliveries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,24 @@ def ready_orders(request):
"""
courier = check_if_active_courier(request)
today = timezone.localdate()

# Filter orders that are ready for delivery
# An order is ready when all legacy stations are complete (2 or 4)
# and no dynamic stations are pending (0) or in progress (1)
orders = Delivery.objects.filter(
order__kitchen_status__in = [2, 4],
order__bar_status__in = [2, 4],
order__gng_status__in = [2, 4],
completed=False,
order__picked_up=False,
timestamp__date=today
)
).exclude(
# Exclude orders with pending or in-progress dynamic stations
order__status_0_stations__isnull=False
).exclude(
order__status_1_stations__isnull=False
).distinct()

if courier:
for d in Delivery.objects.filter(completed = False).all():
if d.courier == request.user:
Expand Down
8 changes: 7 additions & 1 deletion new_admin/templates/new_admin/menus-instance.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ <h1>
<tr>
<td>#{{ dish.id }}</td>
<td>{{ dish.title }}</td>
<td>{{ dish.station }}</td>
<td>
{% if dish.new_station %}
{{ dish.new_station.friendly_name }}
{% else %}
{{ dish.station }}
{% endif %}
</td>
<td>
{% if dish.in_stock %}
<span class="material-symbols-outlined">check</span>
Expand Down
20 changes: 13 additions & 7 deletions online_store/templates/online_store/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ <h1>{{menu.menu.title}}</h1>
<div class="menu">
{% for station, items in menu.dishes.items %}
<div class="category">
{% if station == "bar" %}
<h2>{% trans "Drinks and sweets" %}</h2>
{% elif station == "kitchen" %}
<h2>{% trans "Hot food" %}</h2>
{% elif station == "gng" %}
<h2>{% trans "Packaged food" %}</h2>
{% endif %}
<h2>
{% if station_info and station in station_info %}
{{ station_info.name }}
{% elif station == "bar" %}
{% trans "Drinks and sweets" %}
{% elif station == "kitchen" %}
{% trans "Hot food" %}
{% elif station == "gng" %}
{% trans "Packaged food" %}
{% else %}
{{ station }}
{% endif %}
</h2>
<div class="dishes">
{% for dish in items %}
<div
Expand Down
39 changes: 28 additions & 11 deletions online_store/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def menu(request):
others (dict): A dictionary where keys are titles of inactive menus and values are dictionaries
of grouped dishes by station.
override_menu (str): The primary key of the menu to be set as active, if provided in the query parameters.
station_info (dict): Information about all stations for display purposes.
"""
query = request.GET.get('actual', None)
if query:
Expand All @@ -62,20 +63,28 @@ def menu(request):
active_dishes = Dish.objects.filter(menu=active)
grouped_active = defaultdict(list)
for dish in active_dishes:
grouped_active[dish.station].append({"obj":dish,"json":json.dumps([dish.serialize_with_options()])})
station_code = dish.station_code # Uses new_station.code or falls back to old station field
grouped_active[station_code].append({"obj":dish,"json":json.dumps([dish.serialize_with_options()])})
others = Menu.objects.filter(is_active = False).all()
grouped_other_menus = defaultdict(dict)
for menu_obj in others:
this_grouped = defaultdict(list)
this_dishes = Dish.objects.filter(menu=menu_obj)
for dish in this_dishes:
this_grouped[dish.station].append(dish)
station_code = dish.station_code
this_grouped[station_code].append(dish)
grouped_other_menus[menu_obj.title] = dict(this_grouped)

# Get station info for display
all_stations = Station.objects.all()
station_info = {s.code: {"name": s.friendly_name, "icon": s.icon} for s in all_stations}

return render(request, "online_store/menu.html", {
"route":"menu",
"menu":{"menu":active, "dishes":dict(grouped_active)},
"others":dict(grouped_other_menus),
"override_menu": query
"override_menu": query,
"station_info": station_info
})

def dish(request, id):
Expand Down Expand Up @@ -241,15 +250,23 @@ def place_order(request):
dish = Dish.objects.get(id=dish_id)
if check_if_only_choice_dish(dish):
continue
if dish.station == "bar":
order.bar_status = 0
order.picked_up = False
elif dish.station == "kitchen":
order.kitchen_status = 0
order.picked_up = False
elif dish.station == "gng":
order.gng_status = 0

# Use new dynamic station system
if dish.new_station:
order.set_station_status(dish.new_station, 0) # Set to pending
order.picked_up = False
else:
# Fallback to legacy station handling
if dish.station == "bar":
order.bar_status = 0
order.picked_up = False
elif dish.station == "kitchen":
order.kitchen_status = 0
order.picked_up = False
elif dish.station == "gng":
order.gng_status = 0
order.picked_up = False

for dc in dish.dishcomponent_set.all():
if dc.component.crafting_option == "auto":
craft_component(dc.component.id, 1)
Expand Down
21 changes: 19 additions & 2 deletions pos_server/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
admin.site.register(Ingredient)
admin.site.register(Order)
admin.site.register(Menu)
admin.site.register(Station)
admin.site.register(EligibleDevice)
# admin.site.register(OrderDish)
# admin.site.register(DishComponent)
# admin.site.register(ComponentIngredient)

class StationAdmin(admin.ModelAdmin):
list_display = ('friendly_name', 'code', 'icon')
search_fields = ('friendly_name', 'code')
ordering = ('friendly_name',)

admin.site.register(Station, StationAdmin)

class ComponentIngredientInline(admin.TabularInline):
model = ComponentIngredient
extra = 1 # Number of empty forms to display
Expand All @@ -27,7 +33,18 @@ class DishComponentInline(admin.TabularInline):

class DishAdmin(admin.ModelAdmin):
inlines = [DishComponentInline]
# You can add more customizations here if needed
list_display = ('title', 'price', 'get_station', 'in_stock', 'visible_in_menu')
list_filter = ('new_station', 'in_stock', 'visible_in_menu', 'menu')
search_fields = ('title', 'description')
ordering = ('title',)

def get_station(self, obj):
"""Returns the station name for the dish."""
if obj.new_station:
return obj.new_station.friendly_name
return obj.station
get_station.short_description = 'Station'
get_station.admin_order_field = 'new_station__friendly_name'

# Register the Dish model with the DishAdmin
admin.site.register(Dish, DishAdmin)
Loading
Loading