@@ -75,7 +101,8 @@ import ShoppingListItemEditor from "./ShoppingListItemEditor.vue";
import MultiPurposeLabel from "./MultiPurposeLabel.vue";
import { ShoppingListItemOut } from "~/lib/api/types/group";
import { MultiPurposeLabelOut, MultiPurposeLabelSummary } from "~/lib/api/types/labels";
-import { IngredientFood, IngredientUnit } from "~/lib/api/types/recipe";
+import { IngredientFood, IngredientUnit, RecipeSummary } from "~/lib/api/types/recipe";
+import RecipeList from "~/components/Domain/Recipe/RecipeList.vue";
interface actions {
text: string;
@@ -105,10 +132,15 @@ export default defineComponent({
type: Array as () => IngredientFood[],
required: true,
},
+ recipes: {
+ type: Map,
+ default: undefined,
+ }
},
setup(props, context) {
const { i18n } = useContext();
- const itemLabelCols = ref(props.value.checked ? "auto" : props.showLabel ? "6" : "8");
+ const displayRecipeRefs = ref(false);
+ const itemLabelCols = ref(props.value.checked ? "auto" : props.showLabel ? "4" : "6");
const contextMenu: actions[] = [
{
@@ -190,16 +222,34 @@ export default defineComponent({
return undefined;
});
+ const recipeList = computed(() => {
+ const recipeList: RecipeSummary[] = [];
+ if (!listItem.value.recipeReferences) {
+ return recipeList;
+ }
+
+ listItem.value.recipeReferences.forEach((ref) => {
+ const recipe = props.recipes.get(ref.recipeId)
+ if (recipe) {
+ recipeList.push(recipe);
+ }
+ });
+
+ return recipeList;
+ });
+
return {
updatedLabels,
save,
contextHandler,
+ displayRecipeRefs,
edit,
contextMenu,
itemLabelCols,
listItem,
localListItem,
label,
+ recipeList,
toggleEdit,
};
},
diff --git a/frontend/lib/api/types/group.ts b/frontend/lib/api/types/group.ts
index a0dd0517e00b..42fb45a85461 100644
--- a/frontend/lib/api/types/group.ts
+++ b/frontend/lib/api/types/group.ts
@@ -359,6 +359,7 @@ export interface ShoppingListItemRecipeRefCreate {
recipeId: string;
recipeQuantity?: number;
recipeScale?: number;
+ recipeNote?: string;
}
export interface ShoppingListItemOut {
quantity?: number;
@@ -387,6 +388,7 @@ export interface ShoppingListItemRecipeRefOut {
recipeId: string;
recipeQuantity?: number;
recipeScale?: number;
+ recipeNote?: string;
id: string;
shoppingListItemId: string;
}
@@ -394,6 +396,7 @@ export interface ShoppingListItemRecipeRefUpdate {
recipeId: string;
recipeQuantity?: number;
recipeScale?: number;
+ recipeNote?: string;
id: string;
shoppingListItemId: string;
}
diff --git a/frontend/pages/shopping-lists/_id.vue b/frontend/pages/shopping-lists/_id.vue
index f80f1ff1a9d9..7452ecc8fe32 100644
--- a/frontend/pages/shopping-lists/_id.vue
+++ b/frontend/pages/shopping-lists/_id.vue
@@ -19,6 +19,7 @@
:labels="allLabels || []"
:units="allUnits || []"
:foods="allFoods || []"
+ :recipes="recipeMap"
@checked="saveListItem"
@save="saveListItem"
@delete="deleteListItem(item)"
@@ -46,6 +47,7 @@
:labels="allLabels || []"
:units="allUnits || []"
:foods="allFoods || []"
+ :recipes="recipeMap"
@checked="saveListItem"
@save="saveListItem"
@delete="deleteListItem(item)"
@@ -175,8 +177,8 @@
{{ $tc('shopping-list.linked-recipes-count', shoppingList.recipeReferences ? shoppingList.recipeReferences.length : 0) }}
-
-
+
+
{{ $globals.icons.minus }}
@@ -530,9 +532,10 @@ export default defineComponent({
// =====================================
// Add/Remove Recipe References
- const listRecipes = computed>(() => {
- return shoppingList.value?.recipeReferences?.map((ref) => ref.recipe) ?? [];
- });
+ const recipeMap = computed(() => new Map(
+ (shoppingList.value?.recipeReferences?.map((ref) => ref.recipe) ?? [])
+ .map((recipe) => [recipe.id || "", recipe]))
+ );
async function addRecipeReferenceToList(recipeId: string) {
if (!shoppingList.value || recipeReferenceLoading.value) {
@@ -741,10 +744,10 @@ export default defineComponent({
getLabelColor,
itemsByLabel,
listItems,
- listRecipes,
loadingCounter,
preferences,
presentLabels,
+ recipeMap,
removeRecipeReferenceToList,
reorderLabelsDialog,
toggleReorderLabelsDialog,
diff --git a/mealie/db/models/group/shopping_list.py b/mealie/db/models/group/shopping_list.py
index 01c0086bdbd7..e111537063eb 100644
--- a/mealie/db/models/group/shopping_list.py
+++ b/mealie/db/models/group/shopping_list.py
@@ -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:
diff --git a/mealie/schema/group/group_shopping_list.py b/mealie/schema/group/group_shopping_list.py
index 82d4c27d1b14..546b47a5c1d6 100644
--- a/mealie/schema/group/group_shopping_list.py
+++ b/mealie/schema/group/group_shopping_list.py
@@ -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
diff --git a/mealie/services/group_services/shopping_lists.py b/mealie/services/group_services/shopping_lists.py
index 99e088d2b97a..1315e796ef6d 100644
--- a/mealie/services/group_services/shopping_lists.py
+++ b/mealie/services/group_services/shopping_lists.py
@@ -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