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
42
43
44
45
46
47
48
49
Quintiq file version 2.0
#parent: #root
StaticMethod LinkOperation (
  OperationOutput sourceoperationoutput,
  Operation destinationoperation,
  output BaseOperationLinks trash
) as OperationLink
{
  Description: 'Add given operation outputs as souce operation.'
  TextBody:
  [*
    // DWE2 Feb-1-2016 (created)
    
    ol := null( OperationLink );
    targetoperationlink := OperationLink::FindOperationLinkTypeIndex( sourceoperationoutput.Operation().ID(), destinationoperation.ID() );
    
    // Case of moving an OO to Operation that already have the OO linked
    // E.g O1 have 2 OO (OO1, OO2) linked to O2 and O3, when user drag OO1 to O3, we will then link OO1 to O3 and remove OO2
    if( not isnull( targetoperationlink )
        and not exists( destinationoperation, OperationInput.BaseOperationLink.OperationOutput, oo,
                        oo = sourceoperationoutput ) )
    {
      ol := OperationLink::RecreateWithDifferentGroup( sourceoperationoutput.OperationLinkGroupID(),
                                                       targetoperationlink.DestGroupID(),
                                                       targetoperationlink );
    }
    else
    {
      defaultqty := sourceoperationoutput.MacroPlan().GlobalParameters_MP().DefaultOperationInputOutputQuantity();
    
      sourcegroupid := sourceoperationoutput.OperationLinkGroupID();
      destinationgroupid := OperationLink::GetDestinationGroupID( sourceoperationoutput.Operation(), destinationoperation );
    
      ol := OperationLink::CreateOrDelete( sourceoperationoutput.Operation(),
                                           destinationoperation,
                                           trash,
                                           sourcegroupid,
                                           destinationgroupid,
                                           sourceoperationoutput.Quantity(), // Source quantity
                                           false,
                                           defaultqty, // destination quantity
                                           defaultqty, // destiantion min quantity
                                           defaultqty, // destination max quantity
                                           defaultqty ); // destination group quantity
    }
    
    return ol;
  *]
}