Skip to content

Commit 5500c24

Browse files
authored
Fix including unnecessary supp. billing trans. (#210)
https://eaflood.atlassian.net/browse/WATER-3989 Recent testing found an issue following the change we made in [Inc. changes to agreements & charges in supp bill](#207). Although the final result was correct, we were always creating invoices with transaction lines for scenarios we should have been returning an `EMPTY` bill run. The reason was our changed logic to compare calculated transaction lines to previous ones. It was always returning 'false' i.e. the lines were always different when they should be matching and cancelling each other out. The problem was an unexpected way the previous team was handling Section 130 agreements. Whether a charge version has one or not is held in the linked `charge_elements` table in the adjustments field, for example ```json {"s126": null, "s127": true, "s130": false, "charge": null, "winter": false, "aggregate": null} ``` We generate our calculated transaction lines using this source data so hold `section130Agreement` as a boolean. What we found when we looked at the `billing_transactions` table is that this is a varchar, not a boolean. It looks like the initial build of PRESROC billing stored values other than 'true' or 'false'. But that then changed to 'true' and 'false' and these are the only values used for SROC. This means we weren't aware `FetchPreviousBillingTransactionsService` was returning previous transactions with `section130Agreement` held as a string. So, when we came to compare it was causing it to always determine the transactions were different. So, this change fixes the issue by using [Knex raw](https://knexjs.org/guide/raw.html) to cast the value in our query to a boolean to match what we get and use in `FetchChargeVersionsService`. Doing at there will be the most performant and means it matches our expectations of what type `section130Agreement` will be.
1 parent dcf97ef commit 5500c24

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

app/services/supplementary-billing/fetch-previous-billing-transactions.service.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ async function _fetch (licenceId, invoiceAccountId, financialYearEnding) {
7272
'bt.volume',
7373
'bt.section126Factor',
7474
'bt.section127Agreement',
75-
'bt.section130Agreement',
75+
// NOTE: The section130Agreement field is a varchar in the DB for historic reasons. It seems some early PRESROC
76+
// transactions recorded values other than 'true' or 'false'. For SROC though, it will only ever be true/false. We
77+
// generate our calculated billing transaction lines based on the Section130 flag against charge_elements which is
78+
// always a boolean. So, to avoid issues when we need to compare the values we cast this to a boolean when
79+
// fetching the data.
80+
db.raw('bt.section_130_agreement::boolean'),
7681
'bt.isTwoPartSecondPartCharge',
7782
'bt.scheme',
7883
'bt.aggregateFactor',

test/support/helpers/water/billing-transaction.helper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function defaults (data = {}) {
5050
isCredit: false,
5151
loss: 'medium',
5252
season: 'all year',
53+
section130Agreement: 'false',
5354
scheme: 'sroc',
5455
source: 'non-tidal',
5556
volume: 11

0 commit comments

Comments
 (0)