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

Determine other factors for SROC transaction line #108

Merged
merged 34 commits into from
Feb 20, 2023

Conversation

StuAA78
Copy link
Contributor

@StuAA78 StuAA78 commented Feb 1, 2023

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

To get the Charging Module API to generate a charge we need more information than just billable days (see WATER-3894)

Using how the legacy code generates an SROC transaction line for an annual bill run, we need to create the same type of record in billing_transactions

So, the individual data points need to be sourced from the same places. We then need to populate the same fields. Note that we are looking at the current SROC transactions specifically because there are fields they don't bother to populate.

This PR creates FormatSrocTransactionLineService, which takes a charge element, a charge version and a financial year (plus optionally some flags to indicate whether this is a compensation charge, two part second charge, etc.) and returns an object representing a transaction, formatted ready to be inserted into the db.

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

To get the Charging Module API to generate a charge we need more information than just billable days (see WATER-3894)

Using how the legacy code generates an SROC transaction line for an annual bill run, we need to create the same type of record in billing_transactions

So, the individual data points need to be sourced from the same places. We then need to populate the same fields.

N.B. We looking at the current SROC transactions specifically because there are fields they don't bother to populate.
@StuAA78 StuAA78 added the enhancement New feature or request label Feb 1, 2023
@StuAA78 StuAA78 self-assigned this Feb 1, 2023
We initially define our service (with some fields still to-do) and create a unit test which successfully passes for a simple static field. This lets us know that our testing structure is correct
When calculating `billableDays` we need the abstraction period columns to be present in the `charge_elements` table, so we create migrations to add them for our test purposes
The two fields work very similarly, just with slightly different inputs. We therefore consolidate the common code
We mistakenly used the non-existent `id` property of the charge element. We fix this by using the correct `chargeElementId` property
The test file we used as a template included Sinon, but we realised that as we're not currently using it we can remove it
`chargeFactor` depends on us passing in a flag/option to specify whether this is a standard or compensation charge. Since we know we will be introducing additional options for future fields, we go straight into using our existing pattern for passing an object of options with defaults
When we pass the `isNewLicence` option we reflect its value in the output. Note that in the legacy code, the value of this is set by the `isMinimumCharge` flag, but as we're passing this in we simply give the option the same name as the output field and we will ensure it's passed in with the correct name
Note that as we are not yet creating two-part tariff transactions, we hardcode this field to `false`
We previously returned the `billableDays` value of only one of the periods returned by `AbstractionBillingPeriodService`. After discussing this we realised that we actually needed the sum of _all_ the `billableDays` values, so we update our code accordingly
Previously we were assuming that a chargePeriod object would be passed to the service. However as this is extracted from a chargeVersion object, it makes more sense for the logic to do this to live inside our service.
@StuAA78 StuAA78 marked this pull request as ready for review February 20, 2023 12:33
@StuAA78 StuAA78 merged commit 6201b6f into main Feb 20, 2023
@StuAA78 StuAA78 deleted the determine-factors-for-sroc-transaction-line branch February 20, 2023 13:40
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