yanweiyuan3
2023-10-10 d901b1ab0ee0b690f5ac211b9cdb1db3a58bca86
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
Quintiq file version 2.0
#parent: #root
Method MappingOperationBOMDataSupplyPurchase (
  String orgCode,
  String productId,
  String productType
)
{
  TextBody:
  [*
    
    product := Product_MP::FindById( this, productId );
    if( isnull( product ) ) {
        info(  "product : " + productId + " not found" );
    }
    stockingPointId := orgCode + "_Stock";
    stockingPoint := StockingPoint_MP::FindById( this, stockingPointId );
    if( isnull( stockingPoint ) ) {
        info( "stockingPoint : " + stockingPointId + " not found" );
    }
    
    if( not isnull( product) and not isnull( stockingPoint)){
      routingId := "PR_"+orgCode + "_" + productId;
      unitId := "供应商";
      routingStepName := "Purchase";
      operationId := orgCode + "_PR_" + productId;
      routing := Routing::CreateOrUpdate( this, routingId );
      toDeleteSteps := selectset( routing, RoutingStep, routingStep, true );
      RoutingStep::Delete( toDeleteSteps );
      routingStep := RoutingStep::Create( routing, routingStepName, "", true );
      unit := Unit::FindById( this, unitId );
      if( isnull( unit ) ) {
        unit := this.Unit( relnew, 
                          ID := unitId, Name := unitId, CapacityType := "Infinite",
                          DefaultGridX := 0, DefaultGridY := 0,
                          IsManuallyConfigured := false,
                          Currency_MP := this.BaseCurrency(), UnitOfMeasure_MP := this.DefaultUnitOfMeasure() );
      }
    // Operation
      operation := Operation::FindOperationTypeIndex( operationId);
      if( isnull( operation)){
        operation := Operation::Create( operationId, unit, operationId, routingStep, 
                                    Duration::Zero(), Duration::Zero(), 1.0, false, 
                                    Real::MinReal(), false, Real::MaxReal(), 
                                    0.0, 0.0, false, true );
    // OperaionBom
        operation.CreateOperationBOM( product, stockingPoint, false, true );
        operation.GetOperationBOM( product.ID(), stockingPoint.ID(), false ).Quantity( 1 );
      }
      
    }
  *]
}