Match returns to charge version by purpose type #342
Merged
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-4046
We are now working on Example 2, a licence with a charge version with 4 elements. One has a single purpose. The other has an element with 3 purposes. We need to match 4 returns; 1 to the first element and the rest to the second.
This change links the charge purposes to returns via
water.purposes_uses
, specificallylegacy_id
tometadata.purposes[0].tertiary.code
. It's this that allows us to match a return directly to a charge element.We also realised that we were still assigning the returns at the wrong level. They needed to be assigned to the charge element they match not the charge version.
Finally, we spotted the
innerJoin()
in our_fetchChargeVersions()
query was causing a charge version to appear more than once if it contained multiple charge elements.