How To Override Buildtaxrequest Method Of Apinvoiceentryexternaltax Class

 

Hello everybody,

today I want to leave a short techy post on how to override method BuildTaxRequest of APInvoiceEntryExternalTax class.

public class APInvoiceEntryExternalTaxExtPXGraphExtension<APInvoiceEntryExternalTaxAPInvoiceEntry>
{
    [PXOverride]
    protected virtual GetTaxRequest BuildTaxRequest(APInvoice invoiceFunc<APInvoiceGetTaxRequestbaseAction)
    {
        var result = baseAction(invoice);
        //Your code
 
        return result;
    }
}

Reason for such a behavior is a fact that class APInvoiceEntryExternalTax is graph extension for graph. That's why such a construction is needed.

 

How To Overrde Authorize Cc Payment Action In Acumatica

 

Hello everybody,

as it was mentioned in one of my previous blog posts, regarding overriding base actions of Acumatica graphs, family of graph extensions grows and grows. 

 

Today I want to share one more code snippet which you can use for extending modification of Acumatica actions. Below goes code fragment, which you can use for modification of Authorize CC Payment:

public class PaymentTransactionExt : PXGraphExtension<PaymentTransactionSOOrderEntry>
{
    [PXOverride]
    public virtual IEnumerable AuthorizeCCPayment(PXAdapter adapterFunc<PXAdapterIEnumerablebaseFunc)
    {
        
        var result = baseFunc(adapter);
        
        return result;
    }
}

Of what I foresee now, is a loooooot of work for Acumatica developers upgrading to a newer versions of Acumatica. 

Why I say so? 

Because as usually ISV have their code in SOOrderEntry extensions. But now they either will need to move their code from SOOrderEntry extensions or for example to reference Base1 ( which is your extension ) as well as Base.

Reason why Acumatica does this is probably following few general programming principles of: SRP ( single responsibility principle ), DRY ( Dont Repeat Yourself ) principle, Open Closed principle on graph level, which in long term will bring more stability to the system.

Basic advice will be this, don't expect that upgrade of your code base to 2019 R2 will be as fast, as it used to be in the past, and before giving estimate which you used to give, pay special attention to how new actions are declared.

 

 

How To Override Shoprates Action In Sales Orders Form

 

Hello everybody,

today I want to leave a short post on how to override Shop rates Action in Acumatica. 

I mean this button:

Below goes C# code, with which you can achieve it:

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry.CarrierRatesSOOrderEntry>
{
    [PXOverride()]
    public virtual IEnumerable ShopRates(PXAdapter adapterFunc<PXAdapterIEnumerablebaseMethod)
    {
        //your code here
        var retVal = baseMethod?.Invoke(adapter);
        //and possibly here
        return retVal;
    }
}

As you can see from the code, life in Acumatica becomes more complex, and if in the past you've used to override directly your actions, now you'll need to create extension for extension in order to override some Actions. 

Similar issues I've seen in other places of SOOrderEntry, for example in AuthorizeCCPayment, CaptureCCPayment, etc.

 

How To Override Properly Createpaymentproc Method Of Soorderentry Graph In Acumatica

 

Hello everybody,

today I want to leave short note on how to override and call CreatePaymentProc method of Acumatica which I discovered today with Naveen from Kensium.

My favorite way of overriding methods in Acuamtica with usage of Action and passing there parameters doesn't work. That is because Acumatica uses in method CreatePaymentProc out modifier. Due to this, delegate declaration is needed. 

After some efforts and refactorings we found following code that is working:

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
    public delegate void CreatePaymentBase(SOOrder order, out PXGraph target, string paymentType);
 
    [PXOverride]
    public virtual void CreatePaymentProc(SOOrder order, out PXGraph target, string paymentType,
        CreatePaymentBase baseAction)
    {
        baseAction(order, out target, paymentType);
 
        var resultGraph = target as ARPaymentEntry;
        resultGraph.Document.Current.ExtRefNbr = "12xx14";
    }
}

With such code you can call base method, and modify what it produces.

Override Equals Method Of Value Types

 

Hello everybody.

Today I want to give some demo.

using System;
using System.Diagnostics;

namespace StackOverflowQuest
{
    class Program
    {
        struct StructTest
        {
            public string TestString { get; set; }

            //public override bool Equals(object obj)
            //{
            //    var ct = (StructTest)obj;
            //    return ct.TestString == this.TestString;
            //}
        }
        class ClassTest
        {
            public string TestString { get; set; }

            public override bool Equals(object obj)
            {
                var ct = obj as ClassTest;
                if (ct == null)
                    return false;
                return ct.TestString == this.TestString;
            }
        }

        static void Main(string[] args)
        {
            StructTest st = new StructTest() { TestString = "water"};
            StructTest st2 = new StructTest() { TestString = "water" };

            ClassTest ct1 = new ClassTest() { TestString = "water" };
            ClassTest ct2 = new ClassTest() { TestString = "water" };

            int numberOfIterations = 500000;

            Stopwatch sw2 = new Stopwatch();
            sw2.Start();
            for (int i = 0; i < numberOfIterations; i++)
            {
                ct1.Equals(ct2);
            }
            sw2.Stop();
            Console.WriteLine("class perfomance = {0} Elapsed Milliseconds", sw2.ElapsedMilliseconds);

            Stopwatch sw1 = new Stopwatch();
            sw1.Start();
            for(int i = 0; i < numberOfIterations; i++)
            {
                st.Equals(st2);
            }
            sw1.Stop();
            Console.WriteLine("structs perfomance = {0}  Elapsed Milliseconds", sw1.ElapsedMilliseconds);
            Console.ReadKey();
        }
    }
}

Take note of commented method of Equals method. If I execute that code on my machine, I'm getting difference in perfomance in 6 times. But if to uncomment Equals, then class and struct have comparable perfomance.

No Comments

 

Add a Comment