Live refresh inventory scan review counts

This commit is contained in:
Joren de Graaf
2026-10-26 20:21:53 +01:00
parent 7d9beb915f
commit 129ceec408
6 changed files with 137 additions and 9 deletions
+30 -1
View File
@@ -12,7 +12,9 @@ from planner.models import UserSettings
from .services.diary import diary_context, ring_progress
from .models import FoodFavourite, FoodLogAttachment, FoodLogEntry, FoodPortion, FoodProduct, MealType, Unit, InventoryLocation, KitchenInventoryItem, InventoryConsumption
from .models import (FoodFavourite, FoodLogAttachment, FoodLogEntry, FoodPortion, FoodProduct, MealType, Unit,
InventoryLocation, KitchenInventoryItem, InventoryConsumption, InventoryScanRun,
InventoryScanBatch, InventoryScanItem)
class FoodFoundationTests(TestCase):
@@ -21,6 +23,33 @@ class FoodFoundationTests(TestCase):
self.other = get_user_model().objects.create_user(username='food-two', password='test-password')
self.product = FoodProduct.objects.create(owner=self.user, product_name='Yoghurt', barcode='123', base_unit=Unit.GRAM)
def test_inventory_staging_counts_refresh_and_are_user_scoped(self):
location = InventoryLocation.objects.create(user=self.user, name='Fridge')
run = InventoryScanRun.objects.create(user=self.user)
batch = InventoryScanBatch.objects.create(run=run, location=location, sequence=1)
InventoryScanItem.objects.create(batch=batch, location=location, barcode='111',
status=InventoryScanItem.Status.QUEUED)
InventoryScanItem.objects.create(batch=batch, location=location, barcode='222',
status=InventoryScanItem.Status.FAILED)
other_location = InventoryLocation.objects.create(user=self.other, name='Other fridge')
other_run = InventoryScanRun.objects.create(user=self.other)
other_batch = InventoryScanBatch.objects.create(run=other_run, location=other_location, sequence=1)
InventoryScanItem.objects.create(batch=other_batch, location=other_location, barcode='333',
status=InventoryScanItem.Status.PROCESSING)
self.client.force_login(self.user)
url = reverse('food:inventory-staging-counts')
response = self.client.get(url, secure=True)
self.assertEqual(response.status_code, 200)
self.assertContains(response, '<strong>1</strong>', html=True)
self.assertContains(response, '<strong>1</strong>', html=True)
self.assertContains(response, 'hx-trigger="load, every 5s"')
InventoryScanItem.objects.filter(batch=batch, barcode='111').update(status=InventoryScanItem.Status.COMPLETE)
response = self.client.get(url, secure=True)
self.assertContains(response, '<strong>0</strong>', html=True)
self.assertContains(response, '<strong>1</strong>', html=True)
def test_meals_are_fixed(self):
self.assertEqual(list(MealType.values), ['breakfast', 'lunch', 'dinner', 'snacks'])