正如我在上一个问题(How to customize the sales order process to trigger an automatic "adding contract" process when sales order is successfully completed)中提到的,我需要在添加此销售订单后自动为销售订单中的每个特定产品添加合同。
由于@ Gabriel的回复,我已经学会了在之前的问题中添加合同部分,现在我需要知道如何在销售订单业务逻辑中获取订单商品,客户ID和位置ID中的库存ID等订单信息(屏幕SO301000)。请有人请给我一些示例代码吗?
感谢。
现在我似乎能够从代码中获取客户ID和位置ID:
SOOrder SalesOrder = (SOOrder)Base.Caches[typeof(SOOrder)].Current;
int customer_id = SalesOrder.CustomerID;
int Location ID = SalesOrder.CustomerLocationID;
....
但是我仍然需要找到如何在订单中迭代产品列表(SOLINE项目)...我在T200培训中发现的代码如下所示(这是实施SO发布操作的示例)PDF似乎也是如此老了,对我没有帮助:
public static void ReleaseOrder(SalesOrder order)
{
SalesOrderEntry graph = PXGraph.CreateInstance<SalesOrderEntry>();
graph.Orders.Current = order;
foreach (OrderLine line in graph.OrderDetails.Select())
{
ProductQty productQty = new ProductQty();
productQty.ProductID = line.ProductID;
productQty.AvailQty = -line.OrderQty;
graph.Stock.Insert(productQty);
}
order.ShippedDate = graph.Accessinfo.BusinessDate;
order.Status = OrderStatus.Completed;
graph.Orders.Update(order);
graph.Persist();
}
答案 0 :(得分:2)
当您在扩展程序中覆盖持久性
时,必须循环使用这些行 foreach (SOLine line in this.Base.Transactions.Select())
{
}
您在这里做的是通过执行select方法循环缓存中的有效记录。为此,您必须从Base BLC定义中找到与DAC(SOLine)相关的视图定义(Transactions)。
答案 1 :(得分:0)
我想出了如何做到这一点,以下是我所拥有的代码,它到目前为止为我工作 - 你可以看到我使用&#34; SOLine_RowPersisted&#34;而不是定制&#34;坚持()&#34;就像我之前做的那样。
protected virtual void SOLine_RowPersisted(PXCache sender,PXRowPersistedEventArgs e)
{
if (e.TranStatus == PXTranStatus.Completed)
{
if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Insert)
{
SOOrder SalesOrder = (SOOrder)Base.Caches[typeof(SOOrder)].Current;
SOLine line = (SOLine)e.Row;
// Lookup inventory
InventoryItem template = PXSelect<InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>
.Select(Base, line.InventoryID);
if (template.InventoryCD == null)
{
throw new PXException("Inventory CD can not be blank.");
}
if (template.InventoryCD.StartsWith("AAABBB"))
{
ContractMaint contractMaint = PXGraph.CreateInstance<ContractMaint>();
CTBillEngine engine = PXGraph.CreateInstance<CTBillEngine>();
DateTime StartDate = DateTime.Now;
........
string contractCD = ......
Contract contract = SetupActivateContract(contractMaint, contractCD, StartDate , line.CustomerID, SalesOrder.CustomerLocationID, engine);
}
} else if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Delete)
{
.....
} else if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Update)
{
....
}
}
}