Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(warehouse): add qonto supplier invoices and credit notes tables (#126974)

Tom Owersd10934cb8c68
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 298f8645b77a..9c81d950f50c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -9908,7 +9908,7 @@ Note: Official generated Swagger specs were inspected for monitoring, billing, m
## Qonto — **thin**
-Today (5): `bank_accounts`, `labels`, `memberships`, `transactions`, `transfers`
+Today (9): `bank_accounts`, `beneficiaries`, `client_invoices`, `credit_notes`, `labels`, `memberships`, `supplier_invoices`, `transactions`, `transfers`
Diffed against: <https://docs.qonto.com/llms.txt>
@@ -9916,10 +9916,10 @@ Diffed against: <https://docs.qonto.com/llms.txt>
- [ ] `Cash flow categories (GET /v2/cash_flow_categories)` — resolve transaction cash flow categories and subcategories into readable labels (high)
- [x] `SEPA beneficiaries (GET /v2/sepa/beneficiaries)` — resolve beneficiary identifiers in existing transfer records (high)
- [x] `Client invoices (GET /v2/client_invoices)` — analyze receivables, due dates, and invoice payment status (high)
-- [ ] `Supplier invoices (GET /v2/supplier_invoices)` — analyze payables and documents requiring payment or review (high)
+- [x] `Supplier invoices (GET /v2/supplier_invoices)` — analyze payables and documents requiring payment or review (high)
- [ ] `Teams (GET /v2/teams)` — group memberships and spending by organizational team (medium)
- [ ] `Clients (GET /v2/clients)` — enrich invoice analysis with customer identities and billing details (medium)
-- [ ] `Credit notes (GET /v2/credit_notes)` — reconcile refunded or reduced amounts against client invoices (medium)
+- [x] `Credit notes (GET /v2/credit_notes)` — reconcile refunded or reduced amounts against client invoices (medium)
- [ ] `Quotes (GET /v2/quotes)` — compare quoted sales with invoiced revenue (medium)
- [ ] `Requests (GET /v2/requests)` — measure spending requests, approval outcomes, and pending transfers (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/canonical_descriptions.py
index 25ebbb7ff5c6..1ab5751bb02c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/canonical_descriptions.py
@@ -86,4 +86,40 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"client": "Client that the invoice is addressed to.",
},
},
+ "supplier_invoices": {
+ "description": "Supplier invoices and documents awaiting review that the organization received.",
+ "docs_url": DOCS + "spend-management/supplier-invoices/list-supplier-invoices",
+ "columns": {
+ "id": "Unique supplier invoice identifier.",
+ "supplier_id": "Identifier of the supplier linked to the invoice.",
+ "supplier_name": "Name of the supplier.",
+ "invoice_number": "Invoice number.",
+ "status": "Invoice status, for example to_review, to_approve, awaiting_payment, scheduled, paid, or rejected.",
+ "total_amount": "Total invoice amount and currency.",
+ "payable_amount": "Amount left to pay and currency.",
+ "issue_date": "Date when the invoice was issued.",
+ "due_date": "Date when the invoice payment is due.",
+ "payment_date": "Date when the invoice was paid.",
+ "is_credit_note": "Whether the document is a credit note from the supplier.",
+ "created_at": "Time when the supplier invoice was created.",
+ "updated_at": "Time of the last supplier invoice update.",
+ },
+ },
+ "credit_notes": {
+ "description": "Credit notes that the organization issued against its client invoices.",
+ "docs_url": DOCS + "invoicing/credit-notes/list-credit-notes",
+ "columns": {
+ "id": "Unique credit note identifier.",
+ "invoice_id": "Identifier of the client invoice that the credit note is linked to.",
+ "number": "Credit note number.",
+ "issue_date": "Date when the credit note was issued.",
+ "invoice_issue_date": "Issue date of the linked client invoice.",
+ "currency": "Credit note currency.",
+ "total_amount_cents": "Total credit note amount in the smallest currency unit.",
+ "vat_amount_cents": "VAT amount in the smallest currency unit.",
+ "created_at": "Time when the credit note was created.",
+ "finalized_at": "Time when the credit note was finalized.",
+ "client": "Client that the credit note is addressed to.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/qonto.py b/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/qonto.py
index 1053416d629a..4249d6aae134 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/qonto.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/qonto.py
@@ -24,6 +24,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.qonto.sett
ENDPOINTS,
INCREMENTAL_FIELDS,
PERMISSION_ERROR,
+ SORT_ORDER,
)
@@ -69,15 +70,18 @@ def get_resource(name: str, incremental: bool, last_value: str | datetime | None
if name != "bank_accounts":
params["per_page"] = 100
if name in INCREMENTAL_FIELDS:
- params["sort_by"] = "updated_at:desc"
+ params["sort_by"] = f"updated_at:{SORT_ORDER[name]}"
if incremental and last_value is not None:
watermark = parse_datetime_value(last_value)
if watermark is None:
raise ValueError("Invalid Qonto incremental timestamp")
- params["updated_at_from"] = watermark.isoformat()
- if name == "client_invoices":
+ # Supplier invoices take their filters inside filter[...], unlike transactions and transfers.
+ filter_param = "filter[updated_at_from]" if name == "supplier_invoices" else "updated_at_from"
+ params[filter_param] = watermark.isoformat()
+ if name in ("client_invoices", "credit_notes"):
# Ascending creation order keeps earlier pages stable when new invoices arrive during a sync.
params["sort_by"] = "created_at:asc"
+ if name == "client_invoices":
# Qonto leaves out imported invoices unless the request asks for them.
params["exclude_imported"] = "false"
if name == "transactions":
@@ -150,5 +154,5 @@ def qonto_source(
name=endpoint,
items=lambda: selected,
primary_keys=["bank_account_id", "id"] if endpoint == "transactions" else ["id"],
- sort_mode="desc",
+ sort_mode=SORT_ORDER.get(endpoint, "desc"),
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/settings.py
index 9a30ff7712dc..370bb7284675 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/settings.py
@@ -1,3 +1,5 @@
+from typing import Literal
+
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
ENDPOINTS = {
@@ -8,6 +10,8 @@ ENDPOINTS = {
"transfers": ("sepa/transfers", "transfers"),
"beneficiaries": ("sepa/beneficiaries", "beneficiaries"),
"client_invoices": ("client_invoices", "client_invoices"),
+ "supplier_invoices": ("supplier_invoices", "supplier_invoices"),
+ "credit_notes": ("credit_notes", "credit_notes"),
}
INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
@@ -19,7 +23,14 @@ INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
"field_type": IncrementalFieldType.DateTime,
}
]
- for name in ("transactions", "transfers")
+ for name in ("transactions", "transfers", "supplier_invoices")
+}
+
+# Qonto's supplier invoice sync guide pages through updates in ascending order.
+SORT_ORDER: dict[str, Literal["asc", "desc"]] = {
+ "transactions": "desc",
+ "transfers": "desc",
+ "supplier_invoices": "asc",
}
AUTH_ERROR = "Qonto rejected the credentials. Check your organization login and secret key."
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/tests/test_qonto.py b/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/tests/test_qonto.py
index 04e81bc52fcd..c3cc4ebcc9e1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/tests/test_qonto.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/qonto/tests/test_qonto.py
@@ -67,9 +67,21 @@ def drive(endpoint: str, script: Script, **inputs: Any) -> DriveResult:
(True, datetime(2025, 1, 2, 3, 4, 5), "2025-01-02T03:04:05+00:00"),
],
)
[email protected]("endpoint", ["transactions", "transfers"])
+ ("endpoint", "filter_param", "sort"),
+ [
+ ("transactions", "updated_at_from", "desc"),
+ ("transfers", "updated_at_from", "desc"),
+ ("supplier_invoices", "filter[updated_at_from]", "asc"),
+ ],
+)
def test_incremental_filters(
- endpoint: str, incremental: bool, last_value: str | datetime | None, expected: str | None
+ endpoint: str,
+ filter_param: str,
+ sort: str,
+ incremental: bool,
+ last_value: str | datetime | None,
+ expected: str | None,
) -> None:
responses: list[ScriptedResponse | BaseException] = [
page(endpoint, [{"id": "row"}], 1, 2),
@@ -87,13 +99,13 @@ def test_incremental_filters(
requests = [request for request in result.requests if request.path != "/v2/organization"]
assert len(requests) == 2
for request in requests:
- assert request.param("updated_at_from") == expected
- assert request.query["sort_by"] == ("updated_at:desc",)
+ assert request.param(filter_param) == expected
+ assert request.query["sort_by"] == (f"updated_at:{sort}",)
if endpoint == "transactions":
assert request.query["status[]"] == ("pending", "declined", "completed", "reversed")
assert request.query["bank_account_id"] == ("account-1",)
assert result.response is not None
- assert result.response.sort_mode == "desc"
+ assert result.response.sort_mode == sort
@pytest.mark.parametrize(
@@ -106,6 +118,7 @@ def test_incremental_filters(
"client_invoices",
{"per_page": ("100",), "sort_by": ("created_at:asc",), "exclude_imported": ("false",)},
),
+ ("credit_notes", "credit_notes", {"per_page": ("100",), "sort_by": ("created_at:asc",)}),
],
)
def test_full_refresh_endpoints_walk_every_page(