版本19.104
我试图将构成套件的物品添加到我用代码制作的新销售订单中。我将套件项目作为“免费”项目添加到销售订单中。我的问题是,如果我要在销售订单中添加多个行,则仅将循环中最后一行的套件项目添加到销售订单中。这是一些代码:
public PXSelect<INKitSpecStkDet, Where<INKitSpecStkDet.kitInventoryID,
Equal<Required<INKitSpecStkDet.kitInventoryID>>,
And<INKitSpecStkDet.revisionID,
Equal<Required<INKitSpecStkDet.revisionID>>>>> KitStockItems;
....
public PXAction<MyOrder> MyAction;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "My Action")]
protected void myAction()
{
SOOrderEntry orderEntry = PXGraph.CreateInstance<SOOrderEntry>();
using (PXTransactionScope transScope = new PXTransactionScope())
{
orderEntry.Clear();
SOOrder newOrder = new SOOrder();
newOrder.OrderType = PX.Objects.SO.SOOrderTypeConstants.SalesOrder;
newOrder = orderEntry.CurrentDocument.Insert(newOrder);
newOrder.CustomerID = CurrentDocument.Current.CustomerID;
newOrder.OrderDesc = CurrentDocument.Current.OrderDesc;
newOrder.OrderDate = this.Accessinfo.BusinessDate;
newOrder.ProjectID = CurrentDocument.Current.ProjectID;
newOrder.BranchID = CurrentDocument.Current.BranchID;
newOrder.Hold = true;
newOrder.Status = PX.Objects.SO.SOOrderStatus.Hold;
newOrder = orderEntry.CurrentDocument.Update(newOrder);
orderEntry.Actions.PressSave();
foreach (OrderLine line in Transactions.Select()) //TODO: If only one line in Transactions, no problems.
{
SOLine newLine = orderEntry.Transactions.Insert();
newLine.LineType = PX.Objects.SO.SOLineType.Inventory;
newLine.Operation = PX.Objects.SO.SOOperation.Issue;
newLine.OrderType = newOrder.OrderType;
newLine.InventoryID = line.InventoryID;// 706;
newLine.BranchID = newOrder.BranchID;
newLine.Qty = line.OrderQty; // 1.0m;
newLine.CuryUnitPrice = line.CuryUnitPrice;// 20.0m;
newLine.CuryExtPrice = line.CuryUnitPrice;
newLine.UOM = line.Uom;// "EA";
newLine.SiteID = line.Siteid;// 159;
newLine = orderEntry.Transactions.Update(newLine);
orderEntry.Actions.PressSave();
//TODO: If more than one OrderLine, only last line kit items are added to sales order.
PXResultset<INKitSpecStkDet> resultSet = KitStockItems.Select(new object[] { line.InventoryID, line.KitRevisionID });
foreach (PXResult stkItem in resultSet)
{
INKitSpecStkDet kitItem = stkItem.GetItem<INKitSpecStkDet>();
SOLine stkKitLine = orderEntry.Transactions.Insert();
stkKitLine.InventoryID = kitItem.CompInventoryID;
stkKitLine.Qty = kitItem.DfltCompQty * line.OrderQty;
stkKitLine.UOM = kitItem.UOM;
stkKitLine.IsFree = true;
stkKitLine = orderEntry.Transactions.Update(stkKitLine);
orderEntry.Actions.PressSave();
}
}
transScope.Complete();
}
this.Actions.PressSave();
希望这是有道理的。任何帮助都会很棒。
TIA!
答案 0 :(得分:0)
结果是我在销售订单行上缺少一个字段。我将“手动折扣”设置为true,一切都很好。
....
stkKitLine.IsFree = true;
stkKitLine.ManualDisc = true; //added this
....