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

Handle empty supplementary bill runs #153

Merged
merged 22 commits into from
Mar 10, 2023

Conversation

Cruikshanks
Copy link
Member

https://eaflood.atlassian.net/browse/WATER-3923

From the charge version, we generate transaction lines. For each charge element (reference) we look at the charge purposes connected to it and calculate the billable days. If that result is 0, we skip adding the transaction to the bill run.

This means there is often a case where having calculated and rejected all the transaction lines, the bill run is 'empty'. The legacy process will update the status of the bill run to empty, and remove any billing_invoice and billing_invoice_licence records created.

We need to do the same, though we intend to take a different approach. We'll process all the transaction lines first and only create billing_invoice and billing_invoice_licence records for those that remain. Should there be none, we'll go straight to marking the bill run as empty and stop the process there.

Our intent is to remove needless calls to the DB and simplify the process.

@Cruikshanks Cruikshanks added the enhancement New feature or request label Mar 6, 2023
@Cruikshanks Cruikshanks self-assigned this Mar 6, 2023
https://eaflood.atlassian.net/browse/WATER-3923

From the charge version we generate transaction lines. For each charge element (reference) we look at the charge purposes connected to it and calculate the billable days. If that result is 0, we skip adding the transaction to the bill run.

This means there is often a case where having calculated and rejected all the transaction lines, the bill run is 'empty'. The legacy process will update the status of the bill run to `empty`, and remove any `billing_invoice` and `billing_invoice_licence` records created.

We need to do the same, though we intend to take a different approach. We'll process all the transaction lines first and only create `billing_invoice` and `billing_invoice_licence` records for those that remain. Should there be none, we'll go straight to marking the bill run as `empty` and stop the process there.

Our intent is to remove needless calls to the DB and simplify the process.
@Cruikshanks Cruikshanks force-pushed the handle-empty-supplementary-bill-runs branch from c5e6537 to a390d06 Compare March 9, 2023 14:51
StuAA78 and others added 19 commits March 9, 2023 15:52
Copy and paste from other service. We're not doing anything async so we can drop this.
The solution that has been implemented means we don't have to worry about what transactions got persisted. So, we can delete this section.
You have to persist the billing invoices first else the billing invoice licence lines complain about a missing foreign key.

Fortunately, we don't have the same problem with billing_transactions!
Have tested locally at this stage and we are able to complete a supplementary bill run!
The size of the `go()` function was concerning me at this point. I was also weighing up the trade-offs between keeping another list of objects in memory that could potentially be as large as the original `generatedInvoices` vs the overhead of calling `filter()` on our original list.

My suggestion is to go with the latter, because it also helps shift some of the logic out of the `go()` function so we can break down what is happening and IMHO make things a little clearer.

But this is a suggestion so I am happy to be argued out of it. 🤷
realised we were not considering the licenceID when trying to find the existing billing invoice licence record.
Hopefully, how we are dropping the persist flag is clearer. It also means we are following our convention for arrow functions.

We also did some testing and found the call to `Object.values()` was just returning the same array passed in. So, we've dropped it.
A sonarcloud suggestion
We were supposed to be setting the status to empty. Stemmed from the original copy and paste.
@Cruikshanks
Copy link
Member Author

The issues with SonarCloud are to do with code coverage on the ProcessBillingBatchService. We know we have no unit tests for this service. But we're continuing to 'spike' the process and will ensure there are unit tests when we're happy with what the final process will be.

@Cruikshanks Cruikshanks marked this pull request as ready for review March 10, 2023 16:27
@Cruikshanks Cruikshanks merged commit b3d9b0d into main Mar 10, 2023
@Cruikshanks Cruikshanks deleted the handle-empty-supplementary-bill-runs branch March 10, 2023 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants