3

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?

abulger
  • 71
  • 9

3 Answers3

6

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;
        }
    }
}
Samvel Petrosov
  • 7,580
  • 2
  • 22
  • 46
0

You should be create child class from CarrierRates class.

public class SOOrderEntryEx : PXGraphExtension<SOOrderEntry>
{
    public class CarrierRatesExt : SOOrderEntry.CarrierRates
    {
        protected override IEnumerable ShopRates(PXAdapter adapter)
        {
            return base.ShopRates(adapter); 
        }
    }
}
Vardan Vardanyan
  • 649
  • 5
  • 12
  • I have tried override with child class, but it didn't help – Yuriy Zaletskyy Oct 21 '19 at 08:23
  • @vardan Unfortunately, this isn't working for me either. I added this code to my extension with a breakpoint, and the breakpoint is not getting hit when I click the Shop for Rates button on the SO Entry screen. Any suggestions? – abulger Oct 21 '19 at 20:01
0

I found the following works when there is a workflow extension for actions such as Approve which are declared in the Graph extension and the delegate is implemented in Attribute.cs

#5 did not work for me - returned a null object exception.

using PX.Data; using System.Collections;

namespace PX.Objects.EP
{

public class TimeCardMaint_ApprovalWorkflow_ext : PXGraphExtension<TimeCardMaint_ApprovalWorkflow, TimeCardMaint>
{
    #region Action Overrides
   
    public PXAction<EPTimeCard> approve;
    [PXButton(CommitChanges = true), PXUIField(DisplayName = "Approve")]       
    protected virtual IEnumerable Approve(PXAdapter adapter)
    {
                   
        Base1.approve.Press(adapter);

        // custom code here

        return adapter.Get();

    }

    #endregion

}

}