diff --git a/changelog/67_UNRELEASED_xxxx-xx-xx.md b/changelog/67_UNRELEASED_xxxx-xx-xx.md new file mode 100644 index 00000000..e9a29586 --- /dev/null +++ b/changelog/67_UNRELEASED_xxxx-xx-xx.md @@ -0,0 +1,55 @@ +> ⚠️ xxxBREAKING CHANGESxxx + +> ❗ xxxImportant upgrade informationXXX + +### New feature: xxxx + +- xxx + +### Stock + +- xxx + +### Shopping list + +- xxx + +### Recipes + +- Fixed that consuming recipes was possible when not all ingredients were in-stock (and this potentially consumed some of the in-stock ingredients; not matching the message "nothing removed") + +### Meal plan + +- xxx + +### Chores + +- xxx + +### Calendar + +- xxx + +### Tasks + +- xxx + +### Batteries + +- xxx + +### Equipment + +- xxx + +### Userfields + +- xxx + +### General + +- xxx + +### API + +- Endpoint `/recipes/{recipeId}/consume`: Fixed that consuming partially fulfilled recipes was possible, although an error was already returned in that case (and potentially some of the in-stock ingredients were consumed in fact) diff --git a/grocy.openapi.json b/grocy.openapi.json index 6890654d..2c30a4d0 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -3388,6 +3388,16 @@ "responses": { "204": { "description": "The operation was successful" + }, + "400": { + "description": "The operation was not successful (possible errors are: Invalid recipe id, recipe need is not fulfilled)", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error400" + } + } + } } } } diff --git a/services/RecipesService.php b/services/RecipesService.php index 7b17d0f7..7249150f 100644 --- a/services/RecipesService.php +++ b/services/RecipesService.php @@ -74,6 +74,12 @@ class RecipesService extends BaseService throw new \Exception('Recipe does not exist'); } + $recipeResolved = $this->getDatabase()->recipes_resolved()->where('recipe_id', $recipeId)->fetch(); + if ($recipeResolved->need_fulfilled == 0) + { + throw new \Exception('Recipe need is not fulfilled, consuming not possible'); + } + $transactionId = uniqid(); $recipePositions = $this->getDatabase()->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll(); diff --git a/views/recipes.blade.php b/views/recipes.blade.php index d754f364..00d1b0af 100644 --- a/views/recipes.blade.php +++ b/views/recipes.blade.php @@ -295,7 +295,7 @@