-
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.
A new `bu_internal_invoice.py` file has been added. Note that the BU Internal invoice depends on the billable invoice. The test case for the BU Internal invoice has been modified appropriately A new function `apply_flat_discount()` has been added, containing logic that is used by the functions to apply the new-pi credit and the BU subsidy. More info on this function can be found in its docstring
- Loading branch information
Showing
6 changed files
with
160 additions
and
87 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
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,63 @@ | ||
from dataclasses import dataclass | ||
from decimal import Decimal | ||
|
||
import process_report.invoices.invoice as invoice | ||
import process_report.util as util | ||
|
||
|
||
@dataclass | ||
class BUInternalInvoice(invoice.Invoice): | ||
subsidy_amount: int | ||
|
||
def _prepare(self): | ||
def get_project(row): | ||
project_alloc = row[invoice.PROJECT_FIELD] | ||
if project_alloc.rfind("-") == -1: | ||
return project_alloc | ||
else: | ||
return project_alloc[: project_alloc.rfind("-")] | ||
|
||
self.data = self.data[ | ||
self.data[invoice.INSTITUTION_FIELD] == "Boston University" | ||
].copy() | ||
self.data["Project"] = self.data.apply(get_project, axis=1) | ||
self.data[invoice.SUBSIDY_FIELD] = Decimal(0) | ||
self.data = self.data[ | ||
[ | ||
invoice.INVOICE_DATE_FIELD, | ||
invoice.PI_FIELD, | ||
"Project", | ||
invoice.COST_FIELD, | ||
invoice.CREDIT_FIELD, | ||
invoice.SUBSIDY_FIELD, | ||
invoice.BALANCE_FIELD, | ||
] | ||
] | ||
|
||
def _process(self): | ||
project_list = self.data["Project"].unique() | ||
data_no_dup = self.data.drop_duplicates("Project", inplace=False) | ||
sum_fields = [invoice.COST_FIELD, invoice.CREDIT_FIELD, invoice.BALANCE_FIELD] | ||
for project in project_list: | ||
project_mask = self.data["Project"] == project | ||
no_dup_project_mask = data_no_dup["Project"] == project | ||
|
||
sum_fields_sums = self.data[project_mask][sum_fields].sum().values | ||
data_no_dup.loc[no_dup_project_mask, sum_fields] = sum_fields_sums | ||
|
||
self.data = self._apply_subsidy(data_no_dup, self.subsidy_amount) | ||
|
||
def _apply_subsidy(self, dataframe, subsidy_amount): | ||
pi_list = dataframe[invoice.PI_FIELD].unique() | ||
|
||
for pi in pi_list: | ||
pi_projects = dataframe[dataframe[invoice.PI_FIELD] == pi] | ||
util.apply_flat_discount( | ||
dataframe, | ||
pi_projects, | ||
subsidy_amount, | ||
invoice.SUBSIDY_FIELD, | ||
invoice.BALANCE_FIELD, | ||
) | ||
|
||
return dataframe |
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
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
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
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