lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
Quintiq file version 2.0
#parent: #root
Method ConvertInventorySpecificationToSafetyStocks
{
  TextBody:
  [*
    updates := construct( InventorySpecifications );
    
    // Always create safety stock regardless if target = 0
    traverse( this, Product_MP.InventorySpecification, inv )
    {
      safetystock := SafetyStock::FindTypeIndexSafetyStock( inv.ProductID(), inv.StockingPointID(), inv.Start() );
      if( isnull( safetystock) )
      {
        product := Product_MP::FindProductTypeIndex( inv.ProductID() );
        stockingpoint := StockingPoint_MP::FindStockingPointTypeIndex( inv.StockingPointID() );
        if ( not isnull( product ) and not isnull( stockingpoint ) )
        {
          SafetyStock::Create( product,
                               stockingpoint,
                               inv.Start(),
                               inv.HasTargetInDays_DELETED_Nov19(),
                               inv.TargetInDays_DELETED_Nov19(),
                               inv.TargetInQuantity_DELETED_Nov19(),
                               inv.IsCalculated(),
                               not inv.IsCalculated(),
                               not inv.IsManuallyConfigured() );
          
          updates.Add( inv );
        }                       
      }
      
      // Delete inventory spec thas has no min and no max levels defined
      // If max level checked and value 0, respect user decision and don't remove 
      traverse( updates, Elements, in, not in.HasMinLevel() and not in.HasMaxLevel() ) 
      {
        in.Delete();
      }
    }
  *]
}