Skip to content

Commit

Permalink
Fix issues with reissue post The Great Rename
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4336

Whilst working on updating our acceptance tests due to changes in the view bill run and view bill screens we found even after accounting for the changes, the SROC reissue test still failed.

After investigation we were able to identify changes made during the [The Great Rename](#416) had broken the reissue engine.

Prior to the rename the reissue engine was depending on shared fields between records. For example, a `water.billing_invoice` and a `crm_v2.invoice_account` shared the same fields; `invoice_account_id` and `invoice_account_number`.

So, you could pass an instance of both to a service like `GenerateBillService` and as far as it is concerned it is dealing with a 'billing account' instance because it has the `invoice_account_id` and `invoice_account_number` properties it expects.

```javascript
const billingInvoice = {
  billingInvoiceId: 'e1b40699-3b57-422c-96c3-3732e86312fc'
  invoiceAccountId: '53c85d8c-d5fc-48db-9c59-aa36995c0e4b',
  invoiceAccountNumber: 'A00000002A'
}

const invoiceAccount = {
  invoiceAccountId: '53c85d8c-d5fc-48db-9c59-aa36995c0e4b',
  invoiceAccountNumber: 'A00000002A'
}
```

Post the rename this is no longer the case. Now we have the following

```javascript
const billingInvoice = {
  id: 'e1b40699-3b57-422c-96c3-3732e86312fc'
  invoiceAccountId: '53c85d8c-d5fc-48db-9c59-aa36995c0e4b',
  invoiceAccountNumber: 'A00000002A'
}

const invoiceAccount = {
  id: '53c85d8c-d5fc-48db-9c59-aa36995c0e4b',
  invoiceAccountNumber: 'A00000002A'
}
```

> We use field names pre the great rename to help explain the issue. But this is not what they would actually be.

It's `invoiceAccountId` on the billing invoice and just `id` on the invoice account. `GenerateBillService` can no longer be given both types of instance and expect to give the same result.

So, this fixes the issue by generating objects that represent what `GenerateBillService` and `GenerateBillLicenceService` expect.
  • Loading branch information
Cruikshanks committed Jan 17, 2024
1 parent b27e0a3 commit 80bc97e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/services/bill-runs/supplementary/reissue-bill.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,16 @@ function _retrieveOrGenerateBill (dataToReturn, sourceBill, reissueBillRun, char
}

const translatedChargingModuleInvoice = _mapChargingModuleInvoice(chargingModuleReissueInvoice)

// GenerateBillService expects a BillingAccount instance and was built for supplementary billing. We only have the
// Bill object. So, we create a 'billing account' from its data that GenerateBillService can then use.
const billingAccount = {
id: sourceBill.billingAccountId,
accountNumber: sourceBill.accountNumber
}

const generatedBill = GenerateBillService.go(
sourceBill,
billingAccount,
reissueBillRun.id,
sourceBill.financialYearEnding
)
Expand Down Expand Up @@ -267,7 +275,14 @@ function _retrieveOrGenerateBillLicence (dataToReturn, sourceBill, billingId, so
return existingBillLicence
}

const newBillLicence = GenerateBillLicenceService.go(billingId, sourceBillLicence)
// GenerateBillLicenceService expects a Licence object and was built for supplementary billing. We only have the
// BillLicence object. So, we create a 'licence' from its data that GenerateBillLicenceService can then use.
const licence = {
id: sourceBillLicence.licenceId,
licenceRef: sourceBillLicence.licenceRef
}

const newBillLicence = GenerateBillLicenceService.go(billingId, licence)

dataToReturn.billLicences.push(newBillLicence)

Expand Down

0 comments on commit 80bc97e

Please sign in to comment.