Search code examples
acumatica

Overriding Action that is declared in generic graph extension


I have a customization in place that tweaks the ShopRates action on SO Order Entry by overriding that action. 

In 2018 R2, the ShopRates action was declared directly on the SOOrderEntry graph, so to override the action, we simply had to do the following. 

    public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
    {
       public PXAction<SOOrder> shopRates;
       [PXUIField(DisplayName = "Shop for Rates", MapViewRights = PXCacheRights.Select, MapEnableRights = PXCacheRights.Update)]
       [PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntryF)]
       protected virtual IEnumerable ShopRates(PXAdapter adapter)
       {
          Base.shopRates.Press(adapter);
          // custom code
          return adapter.Get();
       }
    }

In 2019 R1, however, the ShopRates action has been moved to CarrierRatesExtension, which is a generic graph extension used on the SOOrderEntry graph by  

public CarrierRates CarrierRatesExt => FindImplementation<CarrierRates>();
public class CarrierRates : CarrierRatesExtension<SOOrderEntry, SOOrder>
{
    . . .     
}

Now that the ShopRates action is no longer defined directly on the SOOrderEntry graph, how can I override it in my SOOrderEntry Extension?


Solution

  • The ShopRates method is defined in the CarrierRatesExtension class which is PXGraphExtension, but the problem is that this class is abstract and has abstract GetCarrierRequest method. So if you create an extension of it you will have to implement also GetCarrierRequest method. But if you review the sources of the SOOrderEntry you will find the nested CarrierRates which inherited from CarrierRatesExtension class and already implements everything that you need. So you need to create a PXGraphExtension of the SOOrderEntry and SOOrderEntry.CarrierRates, because SOOrderEntry.CarrierRates is still PXGraphExtension.

    Below is an example how to override the ShopRates method:

    using PX.Data;
    using PX.Objects.SO;
    using System;
    using System.Collections;
    namespace Test
    {
        public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry.CarrierRates, SOOrderEntry>
        {
            [PXOverride()]
            public virtual IEnumerable ShopRates(PXAdapter adapter,Func<PXAdapter,IEnumerable> baseMethod)
            {
                throw new NotImplementedException("This code overrides shop rates method and is not implemented yet!!");
                var retVal = baseMethod?.Invoke(adapter);
                return retVal;
            }
        }
    }