yanyuan
2023-08-30 eb958a9c253061d89ea524fe124b326369678557
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
Quintiq file version 2.0
#parent: #root
StaticMethod CreateOrUpdate (
  MacroPlan macroPlan,
  String id,
  String productId,
  String stockingPointId,
  String accountName,
  String costDriver,
  Date start,
  Real cost
) as InventoryValueAndCost
{
  TextBody:
  [*
    // yypsybs Aug-16-2023 (created)
    if( accountName = '' ) {
        accountName := 'Inventory holding cost';
    }
    if( costDriver = '' ) {
        costDriver := 'Inventory holding';
    }
    product := Product_MP::FindById( macroPlan, productId );
    stockingPoint := StockingPoint_MP::FindById( macroPlan, stockingPointId );
    account := Account_MP::FindByName( macroPlan, accountName );
    if( isnull( product ) ) {
        error( "product not found" );  
    }
    if( isnull( stockingPoint ) ) {
        error( "stocking point not found" );  
    }
    if( isnull( account ) ) {
        error( "account not found" );  
    }
    result := InventoryValueAndCost::FindById( macroPlan, id );
    if( isnull( result ) ) {
        result := InventoryValueAndCost::Create( id, product, stockingPoint, account, costDriver, start, cost, true ).astype( InventoryValueAndCost );
    } else if( result.ProductID() <> productId ) {
        error( "cannot change product of inventory value and cost" )
    } else {
        result.Update( account, costDriver, start, account.DefaultTimeUnit(), account.DefaultLengthOfTime(), cost, true );
    }
    return result;
  *]
}