yypsybs
2023-09-09 3cb5a54def670d97301f07170fcaad213bfc54f2
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Quintiq file version 2.0
#parent: #root
Method MPSyncOperationBOM (
  Boolean isoverwritemanualconfig,
  IOOperationBOMs iooperationboms
)
{
  Description: 'Synchronization of OperationBOM for MPSync'
  TextBody:
  [*
    // Select a set of existing OperationBOM
    existing := selectset( this, Unit.Operation.OperationBOM, item, true );
    updates := construct( OperationBOMs );
    
    // Traverse the new set of valid OperationBOM
    traverse( iooperationboms , Elements, io, io.IsValid() )
    {
      operationid := io.OperationID();
      productid := io.ProductID();
      spid := io.StockingPointID();
      isinput := io.IsInput();
      // Find existing OperationBOM
      objectinstance := OperationBOM::FindOperationBOMTypeIndex( operationid, productid, spid, isinput );
      // Find existing Operation
      operation := Operation::FindOperationTypeIndex( operationid );
      
      // If no existing OperationBOM is found, and there's valid Operation, create one
      if( isnull( objectinstance ) )
      {
        if( not ( isnull( operation ) ) )
        {
          objectinstance := OperationBOM::Create( operation,
                                                  productid,
                                                  spid,
                                                  isinput,
                                                  io.InputGroupID(),
                                                  true,
                                                  io.Quantity(),
                                                  io.MinQuantityInGroup(),
                                                  io.MaxQuantityInGroup(),
                                                  true,
                                                  io.IsExcluded());
        }
      }
      // Else if the OperationBOM is not manually configured or the imported instance should overwrite manual configuration,
      // update the existing OperationBOM
      else if( not objectinstance.IsManuallyConfigured() or isoverwritemanualconfig )
      {
        // Update OperationBOM
        if( not ( isnull( operation ) ) )
        {
          objectinstance.Update( operation, 
                                 productid, 
                                 spid, 
                                 io.IsInput(),
                                 io.InputGroupID(),
                                 true,
                                 io.Quantity(),
                                 io.MinQuantityInGroup(),
                                 io.MaxQuantityInGroup(),
                                 io.IsExcluded(),
                                 '' ,
                                 true );
          
          updates.Add( objectinstance );
        }
      }
      
      if( not isnull( objectinstance ) )
      {
        // Extended method
        objectinstance.CustomUpdate( io, isoverwritemanualconfig );   
      }
    }
    
    // Get the set of old OperationBOM to be deleted
    tobedeleteset := existing.Difference( updates );
    
    // Traverse the set of OperationBOM to be deleted
    // Only delete OperationBOM that is not manually configured or the imported instance should overwrite manual configuration
    traverse( tobedeleteset, Elements, ele,
              not ele.IsManuallyConfigured() or isoverwritemanualconfig )
    {
      ele.Delete();
    }
  *]
}