Skip to content

Commit

Permalink
NERC Prepay Credits file is now exported through PrepaymentProcessor
Browse files Browse the repository at this point in the history
An optional argument, `export_NERC_credits` is added for testing
purposes, to prevent the credits files from being written
while running test cases
  • Loading branch information
QuanMPhm committed Jan 14, 2025
1 parent e95349a commit dace52c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions process_report/processors/prepayment_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def PREPAY_DEBITS_S3_BACKUP_FILEPATH(self):
prepay_contacts: pandas.DataFrame
prepay_debits_filepath: str
upload_to_s3: bool
export_NERC_credits: bool = True # For testing purposes

@staticmethod
def _load_prepay_debits(prepay_debits_filepath):
Expand All @@ -53,6 +54,9 @@ def _process(self):
self._add_prepay_info()
self._apply_prepayments()

if self.export_NERC_credits:
credits_snapshot = self._get_prepay_credits_snapshot()
self._export_prepay_credits_snapshot(credits_snapshot)
self._export_prepay_debits()
if self.upload_to_s3:
self._export_s3_prepay_debits()
Expand Down Expand Up @@ -201,12 +205,32 @@ def _apply_prepayments(self):
debit_entry_mask, invoice.PREPAY_DEBIT_FIELD
] = prepay_amount_used

def _get_prepay_credits_snapshot(self):
managed_groups_list = list()
for group_name, group_dict in self.group_info_dict.items():
if group_dict[invoice.PREPAY_MANAGED_FIELD]:
managed_groups_list.append(group_name)

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 _backup_s3_prepay_debits(self):
invoice_bucket = util.get_invoice_bucket()
invoice_bucket.upload_file(
self.prepay_debits_filepath, self.PREPAY_DEBITS_S3_BACKUP_FILEPATH
)

def _export_prepay_credits_snapshot(self, credits_snapshot):
credits_snapshot.to_csv(
f"NERC_Prepaid_Group-Credits-{self.invoice_month}.csv", index=False
)

def _export_prepay_debits(self):
self.prepay_debits.to_csv(self.prepay_debits_filepath, index=False)

Expand Down
23 changes: 23 additions & 0 deletions process_report/tests/unit/processors/test_prepayment_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,26 @@ def test_two_group_one_project(self):
answer_prepay_debits,
invoice_month,
)

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_group_info_dict = {
"G1": {"MGHPCC Managed": True},
"G2": {"MGHPCC Managed": False},
"G3": {"MGHPCC Managed": True},
}
answer_credits_snapshot = test_prepay_credits.iloc[[0, 2]]

new_prepayment_proc = test_utils.new_prepayment_processor(
invoice_month=invoice_month
)
new_prepayment_proc.prepay_credits = test_prepay_credits
new_prepayment_proc.group_info_dict = test_group_info_dict
output_snapshot = new_prepayment_proc._get_prepay_credits_snapshot()

self.assertTrue(answer_credits_snapshot.equals(output_snapshot))
1 change: 1 addition & 0 deletions process_report/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@ def new_prepayment_processor(
prepay_contacts,
prepay_debits_filepath,
upload_to_s3,
False,
)

0 comments on commit dace52c

Please sign in to comment.