Skip to content

Commit

Permalink
Exclude ended charge versions from 2PT billing (#865)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4375

In recent testing of triggering an SROC two-part tariff bill run, we've seen errors being thrown by the `DetermineAbstractionPeriodService`.

After investigating it is not the issue. It was being passed an empty charge period and this was because we're including charge versions that end before the billing period starts. This causes `DetermineChargePeriodService` to return an empty charge period.

This change updates `FetchChargeVersionsService` for two-part tariff to exclude charge versions that ended before the billing period starts.
  • Loading branch information
Cruikshanks authored Mar 27, 2024
1 parent d3a8668 commit af943d3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Workflow = require('../../../models/workflow.model.js')
* - have the scheme 'sroc'
* - be linked to a licence with is linked to the selected region
* - have a start date before the end of the billing period
* - have an end date on or after the start of the billing period
* - not be linked to a licence in the workflow
* - not be linked to a licence that 'ended' before the billing period
* - have a status of current
Expand Down Expand Up @@ -49,6 +50,11 @@ async function _fetch (regionCode, billingPeriod) {
.where('chargeVersions.startDate', '<=', billingPeriod.endDate)
.where('chargeVersions.status', 'current')
.where('chargeVersions.regionCode', regionCode)
.where((builder) => {
builder
.whereNull('chargeVersions.endDate')
.orWhere('chargeVersions.endDate', '>=', billingPeriod.startDate)
})
.where((builder) => {
builder
.whereNull('licence.expiredDate')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const FetchChargeVersionsService = require('../../../../app/services/bill-runs/t

describe('Fetch Charge Versions service', () => {
const billingPeriod = {
startDate: new Date('2022-04-01'),
endDate: new Date('2023-03-31')
startDate: new Date('2023-04-01'),
endDate: new Date('2024-03-31')
}
const regionCode = 5
const licenceId = 'cee9ff5f-813a-49c7-ba04-c65cfecf67dd'
Expand Down Expand Up @@ -225,7 +225,27 @@ describe('Fetch Charge Versions service', () => {
describe('because the start date is after the billing period ends', () => {
beforeEach(async () => {
const { id: chargeVersionId } = await ChargeVersionHelper.add(
{ startDate: new Date('2023-04-01'), licenceId, licenceRef, regionCode }
{ startDate: new Date('2024-04-01'), licenceId, licenceRef, regionCode }
)

await ChargeReferenceHelper.add({
chargeVersionId,
chargeCategoryId,
adjustments: { s127: true }
})
})

it('returns no records', async () => {
const results = await FetchChargeVersionsService.go(regionId, billingPeriod)

expect(results).to.be.empty()
})
})

describe('because the end date is before the billing period starts', () => {
beforeEach(async () => {
const { id: chargeVersionId } = await ChargeVersionHelper.add(
{ endDate: new Date('2023-03-31'), licenceId, licenceRef, regionCode }
)

await ChargeReferenceHelper.add({
Expand Down

0 comments on commit af943d3

Please sign in to comment.