diff --git a/cookbook/helper/shopping_helper.py b/cookbook/helper/shopping_helper.py index ffcf5bea..c7772a07 100644 --- a/cookbook/helper/shopping_helper.py +++ b/cookbook/helper/shopping_helper.py @@ -27,9 +27,6 @@ def shopping_helper(qs, request): elif checked in ['true', 1, '1']: qs = qs.filter(checked=True) elif checked in ['recent']: - today_start = timezone.now().replace(hour=0, minute=0, second=0) - week_ago = today_start - timedelta(days=user.userpreference.shopping_recent_days) - qs = qs.filter(Q(checked=False) | Q(completed_at__gte=week_ago)) supermarket_order = ['checked'] + supermarket_order return qs.distinct().order_by(*supermarket_order).select_related('unit', 'food', 'ingredient', 'created_by', 'list_recipe', 'list_recipe__mealplan', 'list_recipe__recipe') diff --git a/cookbook/views/api.py b/cookbook/views/api.py index da59419b..46009eab 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -1165,6 +1165,10 @@ class ShoppingListEntryViewSet(viewsets.ModelViewSet): if 'checked' in self.request.query_params or 'recent' in self.request.query_params: return shopping_helper(self.queryset, self.request) + today_start = timezone.now().replace(hour=0, minute=0, second=0) + week_ago = today_start - datetime.timedelta(days=max(self.request.user.userpreference.shopping_recent_days, 14)) + self.queryset = self.queryset.filter(Q(checked=False) | Q(completed_at__gte=week_ago)) + try: last_autosync = self.request.query_params.get('last_autosync', None) if last_autosync: @@ -1175,7 +1179,7 @@ class ShoppingListEntryViewSet(viewsets.ModelViewSet): traceback.print_exc() # TODO once old shopping list is removed this needs updated to sharing users in preferences - return self.queryset + return self.queryset[:1000] @decorators.action( detail=False,