# Continuation — Google Receipt Ingestion (NOT YET BUILT) — Pascucci USA Inc

**Created**: 2026-06-04 · **Status**: OPEN / PARKED — backfill done by hand; live automation NOT built.
**Owner reminder**: pick this up when we learn how Google emails receipts. Until then, Google charges are
backfilled by hand from forwarded statements/invoices (see "What's already done").

> Companion docs: `docs/RECEIPT_INGESTION_META_GOOGLE.md` (overview, both vendors) and the working Meta
> job this must mirror. **Do not invent** the Google email format — confirm it from a real forwarded
> email before coding the parser.

---

## WHY THIS FILE EXISTS
Meta (Facebook) receipt ingestion is **LIVE and automated** (hourly mailbox poll → Purchase Invoice +
attached PDF). Google is **NOT**. Google's backfill was done manually this session. This file is the
single place that records exactly what is missing and how to finish it, so the thread is not lost.

---

## WHAT'S ALREADY DONE (manual backfill — do NOT redo)
- **Google Ads**: 7 statement charges (Apr+May) → PIs `00075-00081`, GL-invariant relink, each with its
  **monthly statement PDF** attached. Plus `$131.14` Jun-1 (Pending) → Outstanding PI `00086` + `june.png`.
  Supplier `Google`, expense `Google - PUI`, cc `Advertising - PUI`.
- **Google Workspace**: older charges → PIs `00082-00084` relinked (no attachment, no email on file);
  May invoice `5582237647` ($52.80, Pending) → Outstanding PI `00085` + emailed invoice PDF attached.
  Supplier `Google`, expense `Subscriptions & Services - PUI`, cc `Admin and Overheads - PUI`.
- Books verified to the cent (relinks invariant; only the 2 intended Pending accruals moved the ledger).
- Tooling used: `temp/google_invoices/google_backfill.py` (Ads statements), `temp/google_invoices/google_extras.py`
  (Workspace + $131.14). Both reuse `temp/meta_receipts/meta_ingest.py`.

## WHAT IS MISSING (the actual TODO)
1. **Confirm Google's email format** from a REAL forwarded email to `finanly@pascuccicoffee.com`:
   - Google Ads: does it email a **per-charge receipt** (like Meta) or **only a monthly statement** PDF?
     (Current evidence: monthly statement only — but verify.)
   - Google Workspace: monthly **invoice** email with a PDF attachment (per Luca; confirm sender + subject).
2. **Build the Google parser + ingestion**, mirroring the Meta job (see "How to build" below). Until the
   format is confirmed, this stays parked — backfill by hand from forwarded statements/invoices as above.

---

## HOW TO BUILD IT (mirror the proven Meta job)
The Meta path is the template. Reuse its shape exactly.

- **Meta job (the template to copy):**
  - Parser/PDF builder: `finanly/services/jobs/src/finanly_jobs/meta_receipts.py`
    (`fetch_meta_receipts()` READONLY IMAP, dedup by `transaction_id`, card-only; `build_receipt_pdf()` fpdf2).
  - Celery task: `finanly/services/jobs/src/finanly_jobs/tasks.py`
    (`meta_ad_receipts_ingest_all_tenants`).
  - Beat schedule: `finanly/services/jobs/src/finanly_jobs/celery_app.py`
    → `"meta-ad-receipts-ingest-hourly": crontab(minute=0)`. Add a Google entry beside it.
  - PI-create connector endpoint it calls: `POST /v1/ledger/ad-spend/purchase-invoices` on
    connector-erpnext (supplier/expense/cc/lines + render PDF + attach). Reuse the SAME endpoint for Google.

- **Google specifics to parameterize** (no new endpoint needed):
  - Supplier `Google`. Idempotency `bill_no`:
    - Ads per-charge → `GOOGLE-<transaction_id>` if a per-charge id exists; else `GOOGLE-<bank-txn-name>`
      (what the backfill used) when matching off the statement.
    - Workspace → `GOOGLE-WS-<invoice_number>` (e.g. `GOOGLE-WS-5582237647`).
  - Expense/cc:
    - Ads → `Google - PUI` / `Advertising - PUI`.
    - Workspace → `Subscriptions & Services - PUI` / `Admin and Overheads - PUI`.
  - Attachment: Ads → the **monthly statement PDF**; Workspace → the **email's PDF attachment**.

- **Two format branches:**
  - **If Google Ads emails per-charge receipts** → write a Google parser (mirror `fetch_meta_receipts`),
    one PI per charge with the email attached.
  - **If only monthly statements** → write a statement parser: read the "PAYMENTS RECEIVED" lines, create
    one PI per card charge (1:1 with bank txns so each can be matched), attach the statement PDF to each.
    This is exactly what `temp/google_invoices/google_backfill.py` did by hand.

- **Books safety (non-negotiable):** any new accrual must follow the same pattern — Outstanding PI now,
  user matches the bank txn later via the tool's "Match" (→ Payment Entry Dr A/P / Cr Mercury-9908).
  For relinking already-categorized charges, use the GL-invariant snapshot-verified relink (snapshot
  trial balance before/after; abort on any unexpected cent of movement).

## ACTIVATION CHECKLIST (when format is confirmed)
1. Add Google parser to `meta_receipts.py` sibling (e.g. `google_receipts.py`) or extend the job.
2. Add a Celery task + beat entry (hourly) in `tasks.py` / `celery_app.py`.
3. `poetry lock --no-update` in `finanly/services/jobs`, rebuild `jobs` + `jobs-beat`.
4. Ensure mailbox creds in compose env (`META_IMAP_*` already used; reuse the same mailbox).
5. Dry-run against the mailbox; verify each created PI is Outstanding + has the right attachment;
   verify Pascucci trial balance only moves by intended new accruals.

## CONSTRAINTS (carry forward)
- Pascucci must **NEVER** see the "Nourishing" name (DBA rule) — N/A for Google (vendor invoices), but keep
  the guard in mind for any generated document.
- Repo boundary: only `/home/docker/finanly.ai` is editable.
