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

Unflag all processed licences not in bill run #221

Merged
merged 7 commits into from
May 15, 2023

Conversation

Cruikshanks
Copy link
Member

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

This came about 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

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, 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.

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.
@Cruikshanks Cruikshanks added the enhancement New feature or request label May 12, 2023
@Cruikshanks Cruikshanks self-assigned this May 12, 2023
@Cruikshanks Cruikshanks marked this pull request as ready for review May 15, 2023 12:26
@Cruikshanks Cruikshanks requested a review from Jozzey May 15, 2023 14:09
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cruikshanks Cruikshanks merged commit 033d4c2 into main May 15, 2023
@Cruikshanks Cruikshanks deleted the unflag-all-unbilled-licences branch May 15, 2023 15:24
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.

2 participants