Quintiq file version 2.0
#parent: #root
Method New (
  internal[GUIComponent] parent,
  ProductInStockingPoint_MP pisp
) as SafetyStock id:Method_DialogCreateEditSafetyStock_New
{
  #keys: '[136682.2.182627980]'
  Body:
  [*
    //Create new SafetyStock
    Dialog.EnableBatchEditComponents( false );
    Dialog.ShowHideComponent( false );
    
    
    stockingpoint := guard( pisp.StockingPoint_MP(), null( StockingPoint_MP ) );
    owner := guard( pisp.Product_MP(), InventorySpecification::GetDefaultOwner( MacroPlan, stockingpoint ) );
    start := MacroPlan.StartOfPlanning().Date(); 
    
    data := owner.SafetyStock( relshadow,
                               ProductID := owner.ID(),
                               StockingPointID := guard(stockingpoint.ID(),""),
                               Start := start, HasUserTarget := true);
                               
    data.StockingPoint_MP( relset, stockingpoint );
    
    
    Dialog.Data( data );
    
    result := Dialog.DoModal( parent );
    newobj := null( SafetyStock );
    
    if( result > 0 )
    {           
     
      SafetyStock::Create(  data.Product_MP(),
                            data.StockingPoint_MP(),
                            data.Start(),
                            data.HasTargetInDays(), 
                            data.UserTargetInDays(),  
                            data.UserTargetInQuantity(),// Does not have a target in days, the initial targets are 0
                            false, 
                            data.HasUserTarget(), false );     
    
    }
    
    return newobj;
  *]
}
