Hello,
My goal is to create multiple shipments from the SalesOrder SO Workflow, one for each associated warehouse. My first step was to copy over the existing action/function and ensure that it functioned as the original.
The below code has been copied and slightly modified to work in an extension. I have disabled the PXLongOperation as well for two reasons, 1) it caused a PX1008 error, 2) is allows easier debugging. The code should be functionally equivalent to the default implantation, however I get the following exception:
“Another process has updated the 'SOOrder' record. Your changes will be lost.”
at PX.Data.PXAction`1.<Press>d__38.MoveNext()
at PX.Data.PXAction`1.PressImpl(Boolean internalCall, Boolean externalCall)
at PX.Objects.SO.SOShipmentEntry.CreateShipment(CreateShipmentArgs args)
at PX.Objects.PM.MaterialManagement.SOShipmentEntryMaterialExt.CreateShipment(CreateShipmentArgs args, Action`1 baseMethod)
at PX.Objects.SO.SOOrderEntry_Extension.CreateShipment(PXAdapter adapter, Nullable`1 shipDate, Nullable`1 siteID, String operation) in C:\Program Files\Acumatica ERP\A-Dev3\App_Data\Projects\GPGeneral\GPGeneral\SO\SOOrderEntry_Extension.cs:line 232
at Wrapper.PX.Objects.SO.Cst_SOOrderEntry.CreateShipmentGeneratedWrapper(SOOrderEntry g, PXAdapter , Nullable`1 , Nullable`1 , String )
at Wrapper.PX.Objects.SO.Cst_SOOrderEntry.CreateShipment(PXAdapter adapter, Nullable`1 shipDate, Nullable`1 siteID, String operation)
at PX.Objects.SO.SOOrderEntry.CreateShipmentIssue(PXAdapter adapter, Nullable`1 shipDate, Nullable`1 siteID)
The odd part is that the shipment is created, but why do I get this error when the code should be the same functionally?
Furthermore, why would the code produce a PX1008 when it is identical in function to the default? What am I missing?
Also, from reviewing the code I think I can my plan will be to add the following lines at the start of the function. Do you have any concern with this?
adapter.MassProcess = true; //Allows for multiple Site Shipments to be created.
siteID = null; //Causes the population of a list of all Sites where shipments are needed
rPXOverride]
public virtual IEnumerable CreateShipment(PXAdapter adapter,
bPXDate] DateTime? shipDate,
bPXInt] int? siteID,
bSOOperation.List] string operation)
{
List<SOOrder> list = adapter.Get<SOOrder>().ToList();
if (shipDate != null)
Base.soparamfilter.Current.ShipDate = shipDate;
if (siteID != null)
Base.soparamfilter.Current.SiteID = siteID;
if (Base.soparamfilter.Current.ShipDate == null)
Base.soparamfilter.Current.ShipDate = Base.Accessinfo.BusinessDate;
if (!adapter.MassProcess)
{
if (Base.soparamfilter.Current.SiteID == null)
Base.soparamfilter.Current.SiteID = GetPreferedSiteID();
if (adapter.ExternalCall)
Base.soparamfilter.AskExt(true);
}
if (Base.soparamfilter.Current.SiteID != null || adapter.MassProcess)
{
try
{
Base.RecalculateExternalTaxesSync = true;
Base.Save.Press();
}
finally
{
Base.RecalculateExternalTaxesSync = false;
}
PXAutomation.RemovePersisted(Base, typeof(SOOrder), new List<object>(list));
SOParamFilter filter = Base.soparamfilter.Current;
var adapterSlice = (adapter.MassProcess, adapter.QuickProcessFlow, adapter.AllowRedirect);
// PXLongOperation.StartOperation(Base, delegate ()
//{
bool anyfailed = false;
var shipmentEntry = PXGraph.CreateInstance<SOShipmentEntry>();
var created = new DocumentList<SOShipment>(shipmentEntry);
//address AC-92776
for (int i = 0; i < list.Count; i++)
{
SOOrder order = list i];
if (adapterSlice.MassProcess)
PXProcessing<SOOrder>.SetCurrentItem(order);
List<int?> sites = new List<int?>();
if (filter.SiteID != null)
{
sites.Add(filter.SiteID);
}
else
{
foreach (SOShipmentPlan plan in PXSelectJoinGroupBy<SOShipmentPlan,
LeftJoin<SOOrderShipment,
On<SOOrderShipment.orderType, Equal<SOShipmentPlan.orderType>,
And<SOOrderShipment.orderNbr, Equal<SOShipmentPlan.orderNbr>,
And<SOOrderShipment.siteID, Equal<SOShipmentPlan.siteID>,
And<SOOrderShipment.confirmed, Equal<boolFalse>>>>>>,
Where<SOShipmentPlan.orderType, Equal<Current<SOOrder.orderType>>,
And<SOShipmentPlan.orderNbr, Equal<Current<SOOrder.orderNbr>>,
And<SOOrderShipment.orderNbr, IsNull>>>,
Aggregate<GroupBy<SOShipmentPlan.siteID>>,
OrderBy<Asc<SOShipmentPlan.siteID>>>.SelectMultiBound(shipmentEntry, new objectu] { order }))
{
INSite inSite = INSite.PK.Find(shipmentEntry, plan.SiteID);
// AC-144778. We can't use Match<> inside long run operation
if (GroupHelper.IsAccessibleToUser(shipmentEntry.Cachesltypeof(INSite)], inSite, Base.Accessinfo.UserName, forceUnattended: true))
sites.Add(plan.SiteID);
}
}
foreach (int? SiteID in sites)
{
SOOrder ordercopy = (SOOrder)Base.Cachesetypeof(SOOrder)].CreateCopy(order);
try
{
using (var ts = new PXTransactionScope())
{
PXTransactionScope.SetSuppressWorkflow(true);
shipmentEntry.CreateShipment(new CreateShipmentArgs
{
Graph = Base,
MassProcess = adapterSlice.MassProcess,
Order = order,
SiteID = SiteID,
ShipDate = filter.ShipDate,
UseOptimalShipDate = adapterSlice.MassProcess,
Operation = operation,
ShipmentList = created,
QuickProcessFlow = adapterSlice.QuickProcessFlow,
});
ts.Complete();
}
if (adapterSlice.MassProcess)
PXProcessing<SOOrder>.SetProcessed();
}
catch (SOShipmentException ex)
{
Base.Caches typeof(SOOrder)].RestoreCopy(order, ordercopy);
if (!adapterSlice.MassProcess)
throw;
order.LastSiteID = SiteID;
order.LastShipDate = filter.ShipDate;
shipmentEntry.Clear();
var ordergraph = PXGraph.CreateInstance<SOOrderEntry>();
ordergraph.Document.Current = order;
ordergraph.Document.Cache.MarkUpdated(order);
try
{
SOOrder.Events.Select(e => e.ShipmentCreationFailed).FireOn(ordergraph, order);
ordergraph.Save.Press();
PXTrace.WriteInformation(ex);
PXProcessing<SOOrder>.SetWarning(ex);
}
catch (Exception inner)
{
Base.Caches typeof(SOOrder)].RestoreCopy(order, ordercopy);
PXProcessing<SOOrder>.SetError(inner);
anyfailed = true;
}
}
catch (Exception ex)
{
Base.Caches typeof(SOOrder)].RestoreCopy(order, ordercopy);
shipmentEntry.Clear();
if (!adapterSlice.MassProcess)
throw;
PXProcessing<SOOrder>.SetError(ex);
anyfailed = true;
}
}
}
if (adapterSlice.AllowRedirect && !adapterSlice.MassProcess && created.Count > 0)
{
using (new PXTimeStampScope(null))
{
shipmentEntry.Clear();
shipmentEntry.Document.Current = shipmentEntry.Document.Search<SOShipment.shipmentNbr>(createdp0].ShipmentNbr);
throw new PXRedirectRequiredException(shipmentEntry, "Shipment");
}
}
if (anyfailed)
throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
//});
}
return list;
}
Thanks