Implemented an invoice to export prepay groups invoices as PDFs#143
Open
QuanMPhm wants to merge 1 commit into
Open
Implemented an invoice to export prepay groups invoices as PDFs#143QuanMPhm wants to merge 1 commit into
QuanMPhm wants to merge 1 commit into
Conversation
larsks
requested changes
Jan 22, 2025
Comment on lines
+146
to
+175
| def _create_html_invoice(temp_fd): | ||
| environment = Environment(loader=FileSystemLoader(TEMPLATE_DIR_PATH)) | ||
| template = environment.get_template("pi_invoice.html") | ||
| content = template.render( | ||
| data=group_dataframe, | ||
| ) | ||
| temp_fd.write(content) | ||
| temp_fd.flush() | ||
|
|
||
| def _create_pdf_invoice(temp_fd_name): | ||
| chrome_binary_location = os.environ.get( | ||
| "CHROME_BIN_PATH", "usr/bin/chromium" | ||
| ) | ||
| if not os.path.exists(chrome_binary_location): | ||
| sys.exit( | ||
| f"Chrome binary does not exist at {chrome_binary_location}. Make sure the env var CHROME_BIN_PATH is set correctly or that Google Chrome is installed" | ||
| ) | ||
|
|
||
| invoice_pdf_path = f"{self.name}/{group_instituition}_{group_contact_email}_{self.invoice_month}.pdf" | ||
| subprocess.run( | ||
| [ | ||
| chrome_binary_location, | ||
| "--headless", | ||
| "--no-sandbox", | ||
| f"--print-to-pdf={invoice_pdf_path}", | ||
| "--no-pdf-header-footer", | ||
| "file://" + temp_fd_name, | ||
| ], | ||
| capture_output=True, | ||
| ) |
Member
There was a problem hiding this comment.
This looks like a duplicate of the code in process_report/invoices/pi_specific_invoice.py. Can we factor this out into a common base class (or mixin)?
Contributor
Author
13fa050 to
cf00ea7
Compare
A new invoice, `MOCAGroupInvoice`, has been added. Given the code overlap between it and `PIInvoice`. Some refactoring has been made. The list of different changes in this PR is: - The Prepay Group and PI invoices now subclasses from a new invoice class, `PDFInvoice`, which contains logic specific to exporting PDFs - Unused logger removed from `PIInvoice`
Contributor
Author
knikolla
reviewed
Jun 21, 2025
knikolla
left a comment
Contributor
There was a problem hiding this comment.
This PR is a good candidate for us to go over in a Zoom call line by line.
@joachimweyl ^^
| help="Name of output folder containing pi-specific invoice csvs", | ||
| ) | ||
| parser.add_argument( | ||
| "--prepay-groups-output-folder", |
Contributor
There was a problem hiding this comment.
Let's not make this configurable but provide default locations for invoices moving forward. Name should be hardcoded in the invoice.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #137. This PR consists of the last commit. I feel like there is still a bit of polishing left to do, so I will submit this as a draft for now. I'll revisit this when #137 has been fully reviewed and merged.
The PR is quite similar to #137 in terms of logic, using the chromium library to generate the PDFs.