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
  • Loading branch information
QuanMPhm committed Dec 19, 2024
1 parent e8ad7d8 commit 70b81f9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions process_report/processors/prepayment_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def _process(self):
self._add_prepay_info()
self._apply_prepayments()

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 @@ -194,6 +196,26 @@ 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 _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_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,29 @@ def test_two_group_one_project(self):
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))


class TestLenovoProcessor(TestCase):
def test_process_lenovo(self):
Expand Down

0 comments on commit 70b81f9

Please sign in to comment.