| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod GetConversionFactor ( | 
|   const UnitOfMeasure_MP sourceuom, | 
|   const UnitOfMeasure_MP targetuom, | 
|   const Product_MP product | 
| ) const declarative remote as Real | 
| { | 
|   Description: 'Return the conversion factor object from source to target' | 
|   TextBody: | 
|   [* | 
|     //This method returns NAN if conversion factor is not found.  | 
|     //Therefore, it should only be used to check whether the conversion factor exists or not. | 
|     //Should not be used for retrieving the factor value. For that we should always use uom.GetConversionFactor() | 
|      | 
|     factor := log( -1.0 ); | 
|      | 
|     if( not isnull( sourceuom ) ) | 
|     { | 
|       // If the product has conversion factor, traverse from product | 
|       conversionfactor := constnull( ConversionFactor ); | 
|        | 
|       if( not isnull( product ) | 
|           and product.HasConversionFactor() ) | 
|       { | 
|         conversionfactor := select( product, ConversionFactor, cf, | 
|                                     cf.SourceUnitOfMeasure() = sourceuom, | 
|                                     cf.TargetUnitOfMeasure() = targetuom ); | 
|       } | 
|       // Else go for source -> target without product specified | 
|       // Do not use else because some product may have HasConversionFactor = true but the specific conversion factor is not specified. | 
|       // In that case, we will use the conversion factor without product | 
|        | 
|       if( isnull( conversionfactor ) ) | 
|       { | 
|         conversionfactor := select( sourceuom, AsSourceUnitOfMeasureWithNullProduct, cf, true, cf.TargetUnitOfMeasure() = targetuom ); | 
|       } | 
|       factor := guard( conversionfactor.Factor(), log( -1.0 ) ) | 
|        | 
|       // Chain conversion factor because in web, we may only have conversion factors between default uom and each uom | 
|       if( isnull( conversionfactor ) ) | 
|       { | 
|         defaultUOM := sourceuom.MacroPlan().DefaultUnitOfMeasure(); | 
|         converttodefaultfactor := select( sourceuom, AsSourceUnitOfMeasureWithNullProduct, cf, true, cf.TargetUnitOfMeasure() = defaultUOM ); | 
|         defaulttotargetfactor := select( defaultUOM, AsSourceUnitOfMeasureWithNullProduct, cf, true, cf.TargetUnitOfMeasure() = targetuom ); | 
|         factor := guard( converttodefaultfactor.Factor() * defaulttotargetfactor.Factor(), log( -1.0 ) ); | 
|       } | 
|     } | 
|      | 
|     return factor; | 
|   *] | 
| } |