【问题标题】:Adding additional filter field on process shipments在处理货件上添加额外的过滤器字段
【发布时间】:2015-06-12 22:58:33
【问题描述】:

我已向 SOSshipment 和 SOSshipmentFilter 添加了一个新的自定义字段。我正在尝试使用它来过滤处理发货的网格,但我遇到了代码问题。我已经在扩展代码的地方进行了其他自定义,但我能够先调用 baseHandler,然后在它返回时执行我的 sn-p。但是,当我覆盖委托函数时,它只是设置了一个返回 baseMethod 的模板。当我将代码放入以包含新的过滤器字段时,我会收到未定义字段/引用的编译错误。我是否需要从原始委托中复制所有原始代码并将其包含在我的覆盖函数中?以下是我当前的覆盖代码:

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
  }
}

【问题讨论】:

    标签: acumatica


    【解决方案1】:

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

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

      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 数据视图委托”)。

    【讨论】:

    • 这个概念在 2019R1 对我来说效果很好。但在 2020R2 中,我不得不将 Orders.SetProcessTarget(null, null, null, filter.Action, parameters); 语句更改为 Orders.SetProcessWorkflowAction(filter.Action, parameters);。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    • 2011-08-27
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多