2
votes

I need to work with the reusable business objects for Sales tax, discounts, etc. and need to override some of the methods in these graph extensions. For example I am starting with the Opportunities graph. I have a set of order totals that need to calculate into the overall products amount and in the past we just overrode the tax attribute on (I think) tax category. Anyhow I don't see how its possible to use the PXOverrideAttribute on a method from a second level graph extension.

Here is my example:

public class OpportunityMaintExtOne : PXGraphExtension<PX.Objects.CR.OpportunityMaint.SalesTax, PX.Objects.CR.OpportunityMaint>
{ 
    [PXOverride]
    public virtual void CalcDocTotals(object row, decimal CuryTaxTotal, decimal CuryInclTaxTotal, decimal CuryWhTaxTotal,
        Action<object, decimal, decimal, decimal> del)
    {
        del?.Invoke(row, CuryTaxTotal, CuryInclTaxTotal, CuryWhTaxTotal);

        var someOtherTotal = Base1.Documents.Cache.GetValueAsDecimal<CROpportunityExtension.aMCurySomeOtherTotal>(row);
        if (someOtherTotal == 0)
        {
            return;
        }

        var curyDocTotal = someOtherTotal + Base1.Documents.Cache.GetValueAsDecimal<CROpportunity.curyProductsAmount>(row);
        Base1.Documents.Cache.SetValue<CROpportunity.curyProductsAmount>(row, curyDocTotal);
    }
}

What is going on inside of CalcDocTotals in my graph extension is not the focus. It is the fact that I cannot override the OpportunityMaint.SalesTax CalcDocTotals method as I could if the method was in the first level (Base) graph. The SalesTax graph extension has the method as protected but protected methods (if it was in the base graph) are overrideable using the PXOverrideAttribute if you make your method call public which is what I have done. I also tried using a declared delegate in place of the Action but same results (as I expected but wanted to confirm).

My question: Is it possible to override a second, third, etc. level graph extension method using the PXOverrideAttribute?

When I compile the code above and the page loads I get this error:

Method Void CalcDocTotals(System.Object, System.Decimal, System.Decimal, System.Decimal, System.Action`4[System.Object,System.Decimal,System.Decimal,System.Decimal]) in graph extension is marked as [PXOverride], but the original method with such name has not been found in PXGraph

2
I think currently the system is trying to find the CalcDocTotals in the OpportunityMaint graph.But that is only one of the several problems. The second problem is that CalcDocTotals is member of the abstract class and in the SalesTax graph it is protected and just overrode.Samvel Petrosov
As an idea I can suggest to try to implement the TaxGraph abstract class and at some point replace the SalesTax with itSamvel Petrosov
The problem is that Acumatica is already declaring the use of SalesTax. If we declare it again I would assume we would get a double execution/results.Brendan

2 Answers

3
votes

The ability to override extension methods from a higher level extension has been added in 2018R1 Update 4 (18.104.0023). This resolves my question/issue and allows for the code posted in my question to function as is.

0
votes

You cannot override methods from Extension1 in Extension2 etc as far as I've been able to see in my years with Acumatica. My solution to the problem was thus : Create a helper graph with your basic methodology, create a field or property for it in whatever graph you wish to use it in (Preferably a Lazy initialized one), then in whatever project you must override the logic on, just reference your original project, and create an extension of your helper graph.