Add Attributes fields on Inventory Lookup

前端 未结 1 574
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 01:31

I want to add the attributes for my inventory lookup on Sales Order and Purchase Order, does anyone know how to? or any ideas?

相关标签:
1条回答
  • 2021-01-17 02:05

    Please refer below code example to include Attributes Columns in Selector and Grid Control utilizing out-of-box CRAttributesFieldAttribute.

    Declare a class PXAddAtttributeColumns inherited from CRAttributesFieldAttribute.

    public class PXAddAtttributeColumns : CRAttributesFieldAttribute
    {
        string[] _names;
        bool _IsForSelector;
    
        public PXAddAtttributeColumns(string[] names, Type entityType, Type entityIDField, Type classIDField, bool IsForSelector = true)
            : base(entityType, entityIDField, classIDField)
        {
            _names = names;
            _IsForSelector = IsForSelector;
        }
    
        public override void CacheAttached(PXCache sender)
        {
            this._IsActive = true;
            base.CacheAttached(sender);
        }
    
        protected override void AttributeFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, PXFieldState state, string attributeName, int idx)
        {
            if (_names.Any(attributeName.Equals))
            {
                //Out-of-box DisplayName is prefixed with "$Attributes$-" - if you need to take that off.
                state.DisplayName = (!String.IsNullOrEmpty(state.DisplayName)) ? (state.DisplayName.Replace("$Attributes$-", "")) : attributeName;
                state.Visible = true;
                //Requires AutoGenerateColumns="AppendDynamic" for PXGrid Control for dynamic Attribute columns creation
                state.Visibility = (_IsForSelector) ? PXUIVisibility.SelectorVisible : PXUIVisibility.Dynamic;
            }
            base.AttributeFieldSelecting(sender, e, state, attributeName, idx);
        }
    
        public override void CommandPreparing(PXCache sender, PXCommandPreparingEventArgs e)
        {
            base.CommandPreparing(sender, e);
    
            if (e.BqlTable == null && aggregateAttributes && sender.GetItemType().IsDefined(typeof(PXProjectionAttribute), true))
            {
                e.BqlTable = _BqlTable;
            }
        }
    }
    

    To include attributes as Columns in Inventory Look up, declare DAC Extension as below:

    public class InventoryItemPXExt : PXCacheExtension<PX.Objects.IN.InventoryItem>
    {
        #region Attributes
    
        public abstract class attributes : IBqlField { }
    
        [PXAddAtttributeColumns(new[] { "ASSETID", "HWMODEL" },
                typeof(CSAnswerType.inventoryAnswerType),
                typeof(InventoryItem.inventoryID),
                typeof(InventoryItem.itemClassID))]
        public virtual string[] Attributes { get; set; }
    
        #endregion
    }
    

    Fields will show up as below:

    Search can be Enabled on Attribute Columns by setting FilterByAllFields to True

    To include attributes as Columns in Sales Order Details Grid, declare DAC Extension as below:

    public class SOLineExtension : PXCacheExtension<SOLine>
    {
        public abstract class itemAttributes : IBqlField { }
    
        [PXAddAtttributeColumns(new[] { "ASSETID", "HWMODEL" },
                typeof(CSAnswerType.inventoryAnswerType),
                typeof(SOLine.inventoryID),
                typeof(InventoryItem.itemClassID), false)]
        public virtual string[] ItemAttributes { get; set; }
    }
    

    Make sure to specify AutoGenerateColumns="AppendDynamic" for PXGrid control dynamic Attribute columns creation

    Fields will show up as below:

    To include attributes as Columns in grid of Add Stock Item Dialog, declare DAC Extension as below:

    public class SOSiteStatusSelectedExtension : PXCacheExtension<SOSiteStatusSelected>
    {
        public abstract class itemAttributes : IBqlField { }
    
        [PXAddAtttributeColumns(new[] { "ASSETID", "HWMODEL" },
                typeof(CSAnswerType.inventoryAnswerType),
                typeof(InventoryItem.inventoryID),
                typeof(InventoryItem.itemClassID), false)]
        public virtual string[] ItemAttributes { get; set; }
    }
    

    Make sure to specify AutoGenerateColumns="AppendDynamic" for PXGrid control dynamic Attribute columns creation

    Fields will show up as below:

    Note: This example is applicable to 5.3 series – Build 5.30.1367 onwards.

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