**Not mergeable as it stands, but the fixes are small: four changes (items 1–4) should go in before the merge, and one question (item 5) needs an answer from you.** The structure itself is sound: small single-purpose functions, a parameterised query and guaranteed connection cleanup. I reviewed only `export_job.py`; I did not open `test_export_job.py` and ran nothing.

## Fix before merging

1. **A failed export looks like a success to cron** (`export_job.py:56-57`). `run()` catches every exception, logs one line and returns, so the process exits with code 0. For example, if the finance endpoint returns a 503, the only trace is a single stderr line with no traceback, and finance has no file for that day. Use `log.exception(...)` and re-raise, or `sys.exit(1)`.

2. **The upload has no timeout** (`export_job.py:42`). `requests.post` waits forever by default. If the endpoint accepts the connection and never answers, the job hangs with the database connection open, and the next night's run starts alongside it. Add `timeout=(10, 120)` or similar.

3. **Every customer email is written to the log** (`export_job.py:52`). On a day with 5,000 invoices, that is 5,000 addresses in one log line, copied to wherever logs are shipped and retained. Log the count and the day only.

4. **Tests cover only the CSV header and one row**, according to the module docstring. Nothing covers the date window in `fetch_invoices`, an upload returning an error, the failure path in `run()` or a day with zero invoices. The failure-path test is the one that would have caught item 1.

## Check before merging

5. **The definition of "yesterday" depends on two clocks that may disagree** (`export_job.py:47`, `:28`). `date.today()` uses the cron host's timezone, while the database turns the date into midnight in its own session timezone.
   - **Failing case:** the host is on UTC and the database session is on US Pacific. The 02:00 UTC run on 14 Nov asks for 13 Nov, but in Pacific time it is only 18:00 on 13 Nov. Invoices paid in the last six hours of that day are never exported, because the next run asks for 14 Nov.
   - **If both are the same zone:** this is fine. It is still worth pinning the zone explicitly and passing timestamps rather than a bare date.

6. **The upload sends no credentials** (`export_job.py:42`). If the endpoint is authenticated by a token inside `FINANCE_UPLOAD_URL`, that token is written to the log on failure, because the `raise_for_status()` error message includes the full URL. Confirm how the endpoint authenticates and that the URL is HTTPS.

## Should fix, can follow the merge

7. **A missed day cannot be re-run.** The date is hard-coded to yesterday, so recovering from a failed night means editing code. Accept an optional date argument.

8. **Amounts are formatted inconsistently and assume two-decimal currencies** (`export_job.py:37`). 2000 cents is written as `20.0`, 1950 as `19.5` and 1999 as `19.99`. A JPY invoice of 500 yen stored as `500` is written as `5.0`. Use `Decimal` with a per-currency exponent, or export `amount_cents` unchanged.

9. **One transient network error loses the day.** There is no retry on the upload, which matters more once item 1 makes failures visible.

10. **Exported files stay in `/var/exports` forever.** They contain customer emails, are created with default permissions and are never deleted. A crash mid-write also leaves a truncated file under the final name. Write to a temporary name, rename, and delete or expire after upload.

11. **Info logs are probably dropped.** The module never configures logging, so unless something else does, "exporting N invoices" and "export finished" never appear, and only the error line reaches stderr. Call `logging.basicConfig(level=logging.INFO)` in the `__main__` block.

## Minor

12. `FINANCE_UPLOAD_URL` is read at import time (`:16`), so importing the module in a test without that variable raises `KeyError`. `DATABASE_URL` is read lazily; do the same for both.
13. `psycopg2.connect` sits outside the `try` (`:49`), so a connection failure crashes with a traceback while every other failure is swallowed. This resolves itself once item 1 is fixed.
14. The database connection stays open during the upload. Close it after `fetch_invoices`.
15. `open(path, "w")` has no `encoding="utf-8"` (`:33`). Under cron's minimal locale, a non-ASCII email address can raise `UnicodeEncodeError`.
16. An invoice whose `paid_at` is backdated after the 02:00 run (a late payment webhook, for example) is never exported. Whether this can happen depends on how `paid_at` is set.
17. A day with zero invoices uploads a header-only file. Confirm finance wants that rather than no file.
18. An email starting with `=`, `+`, `-` or `@` is treated as a formula if finance opens the CSV in Excel.
19. `fetchall()` loads the whole day into memory. This is fine at normal daily volumes.
20. `EXPORT_DIR` is hard-coded, and the functions have no type hints.

VERDICT: READY WITH CHANGES
