haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
Quintiq file version 2.0
#parent: #root
Method MergeSalesDemands (
  LibOpt_Scope scope,
  ProductInStockingPointInPeriodPlannings pispipsinrun
)
{
  TextBody:
  [*
    pispipsforoptimization := selectset( pispipsinrun, Elements.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispip, true );
    bsdips := ProductInStockingPointInPeriodPlanningLeaf::GetPostponedSalesDemandForMerge( pispipsforoptimization, false ); // Merge only optimizer postponed sales demands. No un-merging if optimizer fails
    //Propagate quantity after merging sales demand
    traverse( bsdips, Elements, postponedsd ) 
    {
      pispip := postponedsd.ProductInStockingPointInPeriodPlanning();
      // only deleted postponed sd if both the pispip and the pispip of the original sales demand are in scope. If the original sd is not in scope the postponed sd is kept as is (no replan).  
      if ( scope.Contains( pispip.PISPIPInOptimizerRun() )
           and scope.Contains( postponedsd.OriginalSalesDemand().ProductInStockingPointInPeriodPlanning().PISPIPInOptimizerRun() ) )
      {
        postponedsd.Delete(); 
      }
    }
    
    // Merge sales demands from before the horizon
    traverse( scope.GetSDIPBeforeScopeInRun(), Elements.astype( LeafSalesDemandInPeriod ), lsdip )
    {
      traverse( lsdip, PostponedSalesDemand, postponedsd,
                not postponedsd.IsManuallyPostponed()
                and scope.Contains( postponedsd.ProductInStockingPointInPeriodPlanning().PISPIPInOptimizerRun() ) )
      {
        postponedsd.Delete();
      }
    }
    
    traverse( scope.GetSDIPBeforeScopeInRun(), Elements.astype( AggregatedSalesDemandInPeriod ), asdip )
    {
      traverse( asdip, DisaggregatedSalesDemandInPeriod.PostponedSalesDemand, postponedsd,
                not postponedsd.IsManuallyPostponed()
                and scope.Contains( postponedsd.ProductInStockingPointInPeriodPlanning().PISPIPInOptimizerRun() ) )
      {
        postponedsd.Delete();
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}