| Quintiq file version 2.0 | 
| #parent: #root | 
| Method MPSyncBaseConversionFactor ( | 
|   Boolean isoverwritemanualconfig, | 
|   IOBaseConversionFactors iobaseconversionfactors | 
| ) | 
| { | 
|   Description: 'Synchronization of BaseConversionFactor for MPSync' | 
|   TextBody: | 
|   [* | 
|     // Select a set of existing BaseConversionFactor | 
|     existing := selectset( this, UnitOfMeasure_MP.BaseConversionFactor, item, true ); | 
|     updates := construct( BaseConversionFactors ); | 
|      | 
|     // Traverse the new set of valid BaseConversionFactor | 
|     traverse( iobaseconversionfactors, Elements, io, io.IsValid() ) | 
|     { | 
|       sourceuom := this.FindUnitOfMeasure( io.SourceUnitOfMeasureName() ); | 
|       targetuom := this.FindUnitOfMeasure( io.TargetUnitOfMeasureName() ); | 
|       product := this.FindProduct( io.ProductID() ); | 
|        | 
|       // Find existing BaseConversionFactor | 
|       objectinstance := BaseConversionFactor::FindBaseConversionFactorTypeIndex( io.SourceUnitOfMeasureName(),  | 
|                                                                                  io.TargetUnitOfMeasureName(), | 
|                                                                                  io.ProductID() ); | 
|        | 
|       // If no existing BaseConversionFactor is found, and both source and target unit of measure is found, create one | 
|       if( isnull( objectinstance ) ) | 
|       { | 
|         if( not ( isnull( targetuom ) or isnull( sourceuom ) ) ) | 
|         { | 
|           objectinstance := BaseConversionFactor::Create( sourceuom, targetuom, io.UserFactor(), io.ProductID(), io.IsEnabled(), true ).astype( BaseConversionFactor ); | 
|         } | 
|       } | 
|       // Else if the BaseConversionFactor is not manually configured or the imported instance should overwrite manual configuration, | 
|       // update the existing BaseConversionFactor | 
|       else if( not objectinstance.IsManuallyConfigured() or isoverwritemanualconfig ) | 
|       { | 
|         // Update BaseConversionFactor | 
|         if( not isnull( targetuom ) ){ | 
|           objectinstance.Update( io.UserFactor(), | 
|                                  targetuom, | 
|                                  product, | 
|                                  io.IsEnabled(), | 
|                                  true ); | 
|           updates.Add( objectinstance ); | 
|         }  | 
|       } | 
|        | 
|       if ( not isnull( objectinstance ) ) | 
|       { | 
|         objectinstance.CustomUpdate( io, isoverwritemanualconfig ); | 
|       }  | 
|     } | 
|      | 
|     // Get the set of old BaseConversionFactor to be deleted | 
|     tobedeleteset := existing.Difference( updates ); | 
|      | 
|     // Traverse the set of BaseConversionFactor to be deleted | 
|     // Only delete BaseConversionFactor that is not manually configured or the imported instance should overwrite manual configuration | 
|     traverse( tobedeleteset, Elements, ele, | 
|               not ele.IsManuallyConfigured() or isoverwritemanualconfig ) | 
|     { | 
|       ele.Delete(); | 
|     } | 
|   *] | 
| } |