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 prepayments #117

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

QuanMPhm
Copy link
Contributor

@QuanMPhm QuanMPhm commented Dec 4, 2024

Closes #115 . This PR consists of the two last commits, "Implemented processor for prepayments" and "Moved institution...". More details about the implementation is in the commit message.

@joachimweyl With this implementation, backprocessing (processing past invoices) will no longer be supported.

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.

The unit tests file only gets larger with this. Could we put the unit tests for prepayment in their own file? I know we have #116 but that's for tests that are already in the codebase, for the new stuff we should just put it in the right place to begin with.

if args.prepay_debits:
prepay_debits_filepath = args.prepay_debits
else:
prepay_debits_filepath = fetch_s3_prepay_debits()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I should have spoken earlier about this, but we have too many of these fetch_something_from_s3() type methods that take no argument. We should factor this out and then re-use the methods.

def fetch_from_s3(local_name, s3_path):
    # do the thing

this doesn't have to be part of this PR.

return institute_map


def get_institution_from_pi(institute_map, pi_uname):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have seen this method somewhere before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a commit to move the institution functions to util.py


def _export_s3_prepay_debits(self):
invoice_bucket = util.get_invoice_bucket()
invoice_bucket.upload_file(self.prepay_debits_filepath, "TODO.csv") # TODO
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@naved001 @knikolla @joachimweyl I'll amend this after we agree on the S3 filename for the debits file

Copy link
Contributor

Choose a reason for hiding this comment

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

@QuanMPhm Prepay/prepay_debits.csv seems fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Back this up in the same way that we backup the old pi file (or upload it to a different location with a timestamp)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I picked "Prepay/prepay_debits.csv" as the s3 location, and f"Prepay/Archive/prepay_debits {util.get_iso8601_time()}.csv" as the backup location

@naved001 naved001 dismissed their stale review December 17, 2024 00:35

I won't be around for a while to reivew so don't want to block it.

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.

Looks good to me. 2 TODOs are left in the code which should be removed.


def _export_s3_prepay_debits(self):
invoice_bucket = util.get_invoice_bucket()
invoice_bucket.upload_file(self.prepay_debits_filepath, "TODO.csv") # TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

Back this up in the same way that we backup the old pi file (or upload it to a different location with a timestamp)

@@ -15,7 +15,11 @@ class BUInternalInvoice(invoice.Invoice):
invoice.INVOICE_DATE_FIELD,
invoice.PI_FIELD,
"Project",
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this PR, but you should switch this field (and all other occurences of the magic string "Project") to instead using invoice.PROJECT_NAME_FIELD in a future patch.

invoice_month,
)

# Invoice month is after some credits and debits are given, TODO: Waiting for Kim's response
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you get the response you needed? Please make sure there are no TODOs left over in the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

If not please link to what the question was.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe my question was whether we would allow "backprocessing". You responded no. This was relevant to how I design the test case, and if we're not doing backprocessing, that will make things a lot simpler :)

@QuanMPhm QuanMPhm force-pushed the 115/prepayment_proc branch from e8ad7d8 to 5ba7121 Compare January 14, 2025 19:26
@QuanMPhm
Copy link
Contributor Author

I have implemented all feedback so far and removed the TODOs

Prepayments have been implemented by a new processor, `PrepaymentProcessor`.
The full implementation for prepayments involved the following changes:
- Several new columns names have been added to `invoices/invoice.py`,
including column names for the prepay data files and for the exported
invoices
- Many invoices will now export with 4 new columns: `Prepaid Group Name`,
`Prepaid Group Institution`, `Prepaid Group Balance`, `Prepaid Group Used`
- 4 command line arguments have been added to `process_report.py`.
3 of them allows the user to pass in a local version of the prepay credits,
contacts, and projects file. The last one (`—prepay-debits`) allows passing
a local version of the prepay debits files, and defaults to fetching from s3 if not
provided
- A set of test cases have been added for `PrepaymentProcessor`

Since the implementation of this feature required a lot of logic decisions
(i.e What happens if a prepaid project is active, but has no
funds?), below is (hopefully) an exhaustive list of code logic decisions
that were made. These can also be inferred through the test cases.
- Prepay projects listed in `prepaid_projects.csv` are identified by their
project name, not project - allocation name
- Attempting to process past invoices (“backprocessing”) may result in
incorrect output due to the nature of the prepay debit ledger
- While backprocessing is not supported for past months, processing
the same invoice month twice will still return correct output. In this
case, the month’s debit entry may be will be overwritten
- Prepay balances can be used in the same month they are added.
- The time range in which prepay projects are considered “active” includes
their start and end date
- After processing of any given invoice month, debit entries for that
month will be added. I emphasize this for clarification. A debit entry
such as:

`2024-11,G1,1062.48`

Should be interpreted as:
In the period from 2024-11-01 to 2024-11-30, prepay group G1 spent $1062.48
As opposed to:
In the period from 2024-10-01 to 2024-10-31, …

- If prepay projects are “active” but their prepay group has $0 balance,
their prepay info (group name, contact email) is still included, but the
prepay balance will be displayed as $0 and the prepay used as an empty field
@QuanMPhm QuanMPhm force-pushed the 115/prepayment_proc branch from 5ba7121 to 5ab6185 Compare January 14, 2025 21:06
@QuanMPhm
Copy link
Contributor Author

The PR has been rebased

…r` to `util`

Since these functions are now used in more than one location (`add_insti_proc`
and `prepay_proc`), it makes sense for them to be relocated to `util`

The test case checking institution-processing has changed slightly
@QuanMPhm QuanMPhm force-pushed the 115/prepayment_proc branch from 5ab6185 to e95349a Compare January 14, 2025 21:14
@QuanMPhm QuanMPhm requested a review from knikolla January 14, 2025 21:15
PREPAY_DEBITS_S3_FILEPATH = "Prepay/prepay_debits.csv"

@property
def PREPAY_DEBITS_S3_BACKUP_FILEPATH(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Generally, all capital letters is reserved for constants. This isn't a constant.

@knikolla knikolla merged commit 28318f7 into CCI-MOC:main Jan 17, 2025
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.

Implement processor for prepayments
4 participants