respect ignore_shopping flag
This commit is contained in:
parent
c72bf57ccb
commit
f8f08ae337
@ -176,7 +176,7 @@ class RecipeShoppingEditor():
|
||||
if not ingredients:
|
||||
return
|
||||
elif isinstance(ingredients, list):
|
||||
ingredients = Ingredient.objects.filter(id__in=ingredients)
|
||||
ingredients = Ingredient.objects.filter(id__in=ingredients, food__ignore_shopping=False)
|
||||
existing = self._shopping_list_recipe.entries.filter(ingredient__in=ingredients).values_list('ingredient__pk', flat=True)
|
||||
add_ingredients = ingredients.exclude(id__in=existing)
|
||||
|
||||
|
@ -969,10 +969,11 @@ class RecipeViewSet(viewsets.ModelViewSet):
|
||||
raise PermissionDenied(detail='Not available in demo', code=None)
|
||||
obj = self.get_object()
|
||||
ingredients = request.data.get('ingredients', None)
|
||||
|
||||
servings = request.data.get('servings', None)
|
||||
list_recipe = request.data.get('list_recipe', None)
|
||||
mealplan = request.data.get('mealplan', None)
|
||||
SLR = RecipeShoppingEditor(request.user, request.space, id=list_recipe, recipe=obj, mealplan=mealplan)
|
||||
SLR = RecipeShoppingEditor(request.user, request.space, id=list_recipe, recipe=obj, mealplan=mealplan, servings=servings)
|
||||
|
||||
content = {'msg': _(f'{obj.name} was added to the shopping list.')}
|
||||
http_status = status.HTTP_204_NO_CONTENT
|
||||
|
@ -1,7 +1,9 @@
|
||||
<template>
|
||||
<div>
|
||||
<b-modal hide-footer :id="`shopping_${this.modal_id}`" @show="loadRecipe" body-class="p-3 pt-0 pt-md-3">
|
||||
<template v-slot:modal-title><h5>{{ $t("Add_Servings_to_Shopping", {servings: recipe_servings}) }}</h5></template>
|
||||
<template v-slot:modal-title
|
||||
><h5>{{ $t("Add_Servings_to_Shopping", { servings: recipe_servings }) }}</h5></template
|
||||
>
|
||||
<loading-spinner v-if="loading"></loading-spinner>
|
||||
<div class="accordion" role="tablist" v-if="!loading">
|
||||
<b-card no-body class="mb-1">
|
||||
@ -9,11 +11,11 @@
|
||||
<b-button block v-b-toggle.accordion-0 class="text-left" variant="outline-info">{{ recipe.name }}</b-button>
|
||||
</b-card-header>
|
||||
<b-collapse id="accordion-0" class="p-2" visible accordion="my-accordion" role="tabpanel">
|
||||
|
||||
<div>
|
||||
<table class="table table-sm mb-0">
|
||||
|
||||
<ingredient-component v-for="i in steps.flatMap(s => s.ingredients)" v-bind:key="i.id"
|
||||
<ingredient-component
|
||||
v-for="i in steps.flatMap((s) => s.ingredients)"
|
||||
v-bind:key="i.id"
|
||||
:detailed="true"
|
||||
:ingredient="i"
|
||||
:ingredient_factor="ingredient_factor"
|
||||
@ -29,8 +31,7 @@
|
||||
<b-button btn-sm block v-b-toggle="'accordion-' + r.recipe.id" class="text-left" variant="outline-primary">{{ r.recipe.name }}</b-button>
|
||||
</b-card-header>
|
||||
<b-collapse :id="'accordion-' + r.recipe.id" accordion="my-accordion" role="tabpanel">
|
||||
|
||||
<div v-for="i in r.steps.flatMap(s => s.ingredients)" v-bind:key="i.id">
|
||||
<div v-for="i in r.steps.flatMap((s) => s.ingredients)" v-bind:key="i.id">
|
||||
<table class="table table-sm mb-0">
|
||||
<ingredient-component
|
||||
:use_plural="true"
|
||||
@ -77,7 +78,7 @@ const {ApiApiFactory} = require("@/utils/openapi/api")
|
||||
import { StandardToasts } from "@/utils/utils"
|
||||
import IngredientComponent from "@/components/IngredientComponent"
|
||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||
import {useMealPlanStore} from "@/stores/MealPlanStore";
|
||||
import { useMealPlanStore } from "@/stores/MealPlanStore"
|
||||
// import CustomInputSpinButton from "@/components/CustomInputSpinButton"
|
||||
|
||||
export default {
|
||||
@ -127,7 +128,7 @@ export default {
|
||||
if (!this.recipe_servings) {
|
||||
this.recipe_servings = result.data?.servings
|
||||
}
|
||||
this.steps.forEach(s => s.ingredients.filter(i => i.food?.food_onhand === false).forEach(i => this.$set(i, 'checked', true)))
|
||||
this.steps.forEach((s) => s.ingredients.filter((i) => i.food?.food_onhand === false).forEach((i) => this.$set(i, "checked", true)))
|
||||
this.loading = false
|
||||
})
|
||||
.then(() => {
|
||||
@ -143,7 +144,7 @@ export default {
|
||||
promises.push(
|
||||
apiClient.listSteps(x.id).then((recipe_steps) => {
|
||||
let sub_recipe_steps = recipe_steps.data.results.filter((x) => x.ingredients.length > 0)
|
||||
sub_recipe_steps.forEach(s => s.ingredients.filter(i => i.food.food_onhand === false).forEach(i => this.$set(i, 'checked', true)))
|
||||
sub_recipe_steps.forEach((s) => s.ingredients.filter((i) => i.food.food_onhand === false).forEach((i) => this.$set(i, "checked", true)))
|
||||
this.related_recipes.push({
|
||||
recipe: x,
|
||||
steps: sub_recipe_steps,
|
||||
@ -159,13 +160,16 @@ export default {
|
||||
// another choice would be to create ShoppingListRecipes for each recipe - this bundles all related recipe under the parent recipe
|
||||
let shopping_recipe = {
|
||||
id: this.recipe.id,
|
||||
ingredients: this.steps.flatMap(s => s.ingredients.filter(i => i.checked === true).flatMap(i => i.id)).concat(this.related_recipes.flatMap(r => r.steps.flatMap(rs => rs.ingredients.filter(i => i.checked === true).flatMap(i => i.id)))),
|
||||
ingredients: this.steps
|
||||
.flatMap((s) => s.ingredients.filter((i) => i.checked === true).flatMap((i) => i.id))
|
||||
.concat(this.related_recipes.flatMap((r) => r.steps.flatMap((rs) => rs.ingredients.filter((i) => i.checked === true).flatMap((i) => i.id)))),
|
||||
servings: this.recipe_servings,
|
||||
mealplan: this.mealplan,
|
||||
list_recipe: this.list_recipe,
|
||||
}
|
||||
let apiClient = new ApiApiFactory()
|
||||
apiClient.shoppingRecipe(this.recipe.id, shopping_recipe)
|
||||
apiClient
|
||||
.shoppingRecipe(this.recipe.id, shopping_recipe)
|
||||
.then((result) => {
|
||||
StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_CREATE)
|
||||
this.$emit("finish")
|
||||
|
Loading…
Reference in New Issue
Block a user