Skip to content

Commit 6d1bdef

Browse files
committed
Refactor PIINVOICE so env vars are fetched at start of billing pipeline.
1 parent 0a8b862 commit 6d1bdef

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

process_report/invoices/pi_specific_invoice.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import sys
32
from dataclasses import dataclass
43
import subprocess
54
import tempfile
@@ -27,6 +26,8 @@ class PIInvoice(invoice.Invoice):
2726
- NewPICreditProcessor
2827
"""
2928

29+
chrome_binary_location: str
30+
3031
TOTAL_COLUMN_LIST = [
3132
invoice.COST_FIELD,
3233
invoice.CREDIT_FIELD,
@@ -120,20 +121,12 @@ def _create_html_invoice(temp_fd):
120121
temp_fd.flush()
121122

122123
def _create_pdf_invoice(temp_fd_name):
123-
chrome_binary_location = os.environ.get(
124-
"CHROME_BIN_PATH", "/usr/bin/chromium"
125-
)
126-
if not os.path.exists(chrome_binary_location):
127-
sys.exit(
128-
f"Chrome binary does not exist at {chrome_binary_location}. Make sure the env var CHROME_BIN_PATH is set correctly and that Google Chrome is installed"
129-
)
130-
131124
invoice_pdf_path = (
132125
f"{self.name}/{pi_instituition}_{pi}_{self.invoice_month}.pdf"
133126
)
134127
subprocess.run(
135128
[
136-
chrome_binary_location,
129+
self.chrome_binary_location,
137130
"--headless",
138131
"--no-sandbox",
139132
f"--print-to-pdf={invoice_pdf_path}",

process_report/process_report.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ def validate_required_env_vars():
109109
def main():
110110
"""Remove non-billable PIs and projects"""
111111

112+
chrome_binary_location = os.environ.get("CHROME_BIN_PATH", "/usr/bin/chromium")
113+
114+
if not os.path.exists(chrome_binary_location):
115+
sys.exit(
116+
f"Chrome binary does not exist at {chrome_binary_location}. Make sure the env var CHROME_BIN_PATH is set correctly and that Google Chrome is installed"
117+
)
118+
112119
parser = argparse.ArgumentParser()
113120

114121
parser.add_argument(
@@ -369,7 +376,10 @@ def main():
369376
)
370377

371378
pi_inv = pi_specific_invoice.PIInvoice(
372-
name=args.output_folder, invoice_month=invoice_month, data=processed_data
379+
name=args.output_folder,
380+
invoice_month=invoice_month,
381+
data=processed_data,
382+
chrome_binary_location=chrome_binary_location,
373383
)
374384

375385
moca_prepaid_inv = MOCA_prepaid_invoice.MOCAPrepaidInvoice(

process_report/tests/util.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ def new_billable_invoice(
5555

5656

5757
def new_pi_specific_invoice(
58-
name="",
59-
invoice_month="0000-00",
60-
data=None,
58+
name="", invoice_month="0000-00", data=None, chrome_binary_path="/usr/bin/chromium"
6159
):
6260
if data is None:
6361
data = pandas.DataFrame()
64-
return pi_specific_invoice.PIInvoice(
65-
name,
66-
invoice_month,
67-
data,
68-
)
62+
return pi_specific_invoice.PIInvoice(name, invoice_month, data, chrome_binary_path)
6963

7064

7165
def new_nerc_total_invoice(

0 commit comments

Comments
 (0)