在流程货件上添加额外的筛选字段

Adding additional filter field on process shipments

我在 SOShipment 和 SOShipmentFilter 中添加了一个新的自定义字段。我正在尝试使用它来过滤处理装运的网格,但我遇到了代码问题。我在扩展代码的地方进行了其他自定义,但我能够先调用 baseHandler,然后在 returned 时执行我的代码片段。但是,当我重写委托函数时,它只是设置一个带有 return 到 baseMethod 的模板。当我放入我的代码以包含新的过滤器字段时,我收到未定义 fields/references 的编译错误。我是否需要从原始委托复制所有原始代码并将其包含在我的覆盖函数中?以下是我当前的覆盖代码:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PX.Data;
using PX.Objects.CS;
using PX.Objects.IN;
using PX.Objects.AR;
using PX.Objects.CM;
using POReceipt = PX.Objects.PO.POReceipt;
using POReceiptLine = PX.Objects.PO.POReceiptLine;
using POLineType = PX.Objects.PO.POLineType;
using PX.Objects;
using PX.Objects.SO;

namespace PX.Objects.SO
{
  public class SOInvoiceShipment_Extension:PXGraphExtension<SOInvoiceShipment>
  {
    #region Event Handlers
    public delegate IEnumerable ordersDelegate();
    [PXOverride]
    public IEnumerable orders(ordersDelegate baseMethod)
    {
      if (filter.usrTruckNbr != null)
      {
        ((PXSelectBase<SOShipment>)cmd).WhereAnd<Where<SOShipment.usrTruckNbr, GreaterEqual<Current<SOShipmentFilter.usrTruckNbr>>>>();
      }
      return baseMethod();
    }
    protected virtual void SOShipmentFilter_UsrTruckNbr_CacheAttached(PXCache cache)
    {

    }
    #endregion
  }
}

cmd 是一个位置变量,您无法从您的扩展程序访问它。我看到有两种方法可以达到您想要的结果:

  1. 将整个委托函数复制到您的扩展中。这并不理想,因为每个新版本的 Acumatica 都必须对其进行验证和更新。
  2. 在客户端从原始委托 return 编辑数据但在屏幕上显示之前过滤数据。这不如过滤 SQL 有效,但至少可以消除将太多代码复制到扩展的需要。这是一个完整的示例,它会将发货列表过滤为 return 仅发货数量为偶数的文件:

    public class SOInvoiceShipment_Extension : PXGraphExtension<SOInvoiceShipment>
    {
        [PXFilterable]
        public PXFilteredProcessing<SOShipment, SOShipmentFilter> Orders;
    
        protected IEnumerable orders()
        {
            // Filter the list of shipments to return only documents where shipment quantity is even
            foreach (SOShipment shipment in Base.Orders.Select())
            {            
                if(shipment.ShipmentQty % 2 == 0)
                {
                    yield return shipment;
                }
            }
        }
    
        public void SOShipmentFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            if (e.Row == null) return;
    
            SOShipmentFilter filter = e.Row as SOShipmentFilter;
            if (filter != null && !string.IsNullOrEmpty(filter.Action))
            {
                Dictionary<string, object> parameters = Base.Filter.Cache.ToDictionary(filter);
                Orders.SetProcessTarget(null, null, null, filter.Action, parameters);
            }
        }
    }
    

在任何情况下,您都不应该使用 PXOverride 来覆盖视图委托;不幸的是,当您尝试覆盖委托时,自定义工具会生成错误的方法签名,这将得到改进。您应该参考可用的 T300 培训 here 以获取有关此类自定义的更多信息(查找“声明或更改 BLC 数据视图委托”)。