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

Refactored billable invoice #61

Merged
merged 2 commits into from
Aug 16, 2024
Merged

Conversation

QuanMPhm
Copy link
Contributor

@QuanMPhm QuanMPhm commented Jun 11, 2024

Closes #64, I have refactored the billable invoice. I'll explain in more detail below, and have also have a question that I would like the professionals' opinions on.

For some context, the billable invoice performs 2 preparation steps (removing nonbillables and validating PI names) and 3 distinct steps during processing (loading the old PI file, applying the new PI credit, and then writing back the old PI file). I decided to split these steps into their own functions, and to store those functions in util.py, instead of making them private functions in theBillableInvoice class.

As for the test cases, I created a new test class for the billable invoice. Note that this new test case uses randomly generated values, instead of a hardcoded dataframe. I figured this would be more robust?

While writing the test case, l also had a few design questions I wanted to ask...

Considering how unsightly some of the test cases are, especially for the New PI credit, I was trying to think of ways to make the test case more organized and easier to follow. One of them was to create small test functions that would only test for one specific scenario (i.e a case for new PI, 1-month PI, overwritten entry, etc...), and to make a generator function that would that randomly generate the invoice and old-pi file (along with the expected output after they are processed) for a PI. I'm follow your opinions on whether randomized test data, instead of hardcoded data, would be better.

@QuanMPhm QuanMPhm requested review from larsks, knikolla and naved001 June 11, 2024 01:51
@larsks
Copy link
Member

larsks commented Jun 13, 2024

I would like to see the second commit updated so that the commit message has some description of the changes involved in "Refactored billable invoice".

@QuanMPhm QuanMPhm force-pushed the 52.2/refactor_billable branch 2 times, most recently from ef15ce6 to 342fb30 Compare June 14, 2024 03:22
Copy link
Contributor

@knikolla knikolla left a comment

Choose a reason for hiding this comment

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

Some small comments to make better use of _prepare and _prepare_export methods. Implement them in a separate commit to preserve this diff as mostly a copy paste and dedicate more subtle refactoring changes to future commits (within this PR).

process_report/invoices/billable_invoice.py Outdated Show resolved Hide resolved
process_report/invoices/billable_invoice.py Outdated Show resolved Hide resolved
process_report/invoices/billable_invoice.py Show resolved Hide resolved
process_report/invoices/billable_invoice.py Outdated Show resolved Hide resolved
process_report/invoices/billable_invoice.py Outdated Show resolved Hide resolved
The billable invoice now subclasses the Invoice base class.
The computations involved in preparation, namely filtering out
nonbillable projects and PIs, and validating PI names, have been
moved to `util.py`.

The function for applying the New-PI credit (`apply_credits_new_pi`)
is also moved there, and the I/O needed to read and write out
the PI file has been moved out of this functions for ease of testing.
@QuanMPhm QuanMPhm force-pushed the 52.2/refactor_billable branch 2 times, most recently from 71f8443 to dce97da Compare July 23, 2024 15:44
@QuanMPhm QuanMPhm requested a review from knikolla July 23, 2024 15:45
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.

looks good, left a few questions/suggestions

process_report/invoices/billable_invoice.py Show resolved Hide resolved
process_report/invoices/billable_invoice.py Outdated Show resolved Hide resolved
@QuanMPhm QuanMPhm force-pushed the 52.2/refactor_billable branch from dce97da to a2f6fef Compare July 30, 2024 15:56
@QuanMPhm
Copy link
Contributor Author

@naved001 @knikolla I've implemented all feedback given so far, and did a bit of refactoring with my most recent pushed-up changes.

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.

I am mostly nitpicking, but I think any method where you passed self but didn't use it should just be a staticmethod.

process_report/invoices/billable_invoice.py Show resolved Hide resolved
process_report/process_report.py Outdated Show resolved Hide resolved
process_report/invoices/billable_invoice.py Show resolved Hide resolved
Copy link
Contributor

@knikolla knikolla left a comment

Choose a reason for hiding this comment

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

Some comments, but otherwise looks pretty close.

process_report/invoices/billable_invoice.py Outdated Show resolved Hide resolved
process_report/invoices/billable_invoice.py Show resolved Hide resolved
process_report/tests/unit_tests.py Outdated Show resolved Hide resolved
@QuanMPhm QuanMPhm force-pushed the 52.2/refactor_billable branch from a2f6fef to 0a08fea Compare August 7, 2024 18:52
@QuanMPhm QuanMPhm requested a review from knikolla August 7, 2024 18:53
@QuanMPhm QuanMPhm merged commit 25c8e89 into CCI-MOC:main Aug 16, 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 the billable invoice
5 participants