The initateBeginningBalance method in this service gets a list of periods earlier than the requisition's period start date (previous periods), takes the first one in the list, and assumes it is the most recent previous period. This assumption seems to be incorrect, as the external call orders the previous periods by start date ascending. So the first one in the list would be least recent previous period.
Refactor the code that gets the previous requisition to use the most recent previous period to determine the previous requisition
Create two previous periods with different balances and check requisition uses the correct previous period to initiate a beginning balance
I added missing requisition line items. You should be able to test this ticket by simple creating new requisition for program: dce17f2e-af3e-40ad-8e00-3496adef44c3, facility: e6799d64-d10d-4011-b8c2-0e4d4a3f65ce and emergency: false
Asked to update demo data to have two previous periods with line items for same products with different amounts of stock on hand. Then tested initiating a new requisition for the next processing period and verified that the beginning balance matches the most recent previous requisition, not the older one. Passed, so this is done.