I wouldn't merge this tomorrow as it stands. Three problems need fixing first: a failed export still looks like success, every customer's email address is written to the logs, and the amounts are wrong for some currencies. Most of the fixes are small. The structure is good: the fetch, write and upload steps are separate small functions with a single parameterised query, so each fix stays local.

I also looked for `test_export_job.py`, which the file's docstring mentions. It isn't in this directory, so I couldn't check what it tests.

## Must fix before merge

**1. Failures are hidden, so cron thinks every run worked (`export_job.py:56-57`).**
`except Exception` logs the error and carries on, so the script exits with code 0.
- **Case:** the finance endpoint returns a 500.
- **What happens:** one line is logged, the exit code is 0, cron reports success, and finance gets no file. Nobody notices until finance asks.
- **What should happen:** the script exits with a non-zero code, so cron or alerting catches it.

There's a second gap: `log.error("…%s", error)` records only the message, not the traceback. **Fix:** use `log.exception(...)` and then `raise`, or remove the `except` and keep the `finally`.

**2. Customer emails go into the logs (`export_job.py:52`).**
`[row[1] for row in rows]` logs the email address of every paying customer, every night. That's personal data spreading into log storage, which usually has wider access and longer retention than the database. **Fix:** log only the count and the day.

**3. Money is converted with float division and a fixed factor of 100 (`export_job.py:37`).**
- **Formatting case:** `amount_cents = 100` is written as `1.0`, not `1.00`, and `1234500` becomes `12345.0`. Finance tools that expect two decimal places may reject these or read them wrongly.
- **Currency case:** the code assumes every currency has 2 decimal places. A JPY invoice of ¥5000 (stored as 5000) is exported as `50.0`. A KWD amount, which has 3 decimal places, is out by a factor of 10.

**Fix:** use `Decimal(amount_cents) / Decimal(10) ** exponent(currency)` and set the decimal places explicitly. Or, if finance agrees, export the integer cents unchanged.

**4. The upload has no timeout (`export_job.py:42`).**
`requests.post` with no `timeout=` can wait forever if the endpoint stops responding. The job then never ends, and the next night's run can start on top of it. **Fix:** add `timeout=(10, 60)` or similar.

## Should fix (soon, or before merge if the fix is cheap)

**5. Which hours count as "yesterday" depends on server settings (`:47`, `:28`).**
`date.today()` uses the server's local time zone. Postgres then turns the date bounds into timestamps using the database session's time zone. If those two differ, or if a daylight-saving change falls inside the window, invoices near midnight can be missed or exported on two nights. **Fix:** set the time zone explicitly, e.g. build UTC (or finance's agreed time zone) bounds and pass `timestamptz` values.

**6. A missed night can't be re-run.**
The day is always worked out from today, so if Tuesday's run fails you can't re-export Monday without editing the code. **Fix:** let `run(day=None)` accept a date, with a `--date` command-line option.

**7. Importing the module fails without the upload URL set (`:16`).**
`os.environ["FINANCE_UPLOAD_URL"]` is read when the module loads, so any import without that variable set raises `KeyError`, including imports from tests. **Fix:** read it inside `upload()` or `run()`, the same way `DATABASE_URL` is already read.

**8. Test coverage is thin.**
By the docstring's own account, the tests cover only the CSV header and one row. Nothing tests:
- an upload failure, and that the script then exits non-zero
- a day with no invoices
- money formatting, e.g. `100` → `1.00` and a JPY amount
- the day boundaries
- the log line not containing emails

Items 1 and 3 especially need tests before merge, so they can't come back.

## Minor

**9. Info logs never appear.**
Logging is never configured in `__main__`, so the `log.info` lines are thrown away and only errors show up, through Python's fallback handler. **Fix:** add `logging.basicConfig(level=logging.INFO)` in the entry point.

**10. A failure can leave a half-written CSV.**
If writing stops part-way, a partial file sits in `/var/exports` under the real filename. **Fix:** write to a temporary file, then `os.replace` it into place.

**11. `EXPORT_DIR` is hardcoded and assumed to exist.**
Moving it to configuration, or calling `os.makedirs(..., exist_ok=True)`, would make local runs and tests easier.

**12. No-invoice days are unclear.**
On a day with no paid invoices the job uploads a header-only file. That may be what you want, but confirm finance expects it.

**13. `fetchall()` loads the whole day into memory.**
This is fine at current volumes. Use a server-side cursor if the volumes grow a lot.

**14. The "Tested by" line in the docstring will go stale.**
It already points at a file I couldn't find. Remove it, or keep it accurate.

**15. Nits:** the functions have no type hints or docstrings, which would especially help on `write_csv`'s row shape.

VERDICT: NOT READY
