如何以编程方式从多个订单创建发货?
How to programmatically create a shipment from multiple orders?
创建货件并向其中添加多个订单及其所有商品的最简单方法是什么?
下面的示例利用了销售订单和发货屏幕上使用的 CreateShipment 方法。基本上,此示例所做的是循环遍历给定客户和给定仓库的所有 SOShipmentPlan 计划,以 select 它们的方式类似于添加销售订单弹出窗口在装运屏幕上的工作方式。唯一的区别是执行单个 BQL 查询来检索所有 SOShipmentPlan 记录,这些记录可以添加到装运中,而不是使用添加销售订单弹出窗口代码进行操作。
string operation = SOOperation.Issue;
var graph = PXGraph.CreateInstance<SOShipmentEntry>();
var shipment = graph.Document.Insert();
var customer = (BAccountR)PXSelect<BAccountR,
Where<BAccountR.acctCD, Equal<Required<BAccountR.acctCD>>>>
.SelectSingleBound(graph, new object[] { }, "ABARTENDE");
shipment.CustomerID = customer.BAccountID;
shipment = graph.Document.Update(shipment);
var warehouse = (INSite)PXSelect<INSite,
Where<INSite.siteCD, Equal<Required<INSite.siteCD>>>>
.SelectSingleBound(graph, new object[] { }, "RETAIL");
shipment.SiteID = warehouse.SiteID;
graph.Document.Update(shipment);
SOOrder prevOrder = null;
foreach (PXResult<SOShipmentPlan, SOLineSplit, SOOrderShipment, SOOrder> res in
PXSelectJoin<SOShipmentPlan,
InnerJoin<SOLineSplit,
On<SOLineSplit.planID, Equal<SOShipmentPlan.planID>>,
LeftJoin<SOOrderShipment,
On<SOOrderShipment.orderType, Equal<SOShipmentPlan.orderType>,
And<SOOrderShipment.orderNbr, Equal<SOShipmentPlan.orderNbr>,
And<SOOrderShipment.operation, Equal<SOLineSplit.operation>,
And<SOOrderShipment.siteID, Equal<SOShipmentPlan.siteID>,
And<SOOrderShipment.confirmed, Equal<boolFalse>,
And<SOOrderShipment.shipmentNbr, NotEqual<Current<SOShipment.shipmentNbr>>>>>>>>,
InnerJoin<SOOrder,
On<SOOrder.orderType, Equal<SOShipmentPlan.orderType>,
And<SOOrder.orderNbr, Equal<SOShipmentPlan.orderNbr>,
And<SOOrder.customerID, Equal<Current<SOShipment.customerID>>,
And<SOOrder.cancelled, Equal<boolFalse>,
And<SOOrder.completed, Equal<boolFalse>,
And<SOOrder.hold, Equal<False>,
And<SOOrder.creditHold, Equal<False>>>>>>>>>>>,
Where<SOShipmentPlan.orderType, Equal<Required<SOShipmentPlan.orderType>>,
And<SOShipmentPlan.siteID, Equal<Current<SOShipment.siteID>>,
And<SOOrderShipment.shipmentNbr, IsNull,
And<SOLineSplit.operation, Equal<Required<SOLineSplit.operation>>,
And2<
Where<Current<SOShipment.destinationSiteID>, IsNull,
Or<SOShipmentPlan.destinationSiteID, Equal<Current<SOShipment.destinationSiteID>>>>,
And<
Where<SOShipmentPlan.inclQtySOShipping, Equal<True>,
Or<SOShipmentPlan.inclQtySOShipped, Equal<True>,
Or<SOShipmentPlan.requireAllocation, Equal<False>,
Or<SOLineSplit.lineType, Equal<SOLineType.nonInventory>>>>>>>>>>>>
.Select(graph, "SO", operation))
{
var plan = (SOShipmentPlan)res;
plan.Selected = true;
graph.soshipmentplan.Update(plan);
var order = (SOOrder)res;
prevOrder = prevOrder ?? order;
if (order.OrderNbr == prevOrder.OrderNbr) continue;
graph.CreateShipment(prevOrder, shipment.SiteID, shipment.ShipDate, false, operation, null);
graph.soshipmentplan.Cache.Clear();
prevOrder = order;
}
if (prevOrder != null)
{
graph.CreateShipment(prevOrder, shipment.SiteID, shipment.ShipDate, false, operation, null);
graph.soshipmentplan.Cache.Clear();
}
graph.Actions.PressSave();
创建货件并向其中添加多个订单及其所有商品的最简单方法是什么?
下面的示例利用了销售订单和发货屏幕上使用的 CreateShipment 方法。基本上,此示例所做的是循环遍历给定客户和给定仓库的所有 SOShipmentPlan 计划,以 select 它们的方式类似于添加销售订单弹出窗口在装运屏幕上的工作方式。唯一的区别是执行单个 BQL 查询来检索所有 SOShipmentPlan 记录,这些记录可以添加到装运中,而不是使用添加销售订单弹出窗口代码进行操作。
string operation = SOOperation.Issue;
var graph = PXGraph.CreateInstance<SOShipmentEntry>();
var shipment = graph.Document.Insert();
var customer = (BAccountR)PXSelect<BAccountR,
Where<BAccountR.acctCD, Equal<Required<BAccountR.acctCD>>>>
.SelectSingleBound(graph, new object[] { }, "ABARTENDE");
shipment.CustomerID = customer.BAccountID;
shipment = graph.Document.Update(shipment);
var warehouse = (INSite)PXSelect<INSite,
Where<INSite.siteCD, Equal<Required<INSite.siteCD>>>>
.SelectSingleBound(graph, new object[] { }, "RETAIL");
shipment.SiteID = warehouse.SiteID;
graph.Document.Update(shipment);
SOOrder prevOrder = null;
foreach (PXResult<SOShipmentPlan, SOLineSplit, SOOrderShipment, SOOrder> res in
PXSelectJoin<SOShipmentPlan,
InnerJoin<SOLineSplit,
On<SOLineSplit.planID, Equal<SOShipmentPlan.planID>>,
LeftJoin<SOOrderShipment,
On<SOOrderShipment.orderType, Equal<SOShipmentPlan.orderType>,
And<SOOrderShipment.orderNbr, Equal<SOShipmentPlan.orderNbr>,
And<SOOrderShipment.operation, Equal<SOLineSplit.operation>,
And<SOOrderShipment.siteID, Equal<SOShipmentPlan.siteID>,
And<SOOrderShipment.confirmed, Equal<boolFalse>,
And<SOOrderShipment.shipmentNbr, NotEqual<Current<SOShipment.shipmentNbr>>>>>>>>,
InnerJoin<SOOrder,
On<SOOrder.orderType, Equal<SOShipmentPlan.orderType>,
And<SOOrder.orderNbr, Equal<SOShipmentPlan.orderNbr>,
And<SOOrder.customerID, Equal<Current<SOShipment.customerID>>,
And<SOOrder.cancelled, Equal<boolFalse>,
And<SOOrder.completed, Equal<boolFalse>,
And<SOOrder.hold, Equal<False>,
And<SOOrder.creditHold, Equal<False>>>>>>>>>>>,
Where<SOShipmentPlan.orderType, Equal<Required<SOShipmentPlan.orderType>>,
And<SOShipmentPlan.siteID, Equal<Current<SOShipment.siteID>>,
And<SOOrderShipment.shipmentNbr, IsNull,
And<SOLineSplit.operation, Equal<Required<SOLineSplit.operation>>,
And2<
Where<Current<SOShipment.destinationSiteID>, IsNull,
Or<SOShipmentPlan.destinationSiteID, Equal<Current<SOShipment.destinationSiteID>>>>,
And<
Where<SOShipmentPlan.inclQtySOShipping, Equal<True>,
Or<SOShipmentPlan.inclQtySOShipped, Equal<True>,
Or<SOShipmentPlan.requireAllocation, Equal<False>,
Or<SOLineSplit.lineType, Equal<SOLineType.nonInventory>>>>>>>>>>>>
.Select(graph, "SO", operation))
{
var plan = (SOShipmentPlan)res;
plan.Selected = true;
graph.soshipmentplan.Update(plan);
var order = (SOOrder)res;
prevOrder = prevOrder ?? order;
if (order.OrderNbr == prevOrder.OrderNbr) continue;
graph.CreateShipment(prevOrder, shipment.SiteID, shipment.ShipDate, false, operation, null);
graph.soshipmentplan.Cache.Clear();
prevOrder = order;
}
if (prevOrder != null)
{
graph.CreateShipment(prevOrder, shipment.SiteID, shipment.ShipDate, false, operation, null);
graph.soshipmentplan.Cache.Clear();
}
graph.Actions.PressSave();