Sunday, May 25, 2014

Creating new Sales Pickinglist X++

On recent project, customer put up a requirement which was pretty unusual among common scenarios of sales picking. Customer wants a new sales pickinglist on cancellation of items on a single picking route. 
In order to achieve this functionality let have a look on the tables involved in maintaining data of sales pickinglist. 

  • WMSShipment 
  • WMSPickingRoute
  • WMSPickingRouteLink
  • WMSOrder
  • WMSOrderTrans

WMSShipment 

The WMSShipment table contains information about shipments.

WMSPickingRoute

The WMSPickingRoute table contains information about picking routes. The picking routes are used by the warehouse management system to control the picking process.


WMSPickingRouteLink

The WMSPickingRouteLink table contains information about which sales orders and which picking routes are related.


WMSOrder

The WMSOrder table contains information about orders that are handled by the warehouse management system.


WMSOrderTrans

The WMSOrderTrans table contains information about order lines and items that are handled by the warehouse management system. This table is used for item picking, shipping, and pallet transportation.


X++ Code

To begin with the functionality, I have the following assumption that Sales Order already has Pickinglist Journal posted.



Step 1

Create WMSShipment record.


        WMSShipment                     wmsShipment;
    SalesTable                      salesTableLocal;

    salesTableLocal = SalesTable::find('SO-101328');

    wmsShipment.clear();

    wmsShipment.initTypeOrderPick();
    wmsShipment.insert();


Step 2

Create WMSPickingRoute record.

    WMSPickingRoute                 wmsPickingRoute;

    wmsPickingRoute.clear();
    wmsPickingRoute.initTypeOrderPick(wmsShipment,
                                 WMSExpeditionStatus::Activated,                  WMSPickRequestTable::construct(salesTableLocal),
                                                      '', true);
    wmsPickingRoute.ActivationDateTime = DateTimeUtil::utcNow();
    wmsPickingRoute.insert();


Step 3

Create WMSPickingRouteLink record.

    WMSPickingRouteLink          wmsPickingRouteLink;

    wmsPickingRouteLink.initFromSalesTable(salesTableLocal);
    wmsPickingRouteLink.initFromWMSPickingRoute(wmsPickingRoute);
    wmsPickingRouteLink.insert();


Step 4

Create SalesPickingList line using WMSOrderCreate class.

    SalesLine                       salesLineLocal;
    InventMovement                  inventMovement;
    WMSOrder                        wmsOrder;
    WMSOrderCreate                  orderCreate;
    WMSOrderTrans                   wmsOrderTrans;
// 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,                                                      -cancelQty);
        orderCreate.parmMustBeWMSOrderControlled(true);
        orderCreate.parmQty(cancelQty);
        orderCreate.parmRecalculateMaxQtyForValidation(false);
        orderCreate.parmMaxCWQty(cancelQty);
        orderCreate.parmMaxQty(cancelQty);
        orderCreate.run();
        wmsOrder = orderCreate.parmWMSOrder();
        wmsOrder.updateShipment(wmsShipment, cancelQty,                                     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;
        }
    }


Result

After code execution


No comments:

Post a Comment