Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude VOID returns from two-part tariff billing #1419

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}` }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})`)
}
Expand All @@ -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}`
}

Expand All @@ -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 '/'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 })
Expand All @@ -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
}
}
Loading