11import argparse
22import sys
3- import datetime
43import logging
54from decimal import Decimal
65import os
1110
1211from process_report import util
1312from process_report .invoices import (
13+ invoice ,
1414 lenovo_invoice ,
1515 nonbillable_invoice ,
1616 billable_invoice ,
3333 validate_cluster_name_processor ,
3434)
3535
36- ### PI file field names
37- PI_PI_FIELD = "PI"
38- PI_FIRST_MONTH = "First Invoice Month"
39- PI_INITIAL_CREDITS = "Initial Credits"
40- PI_1ST_USED = "1st Month Used"
41- PI_2ND_USED = "2nd Month Used"
42- ###
43-
44-
45- ### Invoice field names
46- INVOICE_DATE_FIELD = "Invoice Month"
47- PROJECT_FIELD = "Project - Allocation"
48- PROJECT_ID_FIELD = "Project - Allocation ID"
49- PI_FIELD = "Manager (PI)"
50- INVOICE_EMAIL_FIELD = "Invoice Email"
51- INVOICE_ADDRESS_FIELD = "Invoice Address"
52- INSTITUTION_FIELD = "Institution"
53- INSTITUTION_ID_FIELD = "Institution - Specific Code"
54- SU_HOURS_FIELD = "SU Hours (GBhr or SUhr)"
55- SU_TYPE_FIELD = "SU Type"
56- RATE_FIELD = "Rate"
57- COST_FIELD = "Cost"
58- CREDIT_FIELD = "Credit"
59- CREDIT_CODE_FIELD = "Credit Code"
60- SUBSIDY_FIELD = "Subsidy"
61- BALANCE_FIELD = "Balance"
62- ###
6336
6437PI_S3_FILEPATH = "PIs/PI.csv"
6538ALIAS_S3_FILEPATH = "PIs/alias.csv"
@@ -96,10 +69,6 @@ def load_prepay_csv(prepay_credits_path, prepay_projects_path, prepay_contacts_p
9669 )
9770
9871
99- def get_iso8601_time ():
100- return datetime .datetime .now ().strftime ("%Y%m%dT%H%M%SZ" )
101-
102-
10372def validate_required_env_vars (required_env_vars ):
10473 for required_env_var in required_env_vars :
10574 if required_env_var not in os .environ :
@@ -116,11 +85,6 @@ def main():
11685 nargs = "*" ,
11786 help = "One or more CSV files that need to be processed" ,
11887 )
119- parser .add_argument (
120- "--fetch-from-s3" ,
121- action = "store_true" ,
122- help = "If set, fetches invoices from S3 storage. Requires environment variables for S3 authentication to be set" ,
123- )
12488 parser .add_argument (
12589 "--upload-to-s3" ,
12690 action = "store_true" ,
@@ -447,8 +411,8 @@ def merge_csv(files):
447411 dataframe = pandas .read_csv (
448412 file ,
449413 dtype = {
450- COST_FIELD : pandas .ArrowDtype (pyarrow .decimal128 (12 , 2 )),
451- RATE_FIELD : str ,
414+ invoice . COST_FIELD : pandas .ArrowDtype (pyarrow .decimal128 (12 , 2 )),
415+ invoice . RATE_FIELD : str ,
452416 },
453417 )
454418 dataframes .append (dataframe )
@@ -458,17 +422,6 @@ def merge_csv(files):
458422 return merged_dataframe
459423
460424
461- def get_invoice_date (dataframe ):
462- """Returns the invoice date as a pandas timestamp object
463-
464- Note that it only checks the first entry because it should
465- be the same for every row.
466- """
467- invoice_date_str = dataframe [INVOICE_DATE_FIELD ][0 ]
468- invoice_date = pandas .to_datetime (invoice_date_str , format = "%Y-%m" )
469- return invoice_date
470-
471-
472425def timed_projects (timed_projects_file , invoice_date ):
473426 """Returns list of projects that should be excluded based on dates"""
474427 dataframe = pandas .read_csv (timed_projects_file )
@@ -487,11 +440,9 @@ def timed_projects(timed_projects_file, invoice_date):
487440
488441def backup_to_s3_old_pi_file (old_pi_file ):
489442 invoice_bucket = util .get_invoice_bucket ()
490- invoice_bucket .upload_file (old_pi_file , f"PIs/Archive/PI { get_iso8601_time ()} .csv" )
491-
492-
493- def export_billables (dataframe , output_file ):
494- dataframe .to_csv (output_file , index = False )
443+ invoice_bucket .upload_file (
444+ old_pi_file , f"PIs/Archive/PI { util .get_iso8601_time ()} .csv"
445+ )
495446
496447
497448def get_lenovo_su_charge_info (invoice_month , rates_info ):
0 commit comments