forked from CCI-MOC/invoicing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The PI-specific is now implemented in the `PIInvoice` class. This class takes in the entire billable invoice and will export the PI invoices to local storage and S3 Because the `upload_to_s3` function is no longer used, it is removed. Since the `export_s3` function in the Invoice class does not need to be concerned about file extensions, the test case for s3 exporting is somewhat simplified, only checking that the format of the output paths are correct.
- Loading branch information
Showing
4 changed files
with
99 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
from dataclasses import dataclass | ||
|
||
import pandas | ||
|
||
import process_report.invoices.invoice as invoice | ||
import process_report.util as util | ||
|
||
|
||
@dataclass | ||
class PIInvoice(invoice.Invoice): | ||
def _prepare(self): | ||
self.pi_list = self.data[invoice.PI_FIELD].unique() | ||
|
||
def export(self): | ||
def _export_pi_invoice(pi): | ||
if pandas.isna(pi): | ||
return | ||
pi_projects = self.data[self.data[invoice.PI_FIELD] == pi] | ||
pi_instituition = pi_projects[invoice.INSTITUTION_FIELD].iat[0] | ||
pi_projects.to_csv( | ||
f"{self.name}/{pi_instituition}_{pi} {self.invoice_month}.csv" | ||
) | ||
|
||
if not os.path.exists( | ||
self.name | ||
): # self.name is name of folder storing invoices | ||
os.mkdir(self.name) | ||
|
||
for pi in self.pi_list: | ||
_export_pi_invoice(pi) | ||
|
||
def export_s3(self, s3_bucket): | ||
def _export_s3_pi_invoice(pi_invoice): | ||
pi_invoice_path = os.path.join(self.name, pi_invoice) | ||
striped_invoice_path = os.path.splitext(pi_invoice_path)[0] | ||
output_s3_path = f"Invoices/{self.invoice_month}/{striped_invoice_path}.csv" | ||
output_s3_archive_path = f"Invoices/{self.invoice_month}/Archive/{striped_invoice_path} {util.get_iso8601_time()}.csv" | ||
s3_bucket.upload_file(pi_invoice_path, output_s3_path) | ||
s3_bucket.upload_file(pi_invoice_path, output_s3_archive_path) | ||
|
||
for pi_invoice in os.listdir(self.name): | ||
_export_s3_pi_invoice(pi_invoice) |
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