diff --git a/mealie/services/household_services/shopping_lists.py b/mealie/services/household_services/shopping_lists.py index e502eebe9..f05ef26f6 100644 --- a/mealie/services/household_services/shopping_lists.py +++ b/mealie/services/household_services/shopping_lists.py @@ -482,7 +482,7 @@ class ShoppingListService: # since this is the same recipe, we combine the quanities, rather than the scales # all items will have exactly one recipe reference if ingredient.quantity: - existing_item.quantity += ingredient.quantity + existing_item.quantity += ingredient.quantity * scale existing_item.recipe_references[0].recipe_quantity += ingredient.quantity # type: ignore # merge notes diff --git a/tests/integration_tests/user_household_tests/test_group_shopping_lists.py b/tests/integration_tests/user_household_tests/test_group_shopping_lists.py index 445eeb249..9fc0b7866 100644 --- a/tests/integration_tests/user_household_tests/test_group_shopping_lists.py +++ b/tests/integration_tests/user_household_tests/test_group_shopping_lists.py @@ -1054,6 +1054,51 @@ def test_shopping_list_add_recipe_scale( assert refs[0]["recipeScale"] == 1 + recipe_scale +def test_shopping_list_add_recipe_scale_merges_duplicate_foods( + api_client: TestClient, + unique_user: TestUser, + shopping_list: ShoppingListOut, +): + database = unique_user.repos + food = database.ingredient_foods.create(SaveIngredientFood(name=random_string(10), group_id=unique_user.group_id)) + recipe: Recipe = database.recipes.create( + Recipe( + name=random_string(10), + user_id=unique_user.user_id, + group_id=unique_user.group_id, + recipe_ingredient=[ + RecipeIngredient(note="batter", food=food, quantity=1), + RecipeIngredient(note="topping", food=food, quantity=2), + ], + ) + ) + + response = api_client.post( + api_routes.households_shopping_lists_item_id_recipe(shopping_list.id), + json=utils.jsonify( + [ShoppingListAddRecipeParamsBulk(recipe_id=recipe.id, recipe_increment_quantity=2).model_dump()] + ), + headers=unique_user.token, + ) + utils.assert_deserialize(response, 200) + + response = api_client.get( + api_routes.households_shopping_lists_item_id(shopping_list.id), + headers=unique_user.token, + ) + as_json = utils.assert_deserialize(response, 200) + + assert len(as_json["listItems"]) == 1 + item = as_json["listItems"][0] + + # both lines are scaled before they are combined + assert item["quantity"] == 6 + refs = item["recipeReferences"] + assert len(refs) == 1 + assert refs[0]["recipeQuantity"] == 3 + assert refs[0]["recipeScale"] == 2 + + def test_shopping_lists_remove_recipe( api_client: TestClient, unique_user: TestUser,