-
Notifications
You must be signed in to change notification settings - Fork 5
Implemented the Bare Metal invoice and processor classes #154
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
Draft
QuanMPhm
wants to merge
3
commits into
CCI-MOC:main
Choose a base branch
from
QuanMPhm:152/bm_invoice
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+133
−2
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| from process_report.invoices import invoice | ||
|
|
||
|
|
||
| @dataclass | ||
| class BMInvoice(invoice.Invoice): | ||
| export_columns_list = [ | ||
| invoice.INVOICE_DATE_FIELD, | ||
| invoice.PROJECT_FIELD, | ||
| invoice.PROJECT_ID_FIELD, | ||
| invoice.PI_FIELD, | ||
| invoice.INVOICE_EMAIL_FIELD, | ||
| invoice.INVOICE_ADDRESS_FIELD, | ||
| invoice.INSTITUTION_FIELD, | ||
| invoice.INSTITUTION_ID_FIELD, | ||
| invoice.SU_HOURS_FIELD, | ||
| invoice.SU_TYPE_FIELD, | ||
| invoice.RATE_FIELD, | ||
| invoice.COST_FIELD, | ||
| invoice.CREDIT_FIELD, | ||
| invoice.CREDIT_CODE_FIELD, | ||
| invoice.BALANCE_FIELD, | ||
| ] | ||
|
|
||
| def _prepare_export(self): | ||
| self.export_data = self.data[ | ||
| self.data[invoice.PROJECT_ID_FIELD] == "ESI Bare Metal" | ||
| ] |
This file contains hidden or 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
This file contains hidden or 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,20 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| import pandas | ||
|
|
||
| from process_report.invoices import invoice | ||
| from process_report.processors import processor | ||
|
|
||
|
|
||
| @dataclass | ||
| class BMUsageProcessor(processor.Processor): | ||
| def _get_bm_project_mask(self): | ||
| return pandas.Series(True, index=self.data.index) # TODO: Remove dummy mask | ||
|
|
||
| def _process(self): | ||
| bm_projects_mask = self._get_bm_project_mask() | ||
| self.data.loc[bm_projects_mask, invoice.PROJECT_FIELD] = self.data.loc[ | ||
| bm_projects_mask, invoice.PROJECT_FIELD | ||
| ].apply(lambda v: v + " BM Usage") | ||
| self.data.loc[bm_projects_mask, invoice.PROJECT_ID_FIELD] = "ESI Bare Metal" | ||
| self.data.loc[bm_projects_mask, invoice.INVOICE_EMAIL_FIELD] = "[email protected]" |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -87,10 +87,14 @@ def _filter_nonbillables(self, data): | |
| def _filter_missing_pis(self, data): | ||
| return data[~data["Missing PI"]] | ||
|
|
||
| def _filter_bm_projects(self, data): | ||
| return data[~(data[invoice.PROJECT_ID_FIELD] == "ESI Bare Metal")] | ||
|
|
||
| def _get_credit_eligible_projects(self, data: pandas.DataFrame): | ||
| filtered_data = self._filter_nonbillables(data) | ||
| filtered_data = self._filter_missing_pis(filtered_data) | ||
| filtered_data = self._filter_excluded_su_types(filtered_data) | ||
| filtered_data = self._filter_bm_projects(filtered_data) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^^ |
||
| if self.limit_new_pi_credit_to_partners: | ||
| filtered_data = self._filter_partners(filtered_data) | ||
|
|
||
|
|
||
37 changes: 37 additions & 0 deletions
37
process_report/tests/unit/processors/test_bm_usage_processor.py
This file contains hidden or 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,37 @@ | ||
| from unittest import TestCase | ||
|
|
||
| import pandas | ||
|
|
||
| from process_report.tests import util as test_utils | ||
|
|
||
|
|
||
| class TestBUSubsidyProcessor(TestCase): | ||
| def test_get_bm_project_mask(self): | ||
| test_invoice = pandas.DataFrame({}) | ||
|
|
||
| answer_invoice = test_invoice.iloc[[0, 2]] | ||
|
|
||
| bm_usage_proc = test_utils.new_bm_usage_processor(data=test_invoice) | ||
| bm_project_mask = bm_usage_proc._get_bm_project_mask() | ||
| self.assertTrue(test_invoice[bm_project_mask].equals(answer_invoice)) | ||
|
|
||
| def test_process_bm_usage(self): | ||
| test_invoice = pandas.DataFrame( | ||
| { | ||
| "Project - Allocation": ["test", "test bm-bm"], | ||
| "Project - Allocation ID": [None] * 2, | ||
| "Invoice Email": [None] * 2, | ||
| } | ||
| ) | ||
|
|
||
| answer_invoice = pandas.DataFrame( | ||
| { | ||
| "Project - Allocation": ["test BM Usage", "test bm-bm BM Usage"], | ||
| "Project - Allocation ID": ["ESI Bare Metal"] * 2, | ||
| "Invoice Email": ["[email protected]"] * 2, | ||
| } | ||
| ) | ||
|
|
||
| bm_usage_proc = test_utils.new_bm_usage_processor(data=test_invoice) | ||
| bm_usage_proc.process() | ||
| self.assertTrue(bm_usage_proc.data.equals(answer_invoice)) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to test this filter in test cases for this processor class?