1
votes

Good day

I am looking for a way to override the function ProcessItemBarcode(string Barcode) inside public class INScanReceive : WMSBase

The idea is to extend the INScanReceiveHost graph and manipulate the barcode before it is processed. This is to change how the Scan and Receive page scan'sa barcodes so that I can read and manipulate QR codes

namespace PX.Objects.IN
{

    // Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
    public class INScanReceiveHost_Extension : PXGraphExtension<INScanReceive>
    {
        #region Event Handlers
        [PXOverride]
        public virtual void ProcessItemBarcode(string barcode)
        {
            //change barcode
            Base.ProcessItemBarcode.Invoke(barcode);
        }
        #endregion
    }
}

But It telling me i can't access the function?

Update 2021/06/15

Thanks Sean Prouty for your help so far. I am getting very close to a solution.

I have a follow-up question.

I have overridden the ProcessItemBarcode function and ProcessLotSerialBarcode

Question: Can I call ProcessLotSerialBarcode from ProcessItemBarcode because I have the location from the QR code I can set it from the first scan:

#region Overrides ProcessItemBarcode
//ProcessItemBarcode
public delegate void ProcessItemBarcodeDelegate(string barcode);

[PXOverride]
public virtual void ProcessItemBarcode(string barcode, ProcessItemBarcodeDelegate baseMethod)
{
    try
    {
        string inventoryBC = barcode;
        //...//get InvetoryID using Barcode
        baseMethod?.Invoke(inventoryBC);

        //how do you call the ProcessLotSerialBarcode function?
        ProcessLotSerialBarcode(barcode,  ProcessLotSerialBarcodeDelegate);
    }
    catch (Exception ex)
    {//TODO: check if not a QR code  
        PXTrace.WriteError("ProcessItemBarcode Override: " + ex.Message);
        baseMethod?.Invoke(barcode);
    }
}
#endregion

#region Overrides ProcessLotSerialBarcode
//ProcessLotSerialBarcode
public delegate void ProcessLotSerialBarcodeDelegate(string barcode);

[PXOverride]
public virtual void ProcessLotSerialBarcode(string barcode, ProcessLotSerialBarcodeDelegate baseMethod)
{
    try
    {
        string inventoryBC = "LOgic";
        baseMethod?.Invoke(inventoryBC);
    }
    catch (Exception)
    {
        //TODO: check if not a QR code  
        baseMethod?.Invoke(barcode);
    }

}
#endregion


    [PXProtectedAccess]
public abstract class INScanReceiveHostExtProtectedAccess : PXGraphExtension<INScanReceiveHostExtCustomPackage, INScanReceive, INScanReceiveHost>
{
    [PXProtectedAccess(typeof(INScanReceive))]
    protected abstract void ProcessItemBarcode(string barcode);

    [PXProtectedAccess(typeof(INScanReceive))]
    protected abstract void ApplyState(string state);

    [PXProtectedAccess(typeof(INScanReceive))]
    protected abstract void ProcessLotSerialBarcode(string barcode);
}

I was also thinking of setting the state from the first method but then I need to call

Base.ApplyState(INScanIssue.ScanStates.Confirm);

Then I can set the Header and just keep resetting the scanner to the Confirm state. What do you think?

1

1 Answers

3
votes

Because the method you are trying to override is protected, and not public, you will need to override the logic in a different way using the PXProtectedAccess attribute and an abstract graph extension.

namespace MyCustomPackage.Graph.Extension
{
    public class INScanReceiveHostExtCustomPackage : PXGraphExtension<INScanReceive, INScanReceiveHost>
    {
        public static bool IsActive() => true;

        #region Overrides

        public delegate void ProcessItemBarcodeDelegate(string barcode);

        [PXOverride]
        public virtual void ProcessItemBarcode(string barcode, ProcessItemBarcodeDelegate baseMethod)
        {
            PXTrace.WriteInformation("Running abstract override");
            baseMethod?.Invoke(barcode);

        }

        #endregion
    }


    [PXProtectedAccess]
    public abstract class INScanReceiveHostExtProtectedAccess : PXGraphExtension<INScanReceiveHostExtCustomPackage, INScanReceive, INScanReceiveHost>
    {
        [PXProtectedAccess(typeof(INScanReceive))]
        protected abstract void ProcessItemBarcode(string barcode);        
    }
}

I didn't have a good way to test this unfortunately, so you may need to tweak the type that is being passed to the PXProtectedAccess attribute above the abstract method. If this doesn't work, try passing the INScanReceiveHost type to the attribute and see if that works for you.