-
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
Add SROC Supplementary Billing Invoice Service #119
Conversation
https://eaflood.atlassian.net/browse/WATER-3896 In order to 'piggy-back' onto the existing functions in the legacy service for reviewing, confirming, sending, viewing, deleting a bill run etc we need to create the same base database records as it does for a Bill run. This change will add a service to handle creating the `water.billing_batch_invoice` records in the DB. This is the link between the `billing_batch` and the invoice account, and from there to the licences included in the bill run. We'll need to dig into the legacy code to understand where the previous team extracts the data that forms the `billing_invoice` records. We'll then aim to replicate that here.
the invoiceAccountId whilst it exists in the billingInvoices table it is not a foreign key
A seperate PR will be going in to prevent knexSnakeCaseMappers from incorrectly formatting the schema name
https://eaflood.atlassian.net/browse/WATER-3896 Whilst working on [Add SROC Supplementary Billing Invoice Service](#119) we hit an issue. It was the first time we needed to query the `crm_v2` schema. But that threw errors due to the way [Objection.js knexSnakeCaseMappers()](https://vincit.github.io/objection.js/api/objection/#knexsnakecasemappers) works. It uses Knex's [wrapIdentifier()](https://knexjs.org/guide/#wrapidentifier) and [postProcessResponse()](https://knexjs.org/guide/#postprocessresponse) hooks to see each 'identifier' name. It can then test whether it needs converting, either from or to snake case. For example, `knex('table').withSchema('foo').select('table.field as otherName').where('id', 1)` will call `wrapIdentifier()` for the values `'table'`, `'foo'`, `'table'`, `'field'`, `'otherName'` and `'id'`. **knexSnakeCaseMappers()** takes some options, one of them being `underscoreBeforeDigits`. If we didn't use this fields like `address_line_1` or `section_127_agreement` in the DB would be incorrectly converted to `address_line1` and `section127_agreement`. But this is what leads to our problem. The previous teams' decision to name one of the schemas `crm_v2` leads to an incorrect conversion. **knexSnakeCaseMappers()** is seeing this and returning `'crm_v_2'`. It doesn't know it's a schema instead of a column name because Knex doesn't provide that context. This is the exact same issue we faced in [Make timestamps consistent at model layer](#85). Thankfully, a solution that didn't work there will work here. We can provide our own custom knex snake case mappers implementation which knows to ignore `'crm_v_2'`, whilst calling Objection.js own methods for everything else. It also gives us a solution if we face any more funnies like this when dealing with the legacy data.
https://eaflood.atlassian.net/browse/WATER-3896 Whilst working on [Add SROC Supplementary Billing Invoice Service](#119) we hit an issue. It was the first time we needed to query the `crm_v2` schema. But that threw errors due to the way [Objection.js knexSnakeCaseMappers()](https://vincit.github.io/objection.js/api/objection/#knexsnakecasemappers) works. It uses Knex's [wrapIdentifier()](https://knexjs.org/guide/#wrapidentifier) and [postProcessResponse()](https://knexjs.org/guide/#postprocessresponse) hooks to see each 'identifier' name. It can then test whether it needs converting, either from or to snake case. For example, `knex('table').withSchema('foo').select('table.field as otherName').where('id', 1)` will call `wrapIdentifier()` for the values `'table'`, `'foo'`, `'table'`, `'field'`, `'otherName'` and `'id'`. **knexSnakeCaseMappers()** takes some options, one of them being `underscoreBeforeDigits`. If we didn't use this, fields like `address_line_1` or `section_127_agreement` in the DB would be incorrectly converted to `address_line1` and `section127_agreement`. But this is what leads to our problem. The previous teams' decision to name one of the schemas `crm_v2` leads to an incorrect conversion. **knexSnakeCaseMappers()** is seeing this and returning `'crm_v_2'`. It doesn't know it's a schema instead of a column name because Knex doesn't provide that context. This is the exact same issue we faced in [Make timestamps consistent at model layer](#85). Thankfully, a solution that didn't work there will work here. We can provide our own custom Knex snake case mappers implementation which knows to ignore `'crm_v_2'`, whilst calling **Objection.js** own methods for everything else. It also gives us a solution if we face any more funnies like this when dealing with the legacy database.
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.
I can only comment as I raised the PR. But I've flagged a few things for consideration. Nothing major, honest! 😁
app/services/supplementary-billing/fetch-invoice-account.service.js
Outdated
Show resolved
Hide resolved
app/services/supplementary-billing/create-billing-invoice.service.js
Outdated
Show resolved
Hide resolved
app/services/supplementary-billing/create-billing-invoice.service.js
Outdated
Show resolved
Hide resolved
test/services/supplementary-billing/create-billing-invoice.service.test.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Alan Cruikshanks <[email protected]>
Co-authored-by: Alan Cruikshanks <[email protected]>
Co-authored-by: Alan Cruikshanks <[email protected]>
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.
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.
https://eaflood.atlassian.net/browse/WATER-3896
In order to 'piggy-back' onto the existing functions in the legacy service for reviewing, confirming, sending, viewing, deleting a bill run etc we need to create the same base database records as it does for a Bill run.
This change will add a service to handle creating the
water.billing_batch_invoice
records in the DB. This is the link between thebilling_batch
and the invoice account, and from there to the licences included in the bill run.We'll need to dig into the legacy code to understand where the previous team extracts the data that forms the
billing_invoice
records. We'll then aim to replicate that here.