【问题标题】:Custom attribute constructor - PXCustomSelectorAttribute自定义属性构造函数 - PXCustomSelectorAttribute
【发布时间】:2021-12-17 23:28:50
【问题描述】:

美好的一天

我为销售订单的客户 ID 属性创建了一个自定义属性。 使用客户 ID 的当前属性,处于信用保留状态的客户不会显示在列表中。

我的想法是动态更改列表,以便如果订单类型是 QT 客户,则处于信用保留状态的客户仍会显示在列表中。

我的问题是我不知道是否有办法发送/获取当前的 SOOrder.OrderType

这就是我所在的地方


namespace PX.Objects.SO
{

    [PXNonInstantiatedExtension]
    public class SO_SOOrder_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOOrder>
    {
        #region CustomerID  
        [PXMergeAttributes(Method = MergeMethod.Append)]
        // [CustomercustomersAttribute(Current<SOOrder.orderType>))]
        [CustomercustomersAttribute()]
        public int? CustomerID { get; set; }
        #endregion
    }

    public class CustomercustomersAttribute : PXCustomSelectorAttribute
    {
        public string orderType { get; set; }
        public Type orderType2 { get; set; }

        public CustomercustomersAttribute(Type OrderType) : base(typeof(Customer.acctCD))
        {
            this.orderType2 = OrderType;
            this.DescriptionField = typeof(Customer.acctName);
        }

        public CustomercustomersAttribute(string OrderType) : base(typeof(Customer.acctCD))
        {
            this.orderType = OrderType;
            this.DescriptionField = typeof(Customer.acctName);
        }

        public CustomercustomersAttribute() : base(typeof(Customer.acctCD))
        {
            this.DescriptionField = typeof(Customer.acctName);
        }
        protected virtual IEnumerable GetRecords()
        {
            foreach (Customer pc in PXSelect<Customer>.Select(this._Graph))
            {

                if (pc.Status != "A")
                {
                    // Here I want to do the check if 
                    if (orderType.ToString() == "QT")
                    {
                        yield return pc;
                    }
                }
                else
                {
                    yield return pc;

                }
               
            }
        }

    }
}

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    尝试从GraphCaches集合中获取当前缓存对象:

    Type fieldType = [...];
    var cache = _Graph.Caches[BqlCommand.GetItemType(fieldType)];
    var currentCacheObject = cache.Current;
    

    【讨论】:

    • 字段类型在您的问题代码中将是变量“orderType2”。
    • 谢谢 HB 让它工作了
    【解决方案2】:

    尽可能使用现有属性总是一个好主意。

    在您的情况下,您似乎可以使用PXRestrictorAttribute 获得所需的行为。它为 BQL 命令添加了一个限制,该命令为查找控件选择数据并在输入的值不符合限制时显示错误消息。

    Here is a nice article from Sergey Marenich from Acumatica about PXRestrictor.

    这就是您编写限制器的方式。请注意,我们使用 ReplaceInherited 属性来覆盖活跃客户的现有限制器:

    using System;
    using PX.Data;
    using PX.Objects.Common;
    using PX.Objects.AR;
    using PX.Objects.CR;
    using PX.Objects.SO;
    
    namespace PX.Objects.SO
    {
    
      #region CustomerID  
      [PXMergeAttributes(Method = MergeMethod.Append)]
      [PXRestrictor(typeof(Where<Customer.status, IsNull,
                            Or<Customer.status, Equal<BAccount.status.active>,
                            Or<Customer.status, Equal<BAccount.status.oneTime>,
                            Or2<Where<Customer.status, Equal<BAccount.status.Hold>, And<Current<SOOrder.orderType>,Equal<SOOrderTypeConstants.quoteOrder>>>>
                            >>>), "Customer status is {0} and this is not a quote", typeof(Customer.status), ReplaceInherited = true)]
      public virtual int? CustomerID { get; set; }
      #endregion
    
    }
    

    奖励:如果这是您唯一需要的自定义,您可以直接从 UI 将其添加到自定义项目中,而无需实际编译扩展库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多