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(); 
 | 
    } 
 | 
  *] 
 | 
} 
 |