Barcode Scan Class: To Create a Barcode Scan Class
This activity will walk you through the process of creating a barcode scan class.
Story
Suppose that you need to create a barcode-driven version of the Physical Inventory Review (IN305000) form. The form should have only one scan mode. For this form, you need to define a barcode scan class and configure this mode.
Process Overview
You will define the INScanCount
barcode scan class as a descendant
of the WarehouseManagementSystem<TSelf,TGraph> base scan
class.
In the INScanCount
class, you will create a host class as an empty
descendant for INPICountEntry, the graph object of the Physical Inventory Review (IN305000) form.
You will then implement the CreateScanModes()
abstract
method of the base class to make the barcode scan class
usable. In the method, you will use the yield return
construction
to avoid array creation.
System Preparation
Before you begin performing the steps of this activity, you need to prepare an MYOB Acumatica instance and the PhoneRepairShop customization project by performing the Test Instance: To Deploy an Instance prerequisite activity.
Step 1: Creating a Barcode Scan Class
To create a barcode scan class, do the following:
- In the
PhoneRepairShop_Code
Visual Studio project, add a reference to the PX.BarcodeProcessing.dll file. - Create the
INScanCount
class and make itpublic
. - Add the
using
directives shown in the following code to the file.using PX.BarcodeProcessing; using PX.Objects.IN; using PX.Objects.IN.WMS;
- In the
INScanCount
class, add a host class to apply the barcode scan class to, as shown in the following code.public class INScanCount { public class Host : INPICountEntry { } }
- To simplify referencing the nested components of the barcode scan class, add the
following line before the
INScanCount
class declaration. The WarehouseManagementSystem<TSelf,TGraph> class is a descendant of the BarcodeDrivenStateMachine<TSelf, TGraph> class, which contains warehouse-related logic and components.using WMSBase = WarehouseManagementSystem<INScanCount, INScanCount.Host>;
- Derive the
INScanCount
class fromWMSBase
. The following code shows the result of this step.using PX.BarcodeProcessing; using PX.Objects.IN; using PX.Objects.IN.WMS; namespace PhoneRepairShop { using WMSBase = WarehouseManagementSystem<INScanCount, INScanCount.Host>; public class INScanCount: WMSBase { public class Host : INPICountEntry { } } }
- Fix or suppress the PX1016 error that is displayed by Acuminator.
Step 2: Making the Barcode Scan Class Usable
To make the barcode scan class usable, do the following:
- Add the
using
directives shown in the following code to the file.using System.Collections.Generic; using PX.Data;
- To make the barcode-driven part of the graph extension work, implement the
CreateScanModes() abstract method as follows.
public class INScanCount : WMSBase { ... protected override IEnumerable<ScanMode<INScanCount>> CreateScanModes() { yield return new CountMode(); } }
Tip: You will implement theCountMode
scan mode in Barcode Scan Mode: To Define the Required Properties. - To facilitate access to the important members of the host graph, add the
following
members.
public class INScanCount : WMSBase { ... public virtual INPIHeader Document => DocumentView.Current; public virtual PXSelectBase<INPIHeader> DocumentView => Graph.PIHeader; public virtual PXSelectBase<INPIDetail> Details => Graph.PIDetail; ... }
- Add the following supplementary method, which will be reused in further
implementation of the custom barcode-driven
form.
public class INScanCount : WMSBase { ... protected virtual bool IsDocumentStatusEditable(string status) => status == INPIHdrStatus.Counting; ... }
- To define when the document with which the barcode scan class works can be
edited by the barcode processing, override the
DocumentIsEditable member of the
WMSBase
class.public class INScanCount : WMSBase { ... public override bool DocumentIsEditable => base.DocumentIsEditable && IsDocumentStatusEditable(Document.Status); ... }