diff --git a/app/services/bill-runs/setup/determine-financial-year-end.service.js b/app/services/bill-runs/setup/determine-financial-year-end.service.js index cc573b0964..dbe709c51e 100644 --- a/app/services/bill-runs/setup/determine-financial-year-end.service.js +++ b/app/services/bill-runs/setup/determine-financial-year-end.service.js @@ -55,6 +55,7 @@ async function _determineSupplementaryEndYear (regionId, currentFinancialYearEnd 'toFinancialYearEnding' ]) .where('regionId', regionId) + .where('batchType', 'annual') .where('status', 'sent') // NOTE: We would never have an annual bill run with a toFinancialYearEnding greater than the current one in a // 'real' environment. But we often manipulate bill run dates whilst testing to move annual bill runs out of the diff --git a/test/services/bill-runs/setup/determine-financial-year-end.service.test.js b/test/services/bill-runs/setup/determine-financial-year-end.service.test.js index 7d36666360..be972115b9 100644 --- a/test/services/bill-runs/setup/determine-financial-year-end.service.test.js +++ b/test/services/bill-runs/setup/determine-financial-year-end.service.test.js @@ -108,6 +108,23 @@ describe('Bill Runs Setup Determine Financial Year End service', () => { }) }) + describe("and the last 'sent' bill run is not an annual", () => { + beforeEach(async () => { + await BillRunHelper.add({ + batchType: 'two_part_tariff', regionId, status: 'sent', toFinancialYearEnding: currentFinancialYearEnd + }) + await BillRunHelper.add({ + batchType: 'annual', regionId, status: 'sent', toFinancialYearEnding: currentFinancialYearEnd - 1 + }) + }) + + it("ignores the other bill run and returns the financial year end of the first matching 'sent' annual", async () => { + const result = await DetermineFinancialYearEndService.go(regionId, 'supplementary') + + expect(result).to.equal(currentFinancialYearEnd - 1) + }) + }) + // NOTE: This would never happen in a 'real' environment. All regions have 'sent' annual bill runs so a result // would always be found describe("and there is no 'sent' annual bill run for the same region", () => {