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

Implemented processor for New-PI credit #112

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

QuanMPhm
Copy link
Contributor

@QuanMPhm QuanMPhm commented Nov 7, 2024

Closes #101. Depends on #108. I've implemented processor for applying the New-PI Credit, and included a new field to distinguish between the PI balance and the NERC balance. More details are in my commit message.

There are two commits to this PR, starting with Initialized processor for applying the New-PI Credit and discounts. The first one only copies over code, while the second commit actually makes functional changes.

@QuanMPhm QuanMPhm force-pushed the 101/proc_new_pi_credit branch 2 times, most recently from 0299851 to 59c0012 Compare November 11, 2024 20:23
@QuanMPhm
Copy link
Contributor Author

I fixed a bug with apply_discount_on_project(). In its old version, the function could lead to a negative PI balance.

@knikolla @naved001 I could write the test cases that would catch this mistake in this PR, but since the PR for #102 would catch this, I believe I will just write these tests in that PR?

@naved001
Copy link
Collaborator

I fixed a bug with apply_discount_on_project(). In its old version, the function could lead to a negative PI balance.

Could you say more about the impact of this bug? Would we need to rerun the invoice with the bug fix?

I could write the test cases that would catch this mistake in this PR, but since the PR for #102 would catch this, I believe I will just write these tests in that PR?

Which commit has the bug fix? the commit message in the 3rd commit covers a bunch of things and I didn't find a note about the bug fix. Also, if the fix for a bug is in this PR I think the test should also be a part of this.

@QuanMPhm
Copy link
Contributor Author

QuanMPhm commented Nov 12, 2024

@naved001 The bug fix was made when I amended my PR and force-pushed on Nov 11. This should show you the changes I made to fix the bug.

Edit: @naved001 This was a bug I found in this PR, not in upstream, so it has not have any impact on any of our past billing data.

@QuanMPhm QuanMPhm requested a review from hakasapl November 14, 2024 19:03
@QuanMPhm QuanMPhm force-pushed the 101/proc_new_pi_credit branch from 59c0012 to 2073310 Compare November 19, 2024 13:16
Code from `BillableInvoice` and `DiscountInvoice` has been copied over
without change
The `DiscountProcessor` class has been created, to be subclassed by
processors which applies discounts, such as the New-PI Credit.
This processor class introduces an important class constant,
`IS_DISCOUNT_BY_NERC`, which detemines whether the final balance,
as opposed to the PI balance (more info below), reflects the discount
being applied.

The New-PI credit is now implemented by `NewPICreditProcessor`

During discussions about billing, it was made noted that some discounts
are not provided by the MGHPCC, but instead from other sources, such as
the BU subsidy, which is provided to BU PIs by BU. This provided
motivation for a `PI Balance` field, which would reflect how much money the
PI should be billed, as opposed to the `Balance` field, which currently
reflects how much money the MGHPCC should receive. These two fields would
not equal each other if the PI received discounts not provided by the
MGHPCC.

Implementation of `NewPICreditProcessor` and the new billing
feature required a range of changes:
- `apply_discount_on_project()` in `DiscountProcessor` has been slightly
modified, where the PI balance and MGHPCC balance is now calculated seperately.
- As `BillableInvoice` no longer performs any processing itself, the
dataframe from `NewPICreditProcessor` is now passed to all invoice objects.
- The test cases for the New-PI credit have been refactored. Test cases
for the new billing feature is not written yet. I plan to write
them when the processor for the BU Subsidy is implemented
- With the new processor, certain Processor and Invoice classes depend on
fields created by other Processors, such as the case with
`NewPICreditProcessor` and `ValidateBillablePIsProcessor`. As such, docstrings
have been added to indicate dependancies
@QuanMPhm QuanMPhm force-pushed the 101/proc_new_pi_credit branch from 2073310 to 1686888 Compare November 19, 2024 13:22
Copy link
Collaborator

@naved001 naved001 left a comment

Choose a reason for hiding this comment

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

This looks fine to me. However, I'd like in the future that PRs this size be broken down into smaller commits.

It would also be nice if we split the unit tests, right now it's all one giant file.

@QuanMPhm
Copy link
Contributor Author

QuanMPhm commented Dec 3, 2024

@naved001 My apologies. I realized at some point that the PR could have been split into another commit to include the new PI_BALANCE. Sorry for making you review the whole thing.

I have made an issue to split up the unit test file here

@naved001
Copy link
Collaborator

naved001 commented Dec 9, 2024

@knikolla do you think you'd have time to review this?

@knikolla
Copy link
Contributor

With 3 approvals I feel fine with this merging without my review.

@naved001 naved001 merged commit c979154 into CCI-MOC:main Dec 17, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor processing for the New-PI credit
5 participants