Skip to content

Commit

Permalink
Merge pull request #141 from QuanMPhm/139/remove_magic
Browse files Browse the repository at this point in the history
Removed "Project" magic string from `bu_internal_invoice.py`
  • Loading branch information
knikolla authored Jan 17, 2025
2 parents 28318f7 + 51b3335 commit e0d3bf7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions process_report/invoices/bu_internal_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BUInternalInvoice(invoice.Invoice):
export_columns_list = [
invoice.INVOICE_DATE_FIELD,
invoice.PI_FIELD,
"Project",
invoice.PROJECT_NAME_FIELD,
invoice.GROUP_NAME_FIELD,
invoice.GROUP_INSTITUTION_FIELD,
invoice.GROUP_BALANCE_FIELD,
Expand All @@ -40,17 +40,19 @@ def _sum_project_allocations(self, dataframe):
"""A project may have multiple allocations, and therefore multiple rows
in the raw invoices. For BU-Internal invoice, we only want 1 row for
each unique project, summing up its allocations' costs"""
project_list = dataframe["Project"].unique()
data_no_dup = dataframe.drop_duplicates("Project", inplace=False)
project_list = dataframe[invoice.PROJECT_NAME_FIELD].unique()
data_no_dup = dataframe.drop_duplicates(
invoice.PROJECT_NAME_FIELD, inplace=False
)
sum_fields = [
invoice.COST_FIELD,
invoice.CREDIT_FIELD,
invoice.SUBSIDY_FIELD,
invoice.PI_BALANCE_FIELD,
]
for project in project_list:
project_mask = dataframe["Project"] == project
no_dup_project_mask = data_no_dup["Project"] == project
project_mask = dataframe[invoice.PROJECT_NAME_FIELD] == project
no_dup_project_mask = data_no_dup[invoice.PROJECT_NAME_FIELD] == project

sum_fields_sums = dataframe[project_mask][sum_fields].sum().values
data_no_dup.loc[no_dup_project_mask, sum_fields] = sum_fields_sums
Expand Down

0 comments on commit e0d3bf7

Please sign in to comment.