Tuesday, March 13, 2018

Creating work order through code


SalesLine                       salesLineLocal;
    InventMovement                  inventMovement;
    WMSOrder                        wmsOrder;
    WMSOrderCreate                  orderCreate;
    WMSOrderTrans                   wmsOrderTrans;
    SalesTable                      salesTableLocal;
    WMSShipment                     wmsShipment;
    WMSPickingRoute                 wmsPickingRoute;
    WMSPickingRouteLink          wmsPickingRouteLink;
 
    salesTableLocal = SalesTable::find('SO-101328');
    wmsShipment.clear();
    wmsPickingRoute.clear();
    wmsShipment.initTypeOrderPick();
    wmsShipment.insert();
    wmsPickingRoute.initTypeOrderPick(wmsShipment, wmsExpeditionStatus::Activated,wmsPickRequestTable::construct(salesTableLocal), '', true);
    wmsPickingRoute.ActivationDateTime = DateTimeUtil::utcNow();
    wmsPickingRoute.insert();
    wmsPickingRouteLink.initFromSalesTable(salesTableLocal);
    wmsPickingRouteLink.initFromWMSPickingRoute(wmsPickingRoute);
    wmsPickingRouteLink.insert();

    // Creating records for each salesline

    while select salesLineLocal where salesLineLocal.SalesId == salesTableLocal.SalesId
    {
        // Inventory Movement object is required to create new           SalesPickingList lines
        inventMovement = InventMovement::construct(salesLineLocal);
        orderCreate = WMSOrderCreate::newMovement(inventMovement, 3);
        orderCreate.parmMustBeWMSOrderControlled(true);
        orderCreate.parmQty(3);
        orderCreate.parmRecalculateMaxQtyForValidation(false);
        orderCreate.parmMaxCWQty(3);
        orderCreate.parmMaxQty(3);
        orderCreate.run();
        wmsOrder = orderCreate.parmWMSOrder();
        wmsOrder.updateShipment(wmsShipment, 3, wmsPickingRoute.PickingRouteID, false);
        // Updating status to activated
        while select forupdate wmsOrderTrans
            where wmsOrderTrans.inventTransId ==  salesLineLocal.inventTransId
               && wmsOrderTrans.expeditionStatus == WMSExpeditionStatus::Registered
        {
            ttsBegin;
            wmsOrderTrans.expeditionStatus = WMSExpeditionStatus::Activated;
            wmsOrderTrans.update();
            ttsCommit;

        }

    }

No comments:

Post a Comment