mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-09 03:45:15 -05:00
feat: Display Shopping List Item Recipe Refs (#2501)
* added recipe ref display to shopping list items * added backend support for recipe notes * added recipe note to item recipe ref display * fixed note merge bug with 3+ notes * tweak display * lint * updated alembic refs --------- Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
This commit is contained in:
@@ -17,11 +17,7 @@ from mealie.schema.group.group_shopping_list import (
|
||||
ShoppingListMultiPurposeLabelCreate,
|
||||
ShoppingListSave,
|
||||
)
|
||||
from mealie.schema.recipe.recipe_ingredient import (
|
||||
IngredientFood,
|
||||
IngredientUnit,
|
||||
RecipeIngredient,
|
||||
)
|
||||
from mealie.schema.recipe.recipe_ingredient import IngredientFood, IngredientUnit, RecipeIngredient
|
||||
from mealie.schema.response.pagination import OrderDirection, PaginationQuery
|
||||
from mealie.schema.user.user import GroupInDB, PrivateUser
|
||||
|
||||
@@ -68,6 +64,11 @@ class ShoppingListService:
|
||||
if to_item.note != from_item.note:
|
||||
to_item.note = " | ".join([note for note in [to_item.note, from_item.note] if note])
|
||||
|
||||
if from_item.note and to_item.note != from_item.note:
|
||||
notes: set[str] = set(to_item.note.split(" | ")) if to_item.note else set()
|
||||
notes.add(from_item.note)
|
||||
to_item.note = " | ".join([note for note in notes if note])
|
||||
|
||||
if to_item.extras and from_item.extras:
|
||||
to_item.extras.update(from_item.extras)
|
||||
|
||||
@@ -318,7 +319,10 @@ class ShoppingListService:
|
||||
unit_id=unit_id,
|
||||
recipe_references=[
|
||||
ShoppingListItemRecipeRefCreate(
|
||||
recipe_id=recipe_id, recipe_quantity=ingredient.quantity, recipe_scale=scale
|
||||
recipe_id=recipe_id,
|
||||
recipe_quantity=ingredient.quantity,
|
||||
recipe_scale=scale,
|
||||
recipe_note=ingredient.note or None,
|
||||
)
|
||||
],
|
||||
)
|
||||
@@ -336,8 +340,10 @@ class ShoppingListService:
|
||||
existing_item.recipe_references[0].recipe_quantity += ingredient.quantity # type: ignore
|
||||
|
||||
# merge notes
|
||||
if existing_item.note != new_item.note:
|
||||
existing_item.note = " | ".join([note for note in [existing_item.note, new_item.note] if note])
|
||||
if new_item.note and existing_item.note != new_item.note:
|
||||
notes: set[str] = set(existing_item.note.split(" | ")) if existing_item.note else set()
|
||||
notes.add(new_item.note)
|
||||
existing_item.note = " | ".join([note for note in notes if note])
|
||||
|
||||
merged = True
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user