From 70b81f95ac176aa0395980d0a38e76331ffb7496 Mon Sep 17 00:00:00 2001 From: Quan Pham Date: Thu, 19 Dec 2024 13:33:33 -0500 Subject: [PATCH] NERC Prepay Credits file is now exported through `PrepaymentProcessor` --- .../processors/prepayment_processor.py | 22 ++++++++++++++++++ process_report/tests/unit_tests.py | 23 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/process_report/processors/prepayment_processor.py b/process_report/processors/prepayment_processor.py index 484df0e..9b6860b 100644 --- a/process_report/processors/prepayment_processor.py +++ b/process_report/processors/prepayment_processor.py @@ -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() @@ -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) diff --git a/process_report/tests/unit_tests.py b/process_report/tests/unit_tests.py index a235926..9cdca20 100644 --- a/process_report/tests/unit_tests.py +++ b/process_report/tests/unit_tests.py @@ -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):