Skip to content

Commit

Permalink
Removed "Project" magic string from bu_internal_invoice.py
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanMPhm committed Jan 15, 2025
1 parent 5c7290d commit 52a0931
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.COST_FIELD,
invoice.CREDIT_FIELD,
invoice.SUBSIDY_FIELD,
Expand All @@ -36,17 +36,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 52a0931

Please sign in to comment.