Skip to content

Commit

Permalink
Add pre sroc returns flagging to service (#1335)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4199
https://eaflood.atlassian.net/browse/WATER-4676

During testing for the first ticket, it was discovered that editing a return on a licence and then flagging that licence for supplementary billing, was always flagging the licence for pre-sroc supplementary billing even when the years were for sroc.

After discussions it was determined that editing a return should only be able to add a flag on a licence for either pre-sroc billing OR two-part tariff supplementary billing.
This is because regular sroc supplementary billing doesn't look at the returns, so editing a return won't change anything on the bill run.
This PR adds an additional check on the determine-return-log-years service to check if the return has a start date before the SROC start date. If it does we add the flag on the licence for pre-sroc supplementary billing.
  • Loading branch information
Beckyrose200 authored Sep 24, 2024
1 parent c8f5559 commit 1c3ba4b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const { ref } = require('objection')

const ReturnLogModel = require('../../../models/return-log.model.js')
const LicenceModel = require('../../../models/licence.model.js')

const SROC_START_DATE = new Date('2022-04-01')

Expand All @@ -34,7 +35,14 @@ async function go (returnLogId) {
flagForBilling: false
}

if (startDate < SROC_START_DATE) {
// As the returns start date is before the SROC start date, we need to flag the return for pre sroc billing
await _flagLicenceForPreSrocSupplementary(licence.id)
}

if (endDate < SROC_START_DATE) {
// If the end date of the return is before the start of SROC then we do not need to flag the licence for sroc
// supplementary billing
return result
}

Expand Down Expand Up @@ -63,6 +71,12 @@ async function _fetchReturnLog (returnLogId) {
})
}

async function _flagLicenceForPreSrocSupplementary (licenceId) {
return LicenceModel.query()
.patch({ includeInPresrocBilling: 'yes' })
.where('id', licenceId)
}

module.exports = {
go
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { expect } = Code

// Test helpers
const LicenceHelper = require('../../../support/helpers/licence.helper.js')
const LicenceModel = require('../../../../app/models/licence.model.js')
const ReturnLogHelper = require('../../../support/helpers/return-log.helper.js')

// Thing under test
Expand Down Expand Up @@ -44,6 +45,14 @@ describe('Determine Return Log Years Service', () => {
expect(result.flagForBilling).to.equal(false)
expect(result.twoPartTariff).to.equal(false)
})

it('does not flag the licence for pre sroc supplementary billing', async () => {
await DetermineReturnLogYearsService.go(returnLog.id)

const result = await LicenceModel.query().select(['includeInPresrocBilling']).where('id', licence.id)

expect(result[0].includeInPresrocBilling).to.equal('no')
})
})

describe('and two-part tariff is true', () => {
Expand Down Expand Up @@ -77,6 +86,14 @@ describe('Determine Return Log Years Service', () => {
expect(result.flagForBilling).to.equal(false)
expect(result.twoPartTariff).to.equal(true)
})

it('flags the licence for pre sroc supplementary billing', async () => {
await DetermineReturnLogYearsService.go(returnLog.id)

const result = await LicenceModel.query().select(['includeInPresrocBilling']).where('id', licence.id)

expect(result[0].includeInPresrocBilling).to.equal('yes')
})
})

describe('and the end date is after the SROC billing start date', () => {
Expand All @@ -95,6 +112,14 @@ describe('Determine Return Log Years Service', () => {
expect(result.flagForBilling).to.equal(true)
expect(result.twoPartTariff).to.equal(true)
})

it('flags the licence for pre sroc supplementary billing', async () => {
await DetermineReturnLogYearsService.go(returnLog.id)

const result = await LicenceModel.query().select(['includeInPresrocBilling']).where('id', licence.id)

expect(result[0].includeInPresrocBilling).to.equal('yes')
})
})
})
})
Expand Down

0 comments on commit 1c3ba4b

Please sign in to comment.