How to use a mapping model to convert a recipe to a shopping list?

I have the following RecipeDM document model representing recipes to be cooked in a kitchen:

I would like to create a shopping list from a recipe so that ingredients can be bought. Therefore I would like to use a mapping model to convert a recipe to a shopping list that is modeled as ShoppingListDM:

For example if I have a recipe for a cake it will specify to use 200g butter for the dough and 100g butter for the topping. Therefore I would like to see an entry in the shopping list that specifies 300g of butter should be bought.

How can I model this with the mapping model?

I am already stuck in the structural mapping model creating the entries for the different quantity units. When I want to specify that the quantity of the recipe ingredient should be mapped to the quantity of the shopping list entry I can not specify that the mapping should look for the product in the shopping list and recipe to be the same:

The models are:
ShoppingListDM.json (2.7 KB)
RecipeDM.json (3.0 KB)

Hi @andreas-fresh-mesa,

in the interests of answering quickly, here’s what I think the answer is:

RecipeToShoppingList_MaM.json (917 Bytes)
RecipeToShoppingList_SmM.json (1.4 KB)

I believe that you need to set the Source Group carefully.

The Documentation describes this here.

By setting the Source Group to be lower down, you “dissolve” the repetition layer. You can see this in Option 3 in the linked Documentation. In your case, this means that Stages and Ingredients are “dissolved” so that it is no longer possible to tell from which Stage the Ingredient came from.

In combination with the Find matching Repetition in the Target Document setting that you were trying to use, this should create the result you desire.

I’ve asked my colleague @felix-blazing-river to chekc this work as he’s the expert on this topic. However, if this model helps and creates the correct results for you, please let us know :slight_smile:

Hey @andreas-fresh-mesa ,

Your description and the screenshot of ShoppingListDM do not 100% match. I see two options:

  1. Transfer the individual quantities to the shopping list, then aggregate in ShoppingListDM with a Computation

→ use the SmM provided by @malcolm-silver-ice

→ add a Field “TotalAmountInBaseUnit“ and a Computation to the ShoppingListDM , make sure to handle the unit conversions in there to create the sum

→ The Mapping will only create the Entries and Quantities, it will not fill “TotalAmountInBaseUnit“ , so you must trigger a document compute after the mapping by custom code

  1. aggregate first in a Precomputation Model, then transfer the result (total amount) via the Structural Mapping Model

→ Create a Precomputation Model

→ Add Group Recipe/General/Stages/Ingredients to the model, create a Helper Field “Transfer_Product“ to decide when to aggregate (So the aggregation should only happen once), due to the nested structure, the Computation would look like this: (Note, that I changed the Repeatability of the Source in the Mapping Model from 1 to 11)

(There is now exactly one Transfer_Product Field filled for all unique Products. )

→ Create a sibling Helper Field Transfer_QuantityInBaseUnit with a Computation. The latter should have Precondition FieldFilled(Transfer_Product) to be only triggered once. In there, do the aggregation and value conversion.

→ Adopt the ShoppingListDM to show the AggregatedQuantityInBaseUnit

→ in the SMM just drag&drop Transfer_Product and Transfer_QuantityInBaseUnit. This can be a simple Append as there will always be just 1 repetition filled (and empty repetitions are not created)