如何以编程方式从多个订单创建货件?

时间:2017-07-14 15:20:05

标签: acumatica

创建货件并使用所有商品向其添加多个订单的最简单方法是什么?

1 个答案:

答案 0 :(得分:1)

以下示例使用销售订单和发货屏幕上使用的 CreateShipment 方法。基本上,此示例正在循环执行给定客户和给定仓库的所有SOShipmentPlan计划,以类似于“发货”屏幕上“添加销售订单”弹出窗口的方式选择它们。唯一的区别是执行单个BQL查询以检索所有SOShipmentPlan记录,这些记录可以添加到Shipment中,而不是使用Add Sales Orders弹出思想代码进行操作。

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();
相关问题