Quintiq file version 2.0
|
#parent: #root
|
Method MPSyncRecipeIngredient (
|
Boolean isoverwitemanualconfig,
|
IORecipeIngredients iorecipeingredients
|
)
|
{
|
Description: 'Synchronization of RecipeIngredient for MPSync'
|
TextBody:
|
[*
|
// Select a set of existing RecipeIngredient
|
existing := selectset( this, Recipe.RecipeIngredient, item, true );
|
updates := construct( RecipeIngredients );
|
|
// Traverse the new set of valid RecipeIngredient
|
traverse( iorecipeingredients , Elements, io, io.IsValid() )
|
{
|
recipename := io.RecipeName();
|
ingredientname := io.IngredientName();
|
|
objectinstance := RecipeIngredient::FindRecipeIngredientTypeIndex( recipename, ingredientname );
|
recipe := Recipe::FindRecipeTypeIndex( recipename );
|
ingredient := Ingredient::FindIngredientTypeIndex( ingredientname );
|
|
if( isnull( objectinstance ) )
|
{
|
if( not ( isnull( recipe ) or isnull( ingredient ) ) )
|
{
|
objectinstance := RecipeIngredient::Create( recipe, ingredient, true );
|
objectinstance.Update( io.Minimum(), io.Maximum(), io.Nominal() ,true );
|
}
|
}
|
// Else if the RecipeIngredient is not manually configured or the imported instance should overwrite manual configuration,
|
// update the existing RecipeIngredient
|
else if( not objectinstance.IsManuallyConfigured() or isoverwitemanualconfig )
|
{
|
// Update RecipeIngredient
|
objectinstance.Update( io.Minimum(), io.Maximum(), io.Nominal() ,true );
|
|
updates.Add( objectinstance );
|
}
|
|
if( not isnull( objectinstance ) )
|
{
|
// Extended method
|
objectinstance.CustomUpdate( io, isoverwitemanualconfig );
|
}
|
}
|
|
// Get the set of old RecipeIngredient to be deleted
|
tobedeleteset := existing.Difference( updates );
|
|
// Traverse the set of RecipeIngredient to be deleted
|
// Only delete RecipeIngredient that is not manually configured or the imported instance should overwrite manual configuration
|
traverse( tobedeleteset, Elements, ele,
|
not ele.IsManuallyConfigured() or isoverwitemanualconfig )
|
{
|
ele.Delete();
|
}
|
*]
|
}
|