-
Notifications
You must be signed in to change notification settings - Fork 0
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
Unflag all processed licences not in bill run #221
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://eaflood.atlassian.net/browse/WATER-4007 > This came bout dues to an issue found during UAT of SROC supplementary billing The issue was that when the SROC bill run was sent licences that were processed in the bill run retained a 'include in SROC supplementary billing' flag. This means the licence will be processed again in the next supplementary bill run. We've had trouble replicating the issue. So, we went back to the logic to see if that can shine any light. ***The current logic*** At the very end of the send process the legacy code will fire off this query ```sql update water.licences l set include_in_sroc_supplementary_billing = :to where l.date_updated <= :batchCreatedDate and l.region_id = :regionId and l.licence_id not in (select licence_id from water.charge_version_workflows where date_deleted is null) and l.include_in_sroc_supplementary_billing = :from ``` This is the original query used for PRESROC which we copied and tweaked for SROC. Most folks on the team assumed we unflagged only those licences included in the bill run. But that's not the case. The problem is a licence when processed may result in no need for a `billing_invoice` to be generated. Because of the queueing architecture in the legacy code at the point this query is run you've lost which licences never made it into the billing_batch. This is why the legacy code has defaulted to unsetting the flag for any licence last updated prior to the billing_batch (bill run) being created. ***The problem*** Should a licence record get updated after the bill run is created then the query won't include it. We've not been able to pin down how this happens. But our primary suspect is the import process, which seems to update all licence records at approximately the same time. ***The fix*** We're updating our system repo's billing engine to unflag any licences that have been processed, but didn't result in a `billing_invoice` record being created. Should the bill run get cancelled and re-generated it won't matter these are no longer flagged as the result will be the same. With this in place we can then update the query we're asking the legacy code to fire to be much more intelligent. It will be able to use the `billing_invoice_licence` records linked to the bill run to identify exactly which licences were processed and part of the bill run. It won't matter when they got updated. With both steps in place, the new SROC supplementary process will be only unflagging those licences processed during the bill run.
Jozzey
requested changes
May 15, 2023
app/services/supplementary-billing/unflag-unbilled-licences.service.js
Outdated
Show resolved
Hide resolved
Jozzey
approved these changes
May 15, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://eaflood.atlassian.net/browse/WATER-4007
The issue was that when the SROC bill run was sent licences that were processed in the bill run retained a 'include in SROC supplementary billing' flag. This means the licence will be processed again in the next supplementary bill run.
We've had trouble replicating the issue. So, we went back to the logic to see if that can shine any light.
The current logic
At the very end of the send process the legacy code will fire off this query
This is the original query used for PRESROC which we copied and tweaked for SROC. Most folks on the team assumed we unflagged only those licences included in the bill run. But that's not the case.
The problem is a licence when processed may result in no need for a
billing_invoice
to be generated. Because of the queueing architecture in the legacy code at the point this query is run, you've lost which licences never made it into the billing_batch. This is why the legacy code has defaulted to unsetting the flag for any licence last updated prior to the billing_batch (bill run) being created.The problem
Should a licence record get updated after the bill run is created, the query won't include it. We've not been able to pin down how this happens. But our primary suspect is the import process, which seems to update all licence records at approximately the same time.
The fix
We're updating our system repo's billing engine to unflag any licences that have been processed but didn't result in a
billing_invoice
record being created. Should the bill run get cancelled and re-generated it won't matter these are no longer flagged as the result will be the same.With this in place, we can then update the query we're asking the legacy code to fire to be much more intelligent. It can use the
billing_invoice_licence
records linked to the bill run to identify precisely which licences were processed and part of the bill run. It won't matter when they got updated.With both steps in place, the new SROC supplementary process will only unflag those licences processed during the bill run.