mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-12 13:25:14 -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:
@@ -5,11 +5,7 @@ from sqlalchemy.ext.orderinglist import ordering_list
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from mealie.db.models.labels import MultiPurposeLabel
|
||||
from mealie.db.models.recipe.api_extras import (
|
||||
ShoppingListExtras,
|
||||
ShoppingListItemExtras,
|
||||
api_extras,
|
||||
)
|
||||
from mealie.db.models.recipe.api_extras import ShoppingListExtras, ShoppingListItemExtras, api_extras
|
||||
|
||||
from .._model_base import BaseMixins, SqlAlchemyBase
|
||||
from .._model_utils import GUID, auto_init
|
||||
@@ -30,6 +26,7 @@ class ShoppingListItemRecipeReference(BaseMixins, SqlAlchemyBase):
|
||||
recipe: Mapped[Optional["RecipeModel"]] = orm.relationship("RecipeModel", back_populates="shopping_list_item_refs")
|
||||
recipe_quantity: Mapped[float] = mapped_column(Float, nullable=False)
|
||||
recipe_scale: Mapped[float | None] = mapped_column(Float, default=1)
|
||||
recipe_note: Mapped[str | None] = mapped_column(String)
|
||||
|
||||
@auto_init()
|
||||
def __init__(self, **_) -> None:
|
||||
|
||||
@@ -35,6 +35,9 @@ class ShoppingListItemRecipeRefCreate(MealieModel):
|
||||
recipe_scale: NoneFloat = 1
|
||||
"""the number of times this recipe has been added"""
|
||||
|
||||
recipe_note: str | None = None
|
||||
"""the original note from the recipe"""
|
||||
|
||||
@validator("recipe_quantity", pre=True)
|
||||
def default_none_to_zero(cls, v):
|
||||
return 0 if v is None else v
|
||||
|
||||
@@ -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