Wednesday, November 27, 2013

Changing remaining quantity on sales line (intercompany)

While investigating intercompany processes in AX2012 I've found an interesting thing.

Let's assume the scenario from my previous post: an intercompany direct delivery.
Out supply chain looks like this:
SO 101 -> PO 2012 -> SO 102, where 101 and 102 are company names, SO stands for "Sales order" and PO for "Purchase order".

If you're trying to manipulate delivery remainder from the code (not changing the ordered quantity), you would do the following:

    SalesLine    salesLine102;
    SalesQty     qtyDifference;
    InvetnQty    qtyDifferenceInvent;
    //select sales line
    //...
    qtyDifferenceInvent               =
       salesLine102.unitConvertSales2Invent(qtyDifference);
    salesLine102.RemainSalesPhysical -= qtyDifference;
    salesLine102.RemainInventPhysical-= qtyDifferenceInvent;                
      
    salesLine102.update();



The logic behind an update method should update the whole chain of order lines (PO102 and than SO101). However it won't happen!

The right code is placed into the form "Update delivery remainder", which can be called from the order line:


\Forms\SalesUpdateRemain\Methods\closeOk

The right code should be placed before calling update on sales order line buffer:

    

    InterCompanyUpdateRemPhys::synchronize(saleLine102,
                                           qtyDifferenceInvent,
                                           qtyDifference);



Hope it helps you in customizing AX!