yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
MethodOverride SyncSubsetProduct (
  OptimizerPuzzleBase target
)
{
  TextBody:
  [*
    // Copy subset product from WIP to OP
    optimizerpuzzle := target.astype( OptimizerPuzzle );
    isfromdb := false;
    
    currentList := selectset( optimizerpuzzle, SubsetProductInOptimizerPuzzle, sub , true );
    newList := construct( SubsetProductInOptimizerPuzzles );
    
    // Copy or update isuserAction and GetIsSystem subsets
    // Not taking into consideration Product without Parent if Include because of default behaviour
    traverse( this, SubsetProductInOptimizerPuzzleWip, subsource, subsource.IsUserAction() )
    {
      targetSubset := SubsetProductInOptimizerPuzzle::FindSubsetProductOptimizerPuzzleTypeIndices( optimizerpuzzle.Name(), subsource.ProductID() );
      // Case create a new OptimizerPuzzle
      if( isnull( targetSubset ) )
      {
        // Create a SubsetProduct for OptimizerPuzzle. 
        targetSubset := SubsetProductInOptimizerPuzzle::Create( optimizerpuzzle, subsource.Product_MP(), isfromdb );
      }
      // Case edit
      else
      {
        if( targetSubset.OptimizerPuzzleName() <> this.Name() )
        {
          // Update OptimizerPuzzleID and ProductID
          SubsetProductInOptimizerPuzzle::ChangeKeySubsetProductOptimizerPuzzleTypeIndices( targetSubset, this.Name(), targetSubset.ProductID() );
        }
      }
      
      // Update IsInclude and IsUserAction
      targetSubset.IsIncluded( subsource.IsIncluded() );
      targetSubset.IsUserAction( subsource.IsUserAction() );
      newList.Add( targetSubset );
    }
    
    toBeDeleted := currentList.Difference( newList ); 
    SubsetProductInOptimizerPuzzle::Delete( toBeDeleted );
  *]
}