我可以在 DAC 扩展中使用 PXDBScalar 来查询来自同一个 table 的记录吗?

Can I use PXDBScalar in a DAC Extension to query records from the same table?

我对 Acumatica 世界还很陌生。我得到的任务是向 SOLine 添加一个字段,该字段将显示给定 SOLine 上相同库存项目在接下来 30 天内要装运的数量总和。请求是让该字段在一般查询中可用。

我创建了一个 DAC 扩展,并认为应该使用带有 PXDBScalar 的字段。

但是,当我将字段添加到一般查询时,我得到的所有显示记录的值都相同。就好像在尝试查询相同的 table 时,它只使用项目的聚合值之一,而不是为 GI 中显示的每个 item/row 重新计算。

我在 PXDBScalar 公式中是否做错了什么?我是否缺少对当前记录的引用?

namespace PX.Objects.SO
{
  public class SOLineExt : PXCacheExtension<PX.Objects.SO.SOLine>
  {

    #region DaysOf
    public class int_DaysInFuture : PX.Data.BQL.BqlInt.Constant<int_DaysInFuture>
    {
      public int_DaysInFuture()
        : base(30)
        {
        }
    }
    #endregion

    #region UsrSalesInNextThirtyDays
    public abstract class usrSalesInNextThirtyDays : PX.Data.IBqlField {}
    [PXDecimal(2)]
    [PXUIField(DisplayName="Sales in next 30 days")]
    [PXDBScalar(typeof(Search4<SOLine.openQty,
         Where<SOLine.inventoryID, Equal<SOLine.inventoryID>
          ,And< Where<DateDiff<SOLine.shipDate, Today, DateDiff.day>, LessEqual< int_DaysInFuture > >>
         >
        ,Aggregate<GroupBy<SOLine.inventoryID, Sum<SOLine.openQty>>>
                             >))]
    public virtual Decimal? UsrSalesInNextThirtyDays{ get; set; }
    #endregion


  }
}

因此添加此字段表明与 InventoryItem 的链接按预期工作。

    #region UsrSalesInNextThirtyDays2
    public abstract class usrSalesInNextThirtyDaysTwo : PX.Data.IBqlField {}
    [PXDecimal(2)]
    [PXUIField(DisplayName="Base Price")]
    [PXDBScalar(typeof(Search<InventoryItem.basePrice,
         Where<InventoryItem.inventoryID, Equal<SOLine.inventoryID>>
                             >))]
    public virtual Decimal? UsrSalesInNextThirtyDaysTwo{ get; set; }
    #endregion   

所以我尝试添加一个内部联接以使用 inventoryID 字段强制该行到 InventoryItem,但生成的查询仍然返回作为结果集中所有记录的总和结果返回的最后一项的总和。

    public abstract class usrSalesInNextThirtyDays : PX.Data.IBqlField {}
    [PXDecimal(2)]
    [PXUIField(DisplayName="Sales in next 30 days")]
    [PXDBScalar(typeof(
        Search5<SOLine.openQty,
            InnerJoin<InventoryItem,
                On<SOLine.inventoryID, Equal<InventoryItem.inventoryID>>>,
            Where<DateDiff<SOLine.shipDate, Today, DateDiff.day>, LessEqual< int_DaysInFuture > >,
            Aggregate<Sum<SOLine.openQty>>
                             >))]
    public virtual Decimal? UsrSalesInNextThirtyDays{ get; set; }

我觉得我离强制 DAC 生成正确的查询越来越近了,但我还没有做到。

由于子查询的生成方式,您不能以这种方式循环引用 table。