chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
Quintiq file version 2.0
#parent: #root
Method GetHasValidConversionToBaseUOM (
  output Strings feedback_o,
  output Strings sanitycheckfb_o
) declarative remote as Boolean
{
  Description: 'Returns true if this unit of measure has at least one conversion factor to every other unit of measures.'
  TextBody:
  [*
    isvalid := true;
    
    // Only check conversion from other uoms to default UOM is enough.
    // Meaning we don't check conversion from default UOM to other uoms
    // as well as other uoms to other uoms
    
    if( not this.IsDefault() and not isnull( this.MacroPlan().DefaultUnitOfMeasure() ) )
    {
      defaultuom := this.MacroPlan().DefaultUnitOfMeasure();
      
      cf := select( this, AsSourceUnitOfMeasure, cf,
                    cf.TargetUnitOfMeasure() = defaultuom );
                    
      isvalid := guard( cf.GetIsEnabled(), false );
                   
      if( not isnull( feedback_o ) and not isvalid )
      {
        instance := UnitOfMeasure_MP::GetInstanceText( this.Name() );
        message := Translations::MP_UnitOfMeasure_ViolateHasValidConversionToBaseUOM( defaultuom.Name() );
        feedback_o.Add( SanityCheckMessage::GetFormattedMessage( instance, message ) );
        sanitycheckfb_o.Add( SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning() );
      } 
    }
    
    return isvalid;
  *]
}