Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method MPSyncUnit ( 
 | 
  Boolean isoverwritemanualconfig, 
 | 
  IOUnits iounits 
 | 
) 
 | 
{ 
 | 
  Description: 'Synchronization of Unit for MPSync' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Select a set of existing Unit 
 | 
    existing := selectset( this, Unit, item, true ); 
 | 
    updates := construct( Units ); 
 | 
     
 | 
    // Traverse the new set of valid Unit 
 | 
    traverse( iounits , Elements, io, io.IsValid() ) 
 | 
    { 
 | 
      indexkey := io.ID(); 
 | 
      // Find existing Unit 
 | 
      objectinstance := Unit::FindUnitTypeIndex( indexkey ); 
 | 
      // Find existing UnitOfMeasure_MP 
 | 
      uom := UnitOfMeasure_MP::FindUnitOfMeasureTypeIndex( io.UnitOfMeasureName() ); 
 | 
      // Find existing Currency_MP 
 | 
      currency := Currency_MP::FindCurrencyTypeIndex( io.CurrencyID() ); 
 | 
       
 | 
      // If no existing Unit is found, create one 
 | 
      if( isnull( objectinstance ) ) 
 | 
      {  
 | 
        // Check if there's valid UnitOfMeasure_MP and Currency_MP 
 | 
        if( not ( isnull( uom ) or isnull( currency ) ) ) 
 | 
        { 
 | 
          objectinstance := Unit::Create( this, 
 | 
                                          io.ID(), 
 | 
                                          io.ParentUnitID(), 
 | 
                                          io.DisplayIndex(), 
 | 
                                          io.Name(), 
 | 
                                          io.QuantityToProcess(), 
 | 
                                          io.IconName(), 
 | 
                                          io.CapacityType(), 
 | 
                                          io.CurrencyID(), 
 | 
                                          io.StartDate(), 
 | 
                                          io.EndDate(), 
 | 
                                          io.IsPlannedInfinite(), 
 | 
                                          io.UnitOfMeasureName(), 
 | 
                                          io.GroupName(), 
 | 
                                          io.MinimumQuantity(), 
 | 
                                          io.MaximumQuantity(), 
 | 
                                          io.LotSize(), 
 | 
                                          io.GISCountryCode(), 
 | 
                                          io.GISCity(), 
 | 
                                          io.GISPostalCode(), 
 | 
                                          io.HasMaximumQuantity(), 
 | 
                                          io.HasCapacitySmoothing(), 
 | 
                                          io.UserCapacitySmoothingLength(), 
 | 
                                          io.CapacitySmoothingPercentageDelta(), 
 | 
                                          io.IsOverlapCapacitySmoothing(), 
 | 
                                          io.IsSmoothCapacityOverAllPeriods(), 
 | 
                                          io.Notes(), 
 | 
                                          io.CampaignTypeDuration(), 
 | 
                                          io.IsIncludedInSupplySpecification(), 
 | 
                                          io.IsSupplier(), 
 | 
                                          io.HasUserFrozenFutureDuration(), 
 | 
                                          io.UserFrozenFutureDuration(), 
 | 
                                          io.UseShiftOptimization(), 
 | 
                                          true ); 
 | 
        } 
 | 
      } 
 | 
      // Else if the Unit is not manually configured or the imported instance should overwrite manual configuration, 
 | 
      // update the existing Unit 
 | 
      else if( not objectinstance.IsManuallyConfigured() or isoverwritemanualconfig ) 
 | 
      { 
 | 
        // Check if there's valid UnitOfMeasure_MP and Currency_MP 
 | 
        if( not ( isnull( uom ) or isnull( currency ) ) ) 
 | 
        { 
 | 
          // Update Unit 
 | 
          objectinstance.Update( io.ID(), io.Name(), 
 | 
                                 Unit::FindUnitTypeIndex( io.ParentUnitID() ), io.CapacityType(),   
 | 
                                 Group::FindGroupTypeIndex( io.GroupName() ), 
 | 
                                 UnitOfMeasure_MP::FindUnitOfMeasureTypeIndex( io.UnitOfMeasureName() ), 
 | 
                                 Currency_MP::FindCurrencyTypeIndex( io.CurrencyID() ), 
 | 
                                 io.StartDate(), io.EndDate(), io.CampaignTypeDuration(),  
 | 
                                 io.IsPlannedInfinite(), io.MinimumQuantity(), io.HasMaximumQuantity(), io.MaximumQuantity(), 
 | 
                                 io.LotSize(), io.IconName(),  
 | 
                                 io.QuantityToProcess(),  
 | 
                                 io.GISCountryCode(), io.GISCity(), io.GISPostalCode(),  
 | 
                                 io.Notes(), io.HasCapacitySmoothing(), io.IsSmoothCapacityOverAllPeriods(), io.UserCapacitySmoothingLength(), 
 | 
                                 io.CapacitySmoothingPercentageDelta(),io.IsOverlapCapacitySmoothing(), io.IsIncludedInSupplySpecification(), io.IsSupplier(), 
 | 
                                 io.HasUserFrozenFutureDuration(),io.UserFrozenFutureDuration(), 
 | 
                                 io.UseShiftOptimization(), 
 | 
                                 true  ); 
 | 
                                  
 | 
          updates.Add( objectinstance ); 
 | 
        } 
 | 
         
 | 
        if( not isnull( objectinstance ) ) 
 | 
        { 
 | 
          objectinstance.CustomUpdate(io, isoverwritemanualconfig ); 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
     
 | 
    // Get the set of old Unit to be deleted 
 | 
    tobedeleteset := existing.Difference( updates ); 
 | 
     
 | 
    // Traverse the set of Unit to be deleted 
 | 
    // Only delete Unit that is not manually configured or the imported instance should overwrite manual configuration 
 | 
    traverse( tobedeleteset, Elements, ele, 
 | 
              not ele.IsManuallyConfigured() or isoverwritemanualconfig ) 
 | 
    { 
 | 
      ele.Delete(); 
 | 
    } 
 | 
  *] 
 | 
} 
 |