hongji.li
2023-11-03 aefafd2142478d4fb07d6b8b45c3047e247389e0
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
76
77
78
79
80
81
82
83
84
85
Quintiq file version 2.0
#parent: #root
Method Copy (
  SupplyChainView supplychainview,
  Unit parent
) as Unit
{
  Description: 'Copy a unit'
  TextBody:
  [*
    // Copy unit
    unitNode := select( this, UnitNode, un, un.ViewBase() = supplychainview );
    unitname := this.GetNewCopiedUnitName();
    unitid := unitname; // Use copied name as ID during copy
    
    newunit := null( Unit );
    
    newunit := Unit::Create( unitid,
                             this.MacroPlan(),
                             unitname,
                             parent,
                             this.CapacityType(),
                             this.Group(),
                             this.UnitOfMeasure_MP(),
                             this.Currency_MP(),
                             supplychainview,
                             unitNode.IsVisible(),
                             unitNode.GridX() + 3 ,
                             unitNode.GridY(),
                             this.StartDate(),
                             this.EndDate(),
                             this.CampaignTypeDuration(),
                             this.IsPlannedInfinite(),
                             this.MinimumQuantity(),
                             this.HasMaximumQuantity(),
                             this.MaximumQuantity(),
                             this.LotSize(),
                             this.IconName(),
                             '',
                             unitNode.NameDisplayBehavior(),
                             '',
                             this.QuantityToProcess(),
                             this.GISCountryCode(),
                             this.GISCity(),
                             this.GISPostalCode(),
                             this.Notes(),
                             this.HasCapacitySmoothing(),
                             this.IsSmoothCapacityOverAllPeriods(),
                             this.UserCapacitySmoothingLength(),
                             this.CapacitySmoothingPercentageDelta(),
                             this.IsOverlapCapacitySmoothing(),
                             this.IsIncludedInSupplySpecification(),
                             this.IsSupplier(),
                             this.HasUserFrozenFutureDuration(),
                             this.UserFrozenFutureDuration(),
                             this.UseShiftOptimization(),
                             false );
    
    //set relation to the source unit
    newunit.Original( relset, this );
    
    allchildrenunit := selectsortedset( this, Child, u, true, u.Level() );
    traverse( allchildrenunit, Elements, el )
    {
      el.Copy( supplychainview, newunit );
    
    }
    
    // Copy stockingpointunit
    traverse( this, StockingPointUnit, spu )
    {
      newunit.LinkToStockingPoint( spu.StockingPoint_MP(), spu.IsInput() );
    }
    
    // Copy assignments and costs
    // Copying unit will not copy the operation, lane, and lane leg.
    // Therefore, we should not copy the corresponding operation/lane/laneleg cost.
    traverse( this, UnitAccount, ua, AccountAssignment::IsForUnit( ua.CostDriver() ) )
    {
      ua.Copy( newunit );
    }
    
    return newunit;
  *]
}