Published On: October 26, 2020Categories: MS News, Technical

Introduction

If you have a business requirement that requires a new voucher number to be generated for each posted inventory movement journal line – that means that you would need to make customization to the out-of-the-box functionality for generating vouchers for inventory journals.

Out of the box functionality that we have so far is that a new voucher is being generated on:

  1. Change date: For each different date in the inventory journal lines. Example: If we have an inventory movement journal with 10 lines, 4 lines with date 1/10/2020, and 6 lines with date 4/10/2020, this setup would post the journal and generate 2 voucher numbers: 1 voucher number for the lines with the date 1/10/2020 and 1 voucher number for the lines with the date 4/10/2020.
  2. Change date or item: For each different date or item in the inventory journal lines. Example: If we have an inventory movement journal with 10 lines, 4 lines with item itemnumber1 and 6 lines with item itemnumber2 and all lines having the same date, then this setup would post the journal and generate 2 voucher numbers: 1 voucher number for the lines with the item itemnumber1 and 1 voucher number for the lines with the item itemnumber2.

This is defined in the setup of the inventory journal name:

AX2012: (Inventory management/Setup/Journals/Journal names, inventory/General/Voucher)
D365: (Inventory management/Setup/Journal names/Inventory/General/Voucher)

 

Picture1Picture2

So, this blog post is about how to extend this functionality by enabling the generation of a new voucher per journal line.

Example: We have 10 lines in the inventory movement journal, and we want to generate 10 different vouchers -one voucher per journal line.

Step-by-step instructions for AX2012

  1. The first step is to extend the enum InventJournalVoucherChange and add a new option ‘Line change’:Picture3After this step, we should be able to select ‘Line change’ as an option in the inventory journal name setup:

    Picture4

  2. Then we should modify the class InventJournalTransData and override the initVoucher method. This method is the place where we can control the voucher number generation for each journal line.Step 2
  3. Now, we want to keep the same logic for voucher numbers when the setup is ‘Change date’ or ‘Change date or item’.
    For that purpose, we need to copy the code from the \Classes\JournalTransData\initVoucher and add it in case the setup is ‘Change date’ or ‘Change date or item’. In case the setup is our new option ‘Line change’, then we need to add a code that will generate the new voucher number.
    After these changes the initVoucher method on the InventJournalTransData should look something like below:Step 3
  1. Now, when we create an inventory movement journal with 10 lines and post the journal, we will see 10 different vouchers created for each journal line.

Step-by-step instructions for D365

 

  1. The first step is to create an extension of the enum InventJournalVoucherChange and add a new option ‘Line change’:Picture aAfter this step, we should be able to select ‘Line change’ as an option in the inventory journal name setup:

    Picture b

  2. Then we should create an extension of the class InventJournalTransData and using Chain of command we will add the new initVoucher method.
    Please note that this solution needs to call the super() (next call) and for that reason is going to create a new voucher number in the super call, and then we are going to override that voucher number with a new one.Picture c
  3. Now, when we create an inventory movement journal with 10 lines and post the journal, we will see 10 different vouchers created for each journal line.