Acumatica中能否动态构建查找?类似视图委托实现网格的方式
当然可以在Acumatica中动态构建查找功能!
完全可以用类似网格视图委托的思路实现,结合你已经创建的临时表和DAC,就能打造出带自定义计算逻辑的动态查找。下面是具体的实现步骤和注意点:
一、选对临时表的填充时机
因为你需要基于INLotSerialStatus做实时计算,最适合的填充位置是查找字段对应的视图委托——每次用户打开查找弹窗时,这个委托都会触发,能保证展示的批次和计算后数量是最新的。如果你的查找依赖页面上其他字段(比如当前选中的库存ID、仓库),这个方式也能自动获取当前上下文的值。
二、具体实现步骤
1. 确认临时DAC的配置
确保你的临时DAC继承了IBqlTable,并且包含必需的字段:比如批次号、计算后数量、关联的库存ID、仓库ID等,示例如下:
[PXPrimaryGraph(typeof(YourTargetGraph))] [PXCacheName("Calculated Lot Serial")] public class YourTempLotTable : IBqlTable { [PXDBString(15, IsKey = true)] [PXUIField(DisplayName = "Lot/Serial Nbr")] public virtual string LotSerialNbr { get; set; } public abstract class lotSerialNbr : BqlString.Field<lotSerialNbr> { } [PXDBDecimal(6)] [PXUIField(DisplayName = "Calculated Qty")] public virtual decimal? CalculatedQty { get; set; } public abstract class calculatedQty : BqlDecimal.Field<calculatedQty> { } // 关联字段,用于过滤 [PXDBInt] public virtual int? InventoryID { get; set; } public abstract class inventoryID : BqlInt.Field<inventoryID> { } [PXDBInt] public virtual int? WarehouseID { get; set; } public abstract class warehouseID : BqlInt.Field<warehouseID> { } }
2. 在Graph中定义临时视图并添加委托
在你需要使用查找的Graph里,添加临时视图,并通过委托查询INLotSerialStatus、执行计算后填充临时表:
public class YourTargetGraph : PXGraph<YourTargetGraph> { // 定义临时视图 public PXSelect<YourTempLotTable> TempLotView; // 视图委托:填充临时表 protected virtual IEnumerable tempLotView() { // 先清空临时表,避免旧数据残留 TempLotView.Clear(); // 获取当前页面的上下文参数(比如当前选中的库存和仓库) var currentInventory = Base.Document.Current?.InventoryID; var currentWarehouse = Base.Document.Current?.WarehouseID; if (currentInventory == null || currentWarehouse == null) yield break; // 查询符合条件的批次数据 foreach (INLotSerialStatus lot in PXSelect<INLotSerialStatus, Where<INLotSerialStatus.inventoryID, Equal<Required<INLotSerialStatus.inventoryID>>, And<INLotSerialStatus.warehouseID, Equal<Required<INLotSerialStatus.warehouseID>>>>> .Select(Base, currentInventory, currentWarehouse)) { // 这里替换成你的自定义计算逻辑 decimal calculatedQty = lot.QtyOnHand - lot.QtyReserved; // 示例:可用数量=现有库存-预留库存 // 创建临时表记录并赋值 YourTempLotTable tempLot = new YourTempLotTable(); tempLot.LotSerialNbr = lot.LotSerialNbr; tempLot.CalculatedQty = calculatedQty; tempLot.InventoryID = lot.InventoryID; tempLot.WarehouseID = lot.WarehouseID; // 将记录加入临时视图 yield return TempLotView.Insert(tempLot); } } }
3. 绑定查找字段到临时视图
在需要添加查找的DAC字段上,用PXSelector属性指向你的临时视图,同时设置显示的字段:
[PXSelector(typeof(Search<YourTempLotTable.lotSerialNbr, Where<YourTempLotTable.inventoryID, Equal<Current<YourDocumentDAC.inventoryID>>, And<YourTempLotTable.warehouseID, Equal<Current<YourDocumentDAC.warehouseID>>>>>), typeof(YourTempLotTable.lotSerialNbr), typeof(YourTempLotTable.calculatedQty), DescriptionField = typeof(YourTempLotTable.lotSerialNbr))] [PXUIField(DisplayName = "Lot/Serial Nbr")] public virtual string LotSerialNbr { get; set; } public abstract class lotSerialNbr : BqlString.Field<lotSerialNbr> { }
三、关键注意点
- 缓存管理:临时DAC要加上
[PXPrimaryGraph(typeof(YourTargetGraph))]属性,确保Acumatica正确管理临时表的缓存。 - 性能优化:如果批次数据量大,一定要通过库存ID、仓库ID等条件过滤
INLotSerialStatus,避免全表查询拖慢性能。 - 上下文同步:如果查找依赖的页面字段有变化,比如用户切换了仓库,视图委托会自动重新执行,保证查找数据同步更新。
内容的提问来源于stack exchange,提问作者Stan A
相关产品推荐
相关产品推荐

