没有简单的方法可以在不进行自定义的情况下在库存商品的备用 ID 上添加搜索功能。另外,请记住,我们在这里讨论的是库存商品和备用 ID 之间的一对多关系,这使得不可能简单地将备用 ID 列放入库存 ID 选择器中,因为这将导致同一库存商品显示多个次,因为需要与交叉引用 DAC 进行连接。
您需要做的第一件事是为库存项目 DAC 创建一个数据库绑定字段(确保在 InventoryItem 数据库中创建 UsrAlternateIDs 列) 表连接库存商品的所有备用 ID (注意 PXUIField 上的可见性设置为 PXUIVisibility.SelectorVisible - 这是在库存 ID 选择器内显示备用 ID 列所必需的):
public class InventoryItemExt : PXCacheExtension<InventoryItem>
{
public abstract class usrAlternateIDs : IBqlField { }
[PXDBString(4000, IsUnicode = true)]
[PXUIField(DisplayName = "Alternate IDs", Visibility = PXUIVisibility.SelectorVisible)]
public string UsrAlternateIDs { get; set; }
}
下一步是重写 InventoryItemMaint BLC 扩展中的 Persist 方法,以便每次用户在“交叉引用”选项卡中进行更改时重新生成串联的备用 ID:
public class InventoryItemMaint_Extension : PXGraphExtension<InventoryItemMaint>
{
[PXOverride]
public void Persist(Action del)
{
using (PXTransactionScope ts = new PXTransactionScope())
{
InventoryItem item = Base.Item.Current;
if (item != null && Base.itemxrefrecords.Cache.IsDirty)
{
string alternateIDs = string.Empty;
foreach (INItemXRef crossRef in Base.itemxrefrecords.Select())
{
alternateIDs = string.IsNullOrEmpty(alternateIDs) ?
crossRef.AlternateID : alternateIDs + "; " + crossRef.AlternateID;
}
item.GetExtension<InventoryItemExt>().UsrAlternateIDs = alternateIDs;
Base.Item.Update(item);
}
del();
ts.Complete();
}
}
}
And finally, you should add UsrAlternateIDs in PXSelector FastFilterFields property:
Once these 3 steps are completed, the final result should look as follows:
要一步连接所有当前现有的库存商品替代 ID,您可以在库存商品屏幕上实施自定义操作。之后您可以删除该操作。
public class InventoryItemMaint_Extension : PXGraphExtension<InventoryItemMaint>
{
...
public PXAction<InventoryItem> RecalcAlternateIDs;
[PXButton]
[PXUIField(DisplayName = "Concatenate Alternate IDs")]
protected void recalcAlternateIDs()
{
PXLongOperation.StartOperation(Base, () =>
{
InventoryItemMaint itemMaint = PXGraph.CreateInstance<InventoryItemMaint>();
var items = PXSelect<InventoryItem, Where<InventoryItem.stkItem, Equal<boolTrue>>>.Select(itemMaint);
foreach (InventoryItem item in items)
{
itemMaint.Clear();
itemMaint.Item.Current = item;
itemMaint.itemxrefrecords.Cache.IsDirty = true;
itemMaint.Actions.PressSave();
}
});
}
}