-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NERC Prepay Credits file is now exported through `PrepayCreditsSnapsh…
…ot` invoice class The snapshot has custom export paths, and a test case has been written for it.
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from dataclasses import dataclass | ||
|
||
import pandas | ||
|
||
from process_report import util | ||
from process_report.invoices import invoice | ||
|
||
|
||
@dataclass | ||
class PrepayCreditsSnapshot(invoice.Invoice): | ||
prepay_credits: pandas.DataFrame | ||
prepay_contacts: pandas.DataFrame | ||
|
||
export_columns_list = [ | ||
invoice.PREPAY_MONTH_FIELD, | ||
invoice.PREPAY_GROUP_NAME_FIELD, | ||
invoice.PREPAY_CREDIT_FIELD, | ||
] | ||
|
||
@property | ||
def output_path(self): | ||
return f"NERC_Prepaid_Group-Credits-{self.invoice_month}.csv" | ||
|
||
@property | ||
def output_s3_key(self): | ||
return f"Invoices/{self.invoice_month}/NERC_Prepaid_Group-Credits-{self.invoice_month}.csv" | ||
|
||
@property | ||
def output_s3_archive_key(self): | ||
return f"Invoices/{self.invoice_month}/Archive/NERC_Prepaid_Group-Credits-{self.invoice_month} {util.get_iso8601_time()}.csv" | ||
|
||
def _get_prepay_credits_snapshot(self): | ||
managed_groups_list = self.prepay_contacts.loc[ | ||
self.prepay_contacts[invoice.PREPAY_MANAGED_FIELD] == "Yes", | ||
invoice.PREPAY_GROUP_NAME_FIELD, | ||
] | ||
|
||
credits_mask = ( | ||
self.prepay_credits[invoice.PREPAY_MONTH_FIELD] == self.invoice_month | ||
) & ( | ||
self.prepay_credits[invoice.PREPAY_GROUP_NAME_FIELD].isin( | ||
managed_groups_list | ||
) | ||
) | ||
return self.prepay_credits[credits_mask] | ||
|
||
def _prepare(self): | ||
self.export_data = self._get_prepay_credits_snapshot() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
process_report/tests/unit/invoices/test_credits_snapshot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from unittest import TestCase | ||
import pandas | ||
|
||
from process_report.tests import util as test_utils | ||
|
||
|
||
class TestCreditsSnapshot(TestCase): | ||
def _get_test_prepay_credits(self, months, group_names, credits): | ||
return pandas.DataFrame( | ||
{"Month": months, "Group Name": group_names, "Credit": credits} | ||
) | ||
|
||
def _get_test_prepay_contacts(self, group_names, emails, is_managed): | ||
return pandas.DataFrame( | ||
{ | ||
"Group Name": group_names, | ||
"Group Contact Email": emails, | ||
"MGHPCC Managed": is_managed, | ||
} | ||
) | ||
|
||
def test_get_credit_snapshot(self): | ||
invoice_month = "2024-10" | ||
test_prepay_credits = self._get_test_prepay_credits( | ||
["2024-10", "2024-10", "2024-10", "2024-09", "2024-09"], | ||
["G1", "G2", "G3", "G1", "G2"], | ||
[0] * 5, | ||
) | ||
test_prepay_contacts = self._get_test_prepay_contacts( | ||
["G1", "G2", "G3"], [""] * 3, ["Yes", "No", "Yes"] | ||
) | ||
answer_credits_snapshot = test_prepay_credits.iloc[[0, 2]] | ||
|
||
new_prepayment_proc = test_utils.new_prepay_credits_snapshot( | ||
invoice_month=invoice_month, | ||
prepay_credits=test_prepay_credits, | ||
prepay_contacts=test_prepay_contacts, | ||
) | ||
output_snapshot = new_prepayment_proc._get_prepay_credits_snapshot() | ||
|
||
self.assertTrue(answer_credits_snapshot.equals(output_snapshot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters