Skip to main content
Solved

Error trying to override CreateShipment on SOOrderEntry graph

  • November 7, 2024
  • 3 replies
  • 51 views

Joe Schmucker
Captain II
Forum|alt.badge.img+2

I am migrating a 2023 project from another developer to get it to work in 2024.

Due to the requirements for this customization, the previous developer made a complete copy of the CreateShipment action and injected some changes to add logic to the action.

The code in this action has changed from 2023.

To start with, I “re-copied” the Acumatica source code for the action.  I have not injected any changes into the override at this time.  The signature of the action did not change from 2023 to 2024.

When I attempt to Create Shipment from Sales Order Entry, I get this error message:

At this point, I simply have an overridden action with no changes to the base code other than to put “Base.” in front of the various objects that need to reference the base graph.

When I am in debug mode, I cannot hit a breakpoint at the very beginning of this code.

		public delegate IEnumerable CreateShipmentDelegate(PXAdapter adapter,
            [PXDate] DateTime? shipDate,
            [PXInt] int? siteID,
            [SOOperation.List] string operation);
		[PXOverride]
        protected virtual IEnumerable CreateShipment(PXAdapter adapter,
            [PXDate] DateTime? shipDate,
            [PXInt] int? siteID,
            [SOOperation.List] string operation, CreateShipmentDelegate baseMethod)
        {
            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;
                }

                SOParamFilter filter = Base.soparamfilter.Current;
                var adapterSlice = (adapter.MassProcess, adapter.QuickProcessFlow, adapter.AllowRedirect);
                string userName = Base.Accessinfo.UserName;

                PXLongOperation.StartOperation(this, delegate ()
                {
                    bool anyfailed = false;
                    var orderEntry = PXGraph.CreateInstance<SOOrderEntry>();
                    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 object[] { order }))
                            {
                                INSite inSite = INSite.PK.Find(shipmentEntry, plan.SiteID);

                                // AC-144778. We can't use Match<> inside long run operation
                                if (GroupHelper.IsAccessibleToUser(shipmentEntry.Caches[typeof(INSite)], inSite, userName, forceUnattended: true))
                                    sites.Add(plan.SiteID);
                            }
                        }

                        foreach (int? SiteID in sites)
                        {
                            SOOrder ordercopy = PXCache<SOOrder>.CreateCopy(order);
                            try
                            {
                                using (var ts = new PXTransactionScope())
                                {
                                    PXTransactionScope.SetSuppressWorkflow(true);
                                    shipmentEntry.CreateShipment(new CreateShipmentArgs
                                    {
                                        Graph = orderEntry,
                                        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)
                            {
                                PXCache<SOOrder>.RestoreCopy(order, ordercopy);
                                if (!adapterSlice.MassProcess)
                                    throw;

                                order.LastSiteID = SiteID;
                                order.LastShipDate = filter.ShipDate;

                                shipmentEntry.Clear();

                                orderEntry.Clear();
                                orderEntry.Document.Current = order;
                                orderEntry.Document.Cache.MarkUpdated(order, assertError: true);

                                try
                                {
                                    SOOrder.Events.Select(e => e.ShipmentCreationFailed).FireOn(orderEntry, order);
                                    orderEntry.Save.Press();

                                    PXTrace.WriteInformation(ex);
                                    PXProcessing<SOOrder>.SetWarning(ex);
                                }
                                catch (Exception inner)
                                {
                                    PXCache<SOOrder>.RestoreCopy(order, ordercopy);
                                    PXProcessing<SOOrder>.SetError(inner);
                                    anyfailed = true;
                                }
                            }
                            catch (Exception ex)
                            {
                                PXCache<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>(created[0].ShipmentNbr);
                            throw new PXRedirectRequiredException(shipmentEntry, "Shipment");
                        }
                    }

                    if (anyfailed)
                        throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
                });
            }
            return list;
        }

There are two places that new logic is being injected.  1 of the items I can probably do in a different event.  But there is one part that needs to intercept the popup.  I think that is probably why this entire action is being overridden.

 Base.soparamfilter.AskExt(true);

