Filter Inventory by cross reference

后端 未结 1 1180
情书的邮戳
情书的邮戳 2021-01-28 21:54

I want to customize the filtering of inventory by cross reference along with other properties.

I have added two other cross reference items for a stock item like this.

1条回答
  •  粉色の甜心
    2021-01-28 22:15

    There is no simple way to add search capabilities over Stock Item's Alternate IDs without a customization. Also, keep in mind that we are talking here about the one-to-many relationship between Stock Item and Alternate IDs, which makes it impossible to simply drop Alternate ID column into the Inventory ID selector as this will result in same Stock Item shown multiple times because of a necessary join with the Cross-Reference DAC.

    The first thing you need to do is create a database-bound field for the InventoryItem DAC (make sure you create UsrAlternateIDs column in the InventoryItem database) table to concatenate all Alternate IDs of a Stock Item (notice Visibility set to PXUIVisibility.SelectorVisible on PXUIField - this is required to show Alternate IDs column inside the Inventory ID selector):

    public class InventoryItemExt : PXCacheExtension
    {
        public abstract class usrAlternateIDs : IBqlField { }
        [PXDBString(4000, IsUnicode = true)]
        [PXUIField(DisplayName = "Alternate IDs", Visibility = PXUIVisibility.SelectorVisible)]
        public string UsrAlternateIDs { get; set; }
    }
    

    Next step is to override the Persist method in the InventoryItemMaint BLC extension to regenerate concatenated Alternate IDs every time the user makes changes in the Cross-Reference tab :

    public class InventoryItemMaint_Extension : PXGraphExtension
    {
        [PXOverride]
        public void Persist(Action del)
        {
            using (PXTransactionScope ts = new PXTransactionScope())
            {
                InventoryItem item = Base.Item.Current;
                if (item != null && Base.itemxrefrecords.Cache.IsDirty)
                {
                    string alternateIDs = string.Empty;
                    foreach (INItemXRef crossRef in Base.itemxrefrecords.Select())
                    {
                        alternateIDs = string.IsNullOrEmpty(alternateIDs) ?
                            crossRef.AlternateID : alternateIDs + "; " + crossRef.AlternateID;
                    }
                    item.GetExtension().UsrAlternateIDs = alternateIDs;
                    Base.Item.Update(item);
                }
    
                del();
                ts.Complete();
            }
        }
    }
    

    And finally, you should add UsrAlternateIDs in PXSelector FastFilterFields property:

    Once these 3 steps are completed, the final result should look as follows:

    To concatenate all currently existing Stock Item Alternative IDs in one step, you can implement a custom action on the Stock Items screen. You can remove the action after that.

    public class InventoryItemMaint_Extension : PXGraphExtension
    {
        ...
    
        public PXAction RecalcAlternateIDs;
        [PXButton]
        [PXUIField(DisplayName = "Concatenate Alternate IDs")]
        protected void recalcAlternateIDs()
        {
            PXLongOperation.StartOperation(Base, () =>
            {
                InventoryItemMaint itemMaint = PXGraph.CreateInstance();
                var items = PXSelect>>.Select(itemMaint);
                foreach (InventoryItem item in items)
                {
                    itemMaint.Clear();
                    itemMaint.Item.Current = item;
                    itemMaint.itemxrefrecords.Cache.IsDirty = true;
                    itemMaint.Actions.PressSave();
                }
            });
        }
    }
    

    0 讨论(0)
提交回复
热议问题