EricP.
EricP.

Reputation: 489

Confirming Shipment when Create Shipment called in Acumatica 2017 R2

I used the solution from this question to confirm shipments when the user clicked Create Shipment in version 6.x.

Auto confirm shipment when create shipment from Sales Order by Automation Step

I have since upgraded to the latest version, but this logic seems to no longer work when clicking Create Shipment. Instead when the line while (PXLongOperation.GetStatus(Base.UID, out timespan, out ex) == PXLongRunStatus.InProcess) { } is called, when the segment PXLongOperation.GetStatus(Base.UID, out timespan, out ex) is observed in the Watch window, it returns DoesNotExist. The shipment continues to create a normal shipment that is no longer confirmed.

Upvotes: 0

Views: 646

Answers (1)

EricP.
EricP.

Reputation: 489

This seems to have worked for me (also includes executing Update IN action):

    public delegate void CreateShipmentDelegate(SOOrder order, int? SiteID, DateTime? ShipDate, bool? useOptimalShipDate, string operation, DocumentList<SOShipment> list);
    [PXOverride]
    public virtual void CreateShipment(SOOrder order, int? SiteID, DateTime? ShipDate, bool? useOptimalShipDate, string operation, DocumentList<SOShipment> list, CreateShipmentDelegate baseMethod)
    {
        baseMethod(order, SiteID, ShipDate, useOptimalShipDate, operation, list);
        var shipment = Base.Document.Current;

        if (shipment.Hold == true)
        {
            shipment.Hold = false;
            //shipment Status must be set to null to apply 'New Open' Automation Step
            shipment.Status = null;
            shipment = Base.Document.Update(shipment);
            if (shipment.Hold == true || shipment.Status == SOShipmentStatus.Hold)
            {
                throw new PXException("Shipment {0} cannot be taken off Hold", shipment.ShipmentNbr);
            }
        }

        shipment.ShipDate = shipment.ShipDate.Value.AddDays(1);
        Base.Document.Update(shipment);
        Base.Actions.PressSave();


        //Here you can add your custom logic

        //Call Confirm Shipment
        foreach (var shipmentAction in (Base.action.GetState(shipment) as PXButtonState).Menus)
        {
            if (shipmentAction.Command == "Confirm Shipment")
            {
                PXAdapter shipmentAdapter = new PXAdapter(
                    new DummyView(Base, Base.Document.View.BqlSelect,
                        new List<object> { shipment }));
                shipmentAdapter.Menu = shipmentAction.Command;
                //to invoke Confirm Shipment action
                Base.action.Press(shipmentAdapter).RowCast<SOShipment>().ToList();
            }
        }

        //Execute UpdateIN
        Base.UpdateIN.Press();

    }
    internal class DummyView : PXView
    {
        List<object> _Records;
        internal DummyView(PXGraph graph, BqlCommand command, List<object> records)
            : base(graph, true, command)
        {
            _Records = records;
        }
        public override List<object> Select(object[] currents, object[] parameters, object[] searches, string[] sortcolumns, bool[] descendings, PXFilterRow[] filters, ref int startRow, int maximumRows, ref int totalRows)
        {
            return _Records;
        }
    }

Upvotes: 2

Related Questions