Is there something wrong with the Delegate part of this?  It works in 2023 and the only changes is the actual code copied from the Acumatica source.

I know that this is not a good thing to do, but I think that the previous developer found there was no alternative other than to completely override the source.

Best answer by Joe Schmucker

I just noticed I had protected on the method instead of public.  I just tested and I no longer get the error message.  

at the top of the action, they put in this code to update the ship date on a custom field.

            //-------SK Logic Begins -------
            SOOrder orderRow = this.Base.Document.Current;
            if (orderRow != null)
            {
                SOOrderSSGExt orderExtRow = PXCache<SOOrder>.GetExtension<SOOrderSSGExt>(orderRow);

                if (orderExtRow != null
                        && orderExtRow.UsrShipDate != null)
                {
                    Base.soparamfilter.Current.ShipDate = orderExtRow.UsrShipDate;
                }
            }
            //-------SK Logic Ends -------
 

This is the second thing they did.

comment out the AskExt

                //if (adapter.ExternalCall)
                //    Base.soparamfilter.AskExt(true);

add their own code to AskExt only if all so lines have the same site id.  This was a requirement added by the customer so that shipments only come from one location (I think!)

Since this is a “catch a condition” within the middle of the action, I think that is why it is being completely overridden.

                //-------SK Logic Begins -------
                //If condition added to validate if the grid has more than one SiteID on the SOLines to show the Smartpanel
                if (!AllSOLinesWithSameSiteID())
                {
                    if (adapter.ExternalCall)
                        Base.soparamfilter.AskExt(true);
                }
                else
                {
                    if (Base.soparamfilter.Current.SiteID == null)
                    {
                        throw new PXException(QTCEvents.Messages.DestinationNotIdentified);
                    }
                }
                //-------SK Logic Ends -------

The good news is that I fixed the error by making it public instead of private.

View original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img+6
  • Captain II
  • 548 replies
  • November 7, 2024

What is the code supposed to be doing?


Joe Schmucker
Captain II
Forum|alt.badge.img+2
  • Author
  • Captain II
  • 451 replies
  • Answer
  • November 7, 2024

I just noticed I had protected on the method instead of public.  I just tested and I no longer get the error message.  

at the top of the action, they put in this code to update the ship date on a custom field.

            //-------SK Logic Begins -------
            SOOrder orderRow = this.Base.Document.Current;
            if (orderRow != null)
            {
                SOOrderSSGExt orderExtRow = PXCache<SOOrder>.GetExtension<SOOrderSSGExt>(orderRow);

                if (orderExtRow != null
                        && orderExtRow.UsrShipDate != null)
                {
                    Base.soparamfilter.Current.ShipDate = orderExtRow.UsrShipDate;
                }
            }
            //-------SK Logic Ends -------
 

This is the second thing they did.

comment out the AskExt

                //if (adapter.ExternalCall)
                //    Base.soparamfilter.AskExt(true);

add their own code to AskExt only if all so lines have the same site id.  This was a requirement added by the customer so that shipments only come from one location (I think!)

Since this is a “catch a condition” within the middle of the action, I think that is why it is being completely overridden.

                //-------SK Logic Begins -------
                //If condition added to validate if the grid has more than one SiteID on the SOLines to show the Smartpanel
                if (!AllSOLinesWithSameSiteID())
                {
                    if (adapter.ExternalCall)
                        Base.soparamfilter.AskExt(true);
                }
                else
                {
                    if (Base.soparamfilter.Current.SiteID == null)
                    {
                        throw new PXException(QTCEvents.Messages.DestinationNotIdentified);
                    }
                }
                //-------SK Logic Ends -------

The good news is that I fixed the error by making it public instead of private.


Joe Schmucker
Captain II
Forum|alt.badge.img+2
  • Author
  • Captain II
  • 451 replies
  • November 7, 2024

As usual, I spend hours trying to fix something.  I post a request for help out of despair, and MINUTES after I post for help, I figure it out.  


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings