yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Quintiq file version 2.0
#parent: #root
Method GetHasValidConversionFactorInUse (
  output Strings feedback_o,
  output Strings sanitycheckfeedback_o
) declarative remote as Boolean
{
  Description: 'Check if the unit of measure is in use and have conversion factor defined.'
  TextBody:
  [*
    // Check if the unit of measure is in use and have conversion factor defined
    isvalid := true;
    
    // Check whether the UnitOfMeasure has valid conversion factor only if it is in use
    if( this.IsInUse() )
    {
      feedback := '';
      // Select the invalid process IO
      invalidpio := select( this, AsPISPUnitOfMeasurement, pio, not pio.HasValidConversionFactor() );
    
      isvalid := isnull( invalidpio );
    
      // Check if any invalid process IO is found
      // Invalid process IO found
      if( not isvalid )
      {
        // Generate feedback text with the invalid process IO found
        entityname := invalidpio.DefinitionName() + ' ' + invalidpio.GetProcessName();
        spuomname := MacroPlan::GetSubstituteName( guard( invalidpio.PISPUnitOfMeasurement().Name(), '' ) );
        unitoumname := MacroPlan::GetSubstituteName( guard( invalidpio.UnitUnitOfMeasurement().Name(), '' ) );
    
        feedback := Translations::MP_UnitOfMeasure_ViolateHasValidConversionFactorInUse( spuomname,
                                                                                         unitoumname,
                                                                                         entityname );
        sanitycheckfeedback_o.Add( SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning() );
      }
      // No invalid process IO found
      else
      {
        // Select the invalid sales demand
        invalidsd := select( this, SalesDemand, sd, not sd.HasValidConversionFactor() );
    
        isvalid := isnull( invalidsd );
    
        // Check if any invalid sales demand is found
        if( not isvalid )
        {
          // Generate feedback text with the invalid sales demand found
          entityname := Translations::MP_SalesDemand_Instance( invalidsd.ProductInStockingPoint_MP().Name(),
                                                               guard( invalidsd.SalesSegment_MP().Name(), "" ),
                                                               invalidsd.StartDate(),
                                                               invalidsd.EndDate(),
                                                               invalidsd.GetTypeName() );
    
          sduomname := MacroPlan::GetSubstituteName( guard( invalidsd.UnitOfMeasure_MP().Name(), '' ) );
          uompispname := MacroPlan::GetSubstituteName( guard( invalidsd.ProductInStockingPoint_MP().UnitOfMeasure_MP().Name(), '' ) );
    
          feedback := Translations::MP_UnitOfMeasure_ViolateHasValidConversionFactorInUse( sduomname,
                                                                                           uompispname,
                                                                                           entityname );
          sanitycheckfeedback_o.Add( SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning() );
        }
      }
    
      // Add instance text if any of the preconditions above are violated
      if( not isnull( feedback_o ) and not isvalid )
      {
        instance := UnitOfMeasure_MP::GetInstanceText( this.Name() );
        feedback_o.Add( SanityCheckMessage::GetFormattedMessage( instance, feedback ) );
      }
    }
    
    return isvalid;
  *]
}