From e9892aba8988a526846271417870b0d4cacbf262 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Mon, 13 Jan 2025 10:19:49 -0600 Subject: [PATCH] feat: Move "on hand" and "last made" to household (#4616) Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com> --- docs/docs/overrides/api.html | 2 +- .../Recipe/RecipeDialogAddToShoppingList.vue | 10 +- .../Domain/Recipe/RecipeLastMade.vue | 35 +- .../RecipePageParts/RecipePageInfoCard.vue | 1 - .../RecipePageIngredientToolsView.vue | 37 ++- frontend/components/global/AppLoader.vue | 15 +- .../composables/recipes/use-recipe-tools.ts | 1 - frontend/composables/store/use-food-store.ts | 1 - frontend/composables/store/use-tool-store.ts | 7 +- frontend/lib/api/types/admin.ts | 2 +- frontend/lib/api/types/cookbook.ts | 2 +- frontend/lib/api/types/household.ts | 29 +- frontend/lib/api/types/meal-plan.ts | 2 +- frontend/lib/api/types/recipe.ts | 20 +- frontend/lib/api/user/households.ts | 6 + .../g/_groupSlug/recipes/tools/index.vue | 44 ++- frontend/pages/group/data/foods.vue | 68 +++- frontend/pages/group/data/recipe-actions.vue | 5 - frontend/pages/group/data/tools.vue | 57 +++- ...d3b3_add_household_to_recipe_last_made_.py | 263 +++++++++++++++ mealie/db/models/household/__init__.py | 2 + mealie/db/models/household/household.py | 17 + .../models/household/household_to_recipe.py | 60 ++++ mealie/db/models/recipe/ingredient.py | 37 ++- mealie/db/models/recipe/recipe.py | 5 + mealie/db/models/recipe/tool.py | 39 ++- mealie/repos/repository_factory.py | 16 +- mealie/repos/repository_generic.py | 10 +- mealie/repos/repository_household.py | 25 +- mealie/repos/repository_recipes.py | 148 ++++----- .../controller_household_self_service.py | 11 +- .../routes/households/controller_mealplan.py | 4 +- mealie/routes/organizers/controller_tools.py | 1 + mealie/routes/recipe/recipe_crud_routes.py | 12 +- mealie/routes/unit_and_foods/foods.py | 1 + mealie/schema/household/__init__.py | 10 + mealie/schema/household/household.py | 31 +- mealie/schema/recipe/recipe.py | 12 +- mealie/schema/recipe/recipe_ingredient.py | 18 +- mealie/schema/recipe/recipe_tool.py | 28 +- mealie/schema/response/query_filter.py | 117 ++++--- .../household_services/household_service.py | 51 ++- mealie/services/recipe/recipe_service.py | 12 +- .../scheduler/tasks/create_timeline_events.py | 7 +- pyproject.toml | 6 +- .../test_household_self_service.py | 65 ++++ .../test_recipe_cross_household.py | 55 +++- .../test_recipe_suggestions.py | 82 ++++- .../repository_tests/test_pagination.py | 103 ++++++ .../test_recipe_repository.py | 61 +++- .../backup_v2_tests/test_backup_v2.py | 307 ++++++++++-------- .../tasks/test_create_timeline_events.py | 53 ++- tests/utils/api_routes/__init__.py | 5 + 53 files changed, 1618 insertions(+), 400 deletions(-) create mode 100644 mealie/alembic/versions/2024-11-20-17.30.41_b9e516e2d3b3_add_household_to_recipe_last_made_.py create mode 100644 mealie/db/models/household/household_to_recipe.py diff --git a/docs/docs/overrides/api.html b/docs/docs/overrides/api.html index 8c7f4880d..a6f596205 100644 --- a/docs/docs/overrides/api.html +++ b/docs/docs/overrides/api.html @@ -14,7 +14,7 @@
diff --git a/frontend/components/Domain/Recipe/RecipeDialogAddToShoppingList.vue b/frontend/components/Domain/Recipe/RecipeDialogAddToShoppingList.vue index 789d59bd4..6f233b84f 100644 --- a/frontend/components/Domain/Recipe/RecipeDialogAddToShoppingList.vue +++ b/frontend/components/Domain/Recipe/RecipeDialogAddToShoppingList.vue @@ -204,6 +204,10 @@ export default defineComponent({ shoppingListShowAllToggled: false, }); + const userHousehold = computed(() => { + return $auth.user?.householdSlug || ""; + }); + const shoppingListChoices = computed(() => { return props.shoppingLists.filter((list) => preferences.value.viewAllLists || list.userId === $auth.user?.id); }); @@ -248,8 +252,9 @@ export default defineComponent({ } const shoppingListIngredients: ShoppingListIngredient[] = recipe.recipeIngredient.map((ing) => { + const householdsWithFood = (ing.food?.householdsWithIngredientFood || []); return { - checked: !ing.food?.onHand, + checked: !householdsWithFood.includes(userHousehold.value), ingredient: ing, disableAmount: recipe.settings?.disableAmount || false, } @@ -276,7 +281,8 @@ export default defineComponent({ } // Store the on-hand ingredients for later - if (ing.ingredient.food?.onHand) { + const householdsWithFood = (ing.ingredient.food?.householdsWithIngredientFood || []); + if (householdsWithFood.includes(userHousehold.value)) { onHandIngs.push(ing); return sections; } diff --git a/frontend/components/Domain/Recipe/RecipeLastMade.vue b/frontend/components/Domain/Recipe/RecipeLastMade.vue index d60de97b4..178db28bd 100644 --- a/frontend/components/Domain/Recipe/RecipeLastMade.vue +++ b/frontend/components/Domain/Recipe/RecipeLastMade.vue @@ -96,7 +96,12 @@ {{ $globals.icons.calendar }} - {{ $t('recipe.last-made-date', { date: value ? new Date(value).toLocaleDateString($i18n.locale) : $t("general.never") } ) }} +
+ {{ $t('recipe.last-made-date', { date: lastMade ? new Date(lastMade).toLocaleDateString($i18n.locale) : $t("general.never") } ) }} +
+
+ +
@@ -110,7 +115,7 @@