在自定义字段 SOLine 中填充序列化项目的单位成本

Populate Unit Cost for Serialized Item in custom field SOLine

我需要使用相同的 Lot/Serial 编号从采购收据的序列化项目单位成本填充 SOLine 中的自定义列(用户定义成本)(屏幕截图 1)。如果该项目拆分了 Lot/Serial 个数字(屏幕截图 2),那么我必须根据用户在 SOLine 项目中输入的 Lot/Serial 个数字来读取相应的单位成本。

我已经编写了 SOLine_RowPersisting 事件来处理项目是否未拆分但不确定如何查找是否存在拆分的序列化项目。下面是 SOLine_RowPersisting 事件的代码。请提出建议。

protected virtual void SOLine_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
    SOLine row = (SOLine)e.Row;
    if (row == null)
        return;

    if (!string.IsNullOrEmpty(row.LotSerialNbr))
    {
        SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();

        //select UnitCost, * from POReceiptLine where CompanyID = 2 and ReceiptNbr = 'PR004082' and InventoryID = '8502' and LotSerialNbr = 'SUB1703210365'
        //select LotSerialNbr, * from POReceiptLineSplit where CompanyID = 2 and InventoryID = '8502' and LotSerialNbr = 'SUB1704270366'

        //TODO : How to get it from POReceiptLineSplit also

        POReceiptLine poRow = PXSelect<POReceiptLine,
                        Where<POReceiptLine.inventoryID, Equal<Required<POReceiptLine.inventoryID>>,
                            And<POReceiptLine.lotSerialNbr, Equal<Required<POReceiptLine.lotSerialNbr>>,
                            And<POReceiptLine.pOType, Equal<Required<POReceiptLine.pOType>>>>>>.Select(graph, row.InventoryID, row.LotSerialNbr, "RO");

        SOLineExtension ext = PXCache<SOLine>.GetExtension<SOLineExtension>(row);
        ext.UsrUserDefinedCost = poRow.UnitCost;
    }
}

截图 1:- 截图 2:-

您可以从基础 DAC 的 'splits' DataView 迭代 POReceiptLineSplit 记录。

为此,请在 Acumatica 中打开网格,按住 Control+Alt 并单击它。这将带来一个弹出窗口,其中包含网格中包含的记录的 DAC 名称。

从那里 select 您的自定义项目。点击'Grid: splits',网格的DataMember 属性为'splits'。这是来自 Base class 的 DataView 的名称。

有了这些信息,您可以从图形扩展中迭代网格的内容。请注意,我们使用 Base 前缀是因为我们从扩展中引用了基本图。

       foreach (POReceiptLineSplit split in Base.splits.Select())
       {
          PXTrace.WriteInformation("ReceiptNbr: {0}{1}LineNbr: {2}{3}SplitLineNbr: {4}",
                                   split.ReceiptNbr, Environment.NewLine,
                                   split.LineNbr, Environment.NewLine,
                                   split.SplitLineNbr);
       }

SOLineSplit_LotSerialNbr_FieldUpdated 事件需要在 SOOrder 扩展中扩展,POReceiptLine_RowSelected 在 POReceiptEntry 扩展中扩展。下面的代码将有助于从购买收据中获取单位成本。

POReceiptLine poRow = PXSelectJoin<POReceiptLine,
 LeftJoin<POReceiptLineSplit,
  On<POReceiptLine.receiptNbr, Equal<POReceiptLineSplit.receiptNbr>,
   And<POReceiptLine.inventoryID, Equal<POReceiptLineSplit.inventoryID>,
   And<POReceiptLine.lineNbr, Equal<POReceiptLineSplit.lineNbr>>>>>,
 Where<POReceiptLine.inventoryID, Equal<Required<POReceiptLine.inventoryID>>,
   And<POReceiptLineSplit.lotSerialNbr, Equal<Required<POReceiptLineSplit.lotSerialNbr>>,
   And<POReceiptLine.receiptType, Equal<Required<POReceiptLine.receiptType>>>>>>.Select(graph, row.InventoryID, row.LotSerialNbr, "RT");