limj
2023-10-24 93652435728de839582440eefd5122c281181d35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Quintiq file version 2.0
#parent: #root
Method MPSyncRecipeWithEffectiveDate (
  Boolean isoverwitemanualconfig,
  IORecipeWithEffectiveDates iorecipewitheffectivedates
)
{
  Description: 'Synchronization of RecipeWithEffectiveDate for MPSync'
  TextBody:
  [*
    // Select a set of existing RecipeWithEffectiveDate
    existing := selectset( this, Product_MP.RecipeWithEffectiveDate, item, true );
    updates := construct( RecipeWithEffectiveDates );
    
    // Traverse the new set of valid RecipeWithEffectiveDate
    traverse( iorecipewitheffectivedates , Elements, io, io.IsValid() )
    {
      // Find existing RecipeWithEffectiveDate
      objectinstance := RecipeWithEffectiveDate::FindRecipeWithEffectiveDateInProductTypeIndex( io.ProductID(), io.RecipeName(), io.EffectiveDate() );
      // Find existing Product_MP
      product := Product_MP::FindProductTypeIndex( io.ProductID() );
      
      // If no existing RecipeWithEffectiveDate is found, and there's valid Product_MP, create one
      if( not isnull( product ) )
      {
        if( isnull( objectinstance ) )
        {
          objectinstance := RecipeWithEffectiveDate::Create( product,
                                                             io.RecipeName(),
                                                             io.EffectiveDate(),
                                                             true );                                              
        }
        // Else if the RecipeWithEffectiveDate is not manually configured or the imported instance should overwrite manual configuration,
        // update the existing RecipeWithEffectiveDate
        else if( not objectinstance.IsManuallyConfigured() or isoverwitemanualconfig )
        {
          // Update RecipeWithEffectiveDate
          objectinstance.Update( product,
                                 io.RecipeName(),
                                 io.EffectiveDate(),
                                 true );
    
          updates.Add( objectinstance );
        }
        
        if( not isnull( objectinstance ) )
        {
          // Extended method
          objectinstance.CustomUpdate( io, isoverwitemanualconfig );
        }
      }
    }
    
    // Get the set of old RecipeWithEffectiveDate to be deleted
    tobedeleteset := existing.Difference( updates );
    
    // Traverse the set of RecipeWithEffectiveDate to be deleted
    // Only delete RecipeWithEffectiveDate that is not manually configured or the imported instance should overwrite manual configuration
    traverse( tobedeleteset, Elements, ele,
              not ele.IsManuallyConfigured() or isoverwitemanualconfig )
    {
      ele.Delete();
    }
  *]
}