@@ -62,10 +62,17 @@ def add_dollar_sign(data):
6262 .copy ()
6363 .reset_index (drop = True )
6464 )
65- answer_invoice_pi1 .loc [len (answer_invoice_pi1 )] = None
66- answer_invoice_pi1 .loc [
67- answer_invoice_pi1 .index [- 1 ], ["Invoice Month" , "Balance" ]
68- ] = ["Total" , 300 ]
65+ # Create totals row by copying first row and modifying
66+ totals_row = answer_invoice_pi1 .iloc [[0 ]].copy ()
67+ for col in totals_row .columns :
68+ totals_row [col ] = ""
69+ totals_row ["Invoice Month" ] = "Total"
70+ totals_row ["Balance" ] = 300
71+ answer_invoice_pi1 = pandas .concat (
72+ [answer_invoice_pi1 , totals_row ], ignore_index = True
73+ )
74+
75+ # Apply dollar formatting
6976 for column_name in [
7077 "Prepaid Group Balance" ,
7178 "Prepaid Group Used" ,
@@ -74,17 +81,26 @@ def add_dollar_sign(data):
7481 answer_invoice_pi1 [column_name ] = answer_invoice_pi1 [column_name ].apply (
7582 add_dollar_sign
7683 )
84+ answer_invoice_pi1 = answer_invoice_pi1 .astype (pandas .StringDtype ())
7785 answer_invoice_pi1 .fillna ("" , inplace = True )
7886
7987 answer_invoice_pi2 = (
8088 test_invoice [test_invoice ["Manager (PI)" ] == "PI2" ]
8189 .copy ()
8290 .reset_index (drop = True )
8391 )
84- answer_invoice_pi2 .loc [len (answer_invoice_pi2 )] = None
85- answer_invoice_pi2 .loc [
86- answer_invoice_pi2 .index [- 1 ], ["Invoice Month" , "Balance" ]
87- ] = ["Total" , 700 ]
92+
93+ # Create totals row by copying first row and modifying to preserve formatting
94+ totals_row = answer_invoice_pi2 .iloc [[0 ]].copy ()
95+ for col in totals_row .columns :
96+ totals_row [col ] = ""
97+ totals_row ["Invoice Month" ] = "Total"
98+ totals_row ["Balance" ] = 700
99+ answer_invoice_pi2 = pandas .concat (
100+ [answer_invoice_pi2 , totals_row ], ignore_index = True
101+ )
102+
103+ # Drop prepay columns (they're all NA for PI2)
88104 answer_invoice_pi2 = answer_invoice_pi2 .drop (
89105 [
90106 "Prepaid Group Name" ,
@@ -97,6 +113,7 @@ def add_dollar_sign(data):
97113 answer_invoice_pi2 ["Balance" ] = answer_invoice_pi2 ["Balance" ].apply (
98114 add_dollar_sign
99115 )
116+ answer_invoice_pi2 = answer_invoice_pi2 .astype (pandas .StringDtype ())
100117 answer_invoice_pi2 .fillna ("" , inplace = True )
101118
102119 pi_inv = test_utils .new_pi_specific_invoice (data = test_invoice )
@@ -144,4 +161,29 @@ def test_export_pi(self, mock_subprocess_run, mock_path_exists, mock_filter_cols
144161 f"--print-to-pdf={ pi_pdf_path } " ,
145162 "--no-pdf-header-footer" ,
146163 ]
147- assert answer_arglist == chrome_arglist [0 ][:- 1 ]
164+
165+ self .assertEqual (answer_arglist , chrome_arglist [0 ][:- 1 ])
166+
167+ @mock .patch ("process_report.invoices.invoice.Invoice._filter_columns" )
168+ @mock .patch ("os.path.exists" )
169+ @mock .patch ("subprocess.run" )
170+ def test_process_no_warnings (
171+ self , mock_subprocess_run , mock_path_exists , mock_filter_cols
172+ ):
173+ """Test that no warnings are raised during invoice processing"""
174+ invoice_month = "2024-10"
175+ test_invoice = self ._get_test_invoice (
176+ ["PI1" , "PI1" , "PI2" , "PI2" ],
177+ ["BU" , "BU" , "HU" , "HU" ],
178+ [100 , 200 , 300 , 400 ],
179+ group_name = [None , "G1" , None , None ],
180+ )
181+ with tempfile .TemporaryDirectory () as test_dir :
182+ pi_inv = test_utils .new_pi_specific_invoice (
183+ test_dir , invoice_month , data = test_invoice
184+ )
185+ with self .assertNoLogs (
186+ "process_report.invoices.pi_specific_invoice" , level = "WARNING"
187+ ):
188+ pi_inv .process ()
189+ pi_inv .export ()
0 commit comments