Brian Stevens
Brian Stevens

Reputation: 1941

How do I add the Inventory Availability Status to Custom Grid like SO301000

We are adding a custom screen that utilizes Site ID and Inventory ID in the row of the defined grid on the page. We would like to add the Inventory Availability details as shown on SO301000 (Sales Order Entry graph).

A) How do I access the status area of the grid to place text. B) Is there a standard method that I can access for the text used on SO301000.

Upvotes: 0

Views: 584

Answers (1)

Hugues Beauséjour
Hugues Beauséjour

Reputation: 8268

The feature is called StatusField.

You define the status field on the grid ASPX control:

<px:PXGrid ID="grid" runat="server" DataSourceID="ds" StatusField="Availability">

It can be set with a FieldSelecting event:

public void SOLine_Availability_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)

Sales order screen lumps it with the allocation custom data view which makes it hard to re-use:

public LSSOLine lsselect;

In LSSOLine class you'll find the Availability_FieldSelecting method that computes the value:

public override void Availability_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
    var fetchMode = ((SOLine) e.Row)?.Completed == true
        ? AvailabilityFetchMode.None
        : AvailabilityFetchMode.ExcludeCurrent;
    IQtyAllocated availability = AvailabilityFetch(sender, (SOLine)e.Row, fetchMode | AvailabilityFetchMode.TryOptimize);

    if (availability != null)
    {
        PXResult<InventoryItem, INLotSerClass> item = ReadInventoryItem(sender, ((SOLine)e.Row).InventoryID);

        decimal unitRate = INUnitAttribute.ConvertFromBase<SOLine.inventoryID, SOLine.uOM>(sender, e.Row, 1m, INPrecision.NOROUND);
        availability.QtyOnHand = PXDBQuantityAttribute.Round((decimal)availability.QtyOnHand * unitRate);
        availability.QtyAvail = PXDBQuantityAttribute.Round((decimal)availability.QtyAvail * unitRate);
        availability.QtyNotAvail = PXDBQuantityAttribute.Round((decimal)availability.QtyNotAvail * unitRate);
        availability.QtyHardAvail = PXDBQuantityAttribute.Round((decimal)availability.QtyHardAvail * unitRate);

        if(IsAllocationEntryEnabled)
        {
            Decimal? allocated = PXDBQuantityAttribute.Round((decimal)(((SOLine)e.Row).LineQtyHardAvail ?? 0m) * unitRate); ;
            e.ReturnValue = PXMessages.LocalizeFormatNoPrefix(Messages.Availability_AllocatedInfo,
                    sender.GetValue<SOLine.uOM>(e.Row), FormatQty(availability.QtyOnHand), FormatQty(availability.QtyAvail), FormatQty(availability.QtyHardAvail), FormatQty(allocated));
        }
        else
            e.ReturnValue = PXMessages.LocalizeFormatNoPrefix(Messages.Availability_Info,
                    sender.GetValue<SOLine.uOM>(e.Row), FormatQty(availability.QtyOnHand), FormatQty(availability.QtyAvail), FormatQty(availability.QtyHardAvail));


        AvailabilityCheck(sender, (SOLine)e.Row, availability);
    }
    else
    {
        //handle missing UOM
        INUnitAttribute.ConvertFromBase<SOLine.inventoryID, SOLine.uOM>(sender, e.Row, 0m, INPrecision.QUANTITY);
        e.ReturnValue = string.Empty;
    }

    base.Availability_FieldSelecting(sender, e);
}

I would advise to skip using LSSOLine and just copy it's FieldSelecting method.

That approach is documented in more detail in this other answer: https://stackoverflow.com/a/45034612/7376238

Upvotes: 1

Related Questions