From 29eea30e6250cc61abc333ac270daffeaeeed836 Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Thu, 17 Oct 2024 12:29:35 +0100 Subject: [PATCH] Exclude VOID returns from two-part tariff billing (#1419) https://eaflood.atlassian.net/browse/WATER-4709 > Part of our work implementing SROC two-part tariff billing A request has come from our users after testing the current iteration of reviewing the matches and allocations for a two-part tariff return. They are satisfied we don't include VOID return logs in the allocation results. But they would rather we exclude them from the process completely. Then, we wouldn't see them in the results, as they seem to make things confusing. This change excludes VOID return logs (returns that have been replaced because of changes) from the two-part tariff match and allocate process. --------- Co-authored-by: Jason Claxton Co-authored-by: Becky Ransome --- .../match-details.presenter.js | 2 +- .../review-licence.presenter.js | 6 +- .../fetch-return-logs-for-licence.service.js | 1 + .../review-licence.presenter.test.js | 31 -------- ...ch-return-logs-for-licence.service.test.js | 79 +++++++++---------- 5 files changed, 43 insertions(+), 76 deletions(-) diff --git a/app/presenters/bill-runs/two-part-tariff/match-details.presenter.js b/app/presenters/bill-runs/two-part-tariff/match-details.presenter.js index e18911c792..6b29fde8eb 100644 --- a/app/presenters/bill-runs/two-part-tariff/match-details.presenter.js +++ b/app/presenters/bill-runs/two-part-tariff/match-details.presenter.js @@ -119,7 +119,7 @@ function _prepareDate (startDate, endDate) { function _returnLinkAndTotal (returnLog) { const { returnStatus, allocated, quantity } = returnLog - if (['due', 'received', 'void'].includes(returnStatus)) { + if (['due', 'received'].includes(returnStatus)) { return { returnTotal: '/', returnLink: `/return/internal?returnId=${returnLog.returnId}` } } diff --git a/app/presenters/bill-runs/two-part-tariff/review-licence.presenter.js b/app/presenters/bill-runs/two-part-tariff/review-licence.presenter.js index 7afe4a94ee..fe6d88c542 100644 --- a/app/presenters/bill-runs/two-part-tariff/review-licence.presenter.js +++ b/app/presenters/bill-runs/two-part-tariff/review-licence.presenter.js @@ -250,8 +250,6 @@ function _prepareReturnVolume (reviewChargeElement) { reviewReturns.forEach((reviewReturn) => { if (reviewReturn.returnStatus === 'due') { returnVolumes.push(`overdue (${reviewReturn.returnReference})`) - } else if (reviewReturn.returnStatus === 'void') { - returnVolumes.push(`void (${reviewReturn.returnReference})`) } else { returnVolumes.push(`${reviewReturn.quantity} ML (${reviewReturn.returnReference})`) } @@ -262,7 +260,7 @@ function _prepareReturnVolume (reviewChargeElement) { } function _returnLink (returnLog) { - if (['due', 'received', 'void'].includes(returnLog.returnStatus)) { + if (['due', 'received'].includes(returnLog.returnStatus)) { return `/return/internal?returnId=${returnLog.returnId}` } @@ -284,7 +282,7 @@ function _returnStatus (returnLog) { function _returnTotal (returnLog) { const { returnStatus, allocated, quantity } = returnLog - if (['due', 'received', 'void'].includes(returnStatus)) { + if (['due', 'received'].includes(returnStatus)) { return '/' } diff --git a/app/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.js b/app/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.js index 90cdc36cc0..ee274d1425 100644 --- a/app/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.js +++ b/app/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.js @@ -44,6 +44,7 @@ async function _fetch (licenceRef, billingPeriod) { // water-abstraction-service filters out old return logs in this way: see // `src/lib/services/returns/api-connector.js` .where('startDate', '>=', '2008-04-01') + .whereNot('status', 'void') .where('endDate', '>=', billingPeriod.startDate) .where('endDate', '<=', billingPeriod.endDate) .whereJsonPath('metadata', '$.isTwoPartTariff', '=', true) diff --git a/test/presenters/bill-runs/two-part-tariff/review-licence.presenter.test.js b/test/presenters/bill-runs/two-part-tariff/review-licence.presenter.test.js index 5327857b19..6af47d7ffe 100644 --- a/test/presenters/bill-runs/two-part-tariff/review-licence.presenter.test.js +++ b/test/presenters/bill-runs/two-part-tariff/review-licence.presenter.test.js @@ -178,37 +178,6 @@ describe('Review Licence presenter', () => { expect(result.matchedReturns[0].returnLink).to.equal('/return/internal?returnId=v1:1:01/60/28/3437:17061181:2022-04-01:2023-03-31') }) }) - - describe('when a return has a status of "void"', () => { - beforeEach(() => { - licence[0].reviewReturns[0].returnStatus = 'void' - licence[0].reviewChargeVersions[0].reviewChargeReferences[0].reviewChargeElements[0].reviewReturns[0].returnStatus = 'void' - }) - - it('changes the status text to "void"', () => { - const result = ReviewLicencePresenter.go(billRun, licence) - - expect(result.matchedReturns[0].returnStatus).to.equal('void') - }) - - it('formats the returns total correctly', () => { - const result = ReviewLicencePresenter.go(billRun, licence) - - expect(result.matchedReturns[0].returnTotal).to.equal('/') - }) - - it('formats the charge elements return total correctly', () => { - const result = ReviewLicencePresenter.go(billRun, licence) - - expect(result.chargeData[0].chargeReferences[0].chargeElements[0].returnVolume).to.equal(['void (10031343)']) - }) - - it('formats the returns link correctly', () => { - const result = ReviewLicencePresenter.go(billRun, licence) - - expect(result.matchedReturns[0].returnLink).to.equal('/return/internal?returnId=v1:1:01/60/28/3437:17061181:2022-04-01:2023-03-31') - }) - }) }) describe('the "underQuery" property', () => { diff --git a/test/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.test.js b/test/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.test.js index cfb4638d85..785102853d 100644 --- a/test/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.test.js +++ b/test/services/bill-runs/two-part-tariff/fetch-return-logs-for-licence.service.test.js @@ -21,26 +21,7 @@ describe('Fetch Return Logs for Licence service', () => { describe('when there are valid return logs that should be considered', () => { beforeEach(async () => { - const metadata = { - nald: { - periodEndDay: '31', - periodEndMonth: '3', - periodStartDay: '1', - periodStartMonth: '4' - }, - purposes: [ - { - tertiary: { - code: '400', - description: 'Spray Irrigation - Direct' - } - } - ], - description: 'The Description', - isTwoPartTariff: true - } - - returnLogRecord = await ReturnLogHelper.add({ metadata }) + returnLogRecord = await ReturnLogHelper.add({ metadata: _metadata(true) }) }) describe('which have return submission lines within the billing period', () => { @@ -205,26 +186,7 @@ describe('Fetch Return Logs for Licence service', () => { describe('because the return log is not two-part-tariff', () => { beforeEach(async () => { - const metadata = { - nald: { - periodEndDay: '31', - periodEndMonth: '3', - periodStartDay: '1', - periodStartMonth: '4' - }, - purposes: [ - { - tertiary: { - code: '400', - description: 'Spray Irrigation - Direct' - } - } - ], - description: 'The Description', - isTwoPartTariff: false - } - - returnLogRecord = await ReturnLogHelper.add({ metadata }) + returnLogRecord = await ReturnLogHelper.add({ metadata: _metadata(false) }) const { id } = returnLogRecord await ReturnSubmissionHelper.add({ returnLogId: id }) @@ -245,5 +207,42 @@ describe('Fetch Return Logs for Licence service', () => { expect(result).to.have.length(0) }) }) + + describe('because the return is void', () => { + beforeEach(async () => { + returnLogRecord = await ReturnLogHelper.add({ metadata: _metadata(true), status: 'void' }) + const { id } = returnLogRecord + + await ReturnSubmissionHelper.add({ returnLogId: id }) + }) + + it('returns no records', async () => { + const { licenceRef } = returnLogRecord + const result = await FetchReturnLogsForLicenceService.go(licenceRef, billingPeriod) + + expect(result).to.have.length(0) + }) + }) }) }) + +function _metadata (isTwoPartTariff) { + return { + nald: { + periodEndDay: '31', + periodEndMonth: '3', + periodStartDay: '1', + periodStartMonth: '4' + }, + purposes: [ + { + tertiary: { + code: '400', + description: 'Spray Irrigation - Direct' + } + } + ], + description: 'The Description', + isTwoPartTariff + } +}