Skip to content

Commit 5a3474a

Browse files
authored
feat(ledger): flow candidates, classification stats, and accepting suggestions in bulk (#251)
## What The Python equivalent of typescript-client #267 (v2.12.1) and #268, which went out without it. - **`get_flow_candidates(graph_id, entity_id=)`** → `flowCandidates`: the leaf investing and financing rows of the entity's cash flow statement, the set a bank line's `classified_flow_qname` may take. - **`get_classification_stats(graph_id, period, entity_id=)`** → `classificationStats`: per suggestion source, lines accepted, overridden, split or chosen with no suggestion; the share that needed a person; `unstamped` for lines posted before outcomes were recorded; `None` when the ledger is not initialized. - **`accept_suggestions(graph_id, body=)`** → the `accept-suggestions` operation: filters, explicit `event_ids`, `commit`, `dry_run`, `limit`; the result carries the counts, `truncated`, and every line with its outcome or skip reason. - Operation documents `FlowCandidates.graphql` and `ClassificationStats.graphql`; `schema.graphql` refreshed; `graphql/generated` regenerated (the drift gate is clean); `api/` and `models/` regenerated from the local stack on robosystems #1800. Beyond the new operation and its models, the regenerated diff is comment strings on existing request models. ## Waits on The server read and operation ship in the **next robosystems release after v1.16.16**, carrying #1799 (`flowCandidates`) and #1800 (`classificationStats`, `accept-suggestions`). Until it is in prod, the two reads fail GraphQL validation there and the operation answers 404. Additive: a **minor**. No stable-tier change; the integration template's emit symbols are untouched. ## Tests 6 new in `tests/test_ledger_client.py`: the flow rows and the entity default, the stats shape and the null case, the batch's body and result, and the empty-body default. `just lint`, `just typecheck`, `just test`: 687 passed, 17 skipped. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_014Wxgk4yttBxgdE2uBHT71R
2 parents 39deae7 + 419f597 commit 5a3474a

24 files changed

Lines changed: 1619 additions & 46 deletions

‎robosystems_client/api/connections/oauth_callback.py‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ def sync_detailed(
108108
109109
Completes the OAuth authorization flow after provider redirect. Exchanges the authorization code for
110110
tokens, stores them, and triggers an initial sync. This is a redirect target — not typically called
111-
directly. Plaid: pass Link's public_token as `code`; a bank already connected to the graph is
112-
refused (409 DUPLICATE_BANK_CONNECTION).
111+
directly. QuickBooks: only the company that built the graph's books may connect to them; another
112+
company is refused (409 OTHER_COMPANY_BOOKS) before any token is issued. Plaid: pass Link's
113+
public_token as `code`; a bank already connected to the graph is refused (409
114+
DUPLICATE_BANK_CONNECTION).
113115
114116
Args:
115117
graph_id (str):
@@ -148,8 +150,10 @@ def sync(
148150
149151
Completes the OAuth authorization flow after provider redirect. Exchanges the authorization code for
150152
tokens, stores them, and triggers an initial sync. This is a redirect target — not typically called
151-
directly. Plaid: pass Link's public_token as `code`; a bank already connected to the graph is
152-
refused (409 DUPLICATE_BANK_CONNECTION).
153+
directly. QuickBooks: only the company that built the graph's books may connect to them; another
154+
company is refused (409 OTHER_COMPANY_BOOKS) before any token is issued. Plaid: pass Link's
155+
public_token as `code`; a bank already connected to the graph is refused (409
156+
DUPLICATE_BANK_CONNECTION).
153157
154158
Args:
155159
graph_id (str):
@@ -183,8 +187,10 @@ async def asyncio_detailed(
183187
184188
Completes the OAuth authorization flow after provider redirect. Exchanges the authorization code for
185189
tokens, stores them, and triggers an initial sync. This is a redirect target — not typically called
186-
directly. Plaid: pass Link's public_token as `code`; a bank already connected to the graph is
187-
refused (409 DUPLICATE_BANK_CONNECTION).
190+
directly. QuickBooks: only the company that built the graph's books may connect to them; another
191+
company is refused (409 OTHER_COMPANY_BOOKS) before any token is issued. Plaid: pass Link's
192+
public_token as `code`; a bank already connected to the graph is refused (409
193+
DUPLICATE_BANK_CONNECTION).
188194
189195
Args:
190196
graph_id (str):
@@ -221,8 +227,10 @@ async def asyncio(
221227
222228
Completes the OAuth authorization flow after provider redirect. Exchanges the authorization code for
223229
tokens, stores them, and triggers an initial sync. This is a redirect target — not typically called
224-
directly. Plaid: pass Link's public_token as `code`; a bank already connected to the graph is
225-
refused (409 DUPLICATE_BANK_CONNECTION).
230+
directly. QuickBooks: only the company that built the graph's books may connect to them; another
231+
company is refused (409 OTHER_COMPANY_BOOKS) before any token is issued. Plaid: pass Link's
232+
public_token as `code`; a bank already connected to the graph is refused (409
233+
DUPLICATE_BANK_CONNECTION).
226234
227235
Args:
228236
graph_id (str):

‎robosystems_client/api/robo_ledger_fiscal_close/rebuild_schedule.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ def sync_detailed(
138138
monthly_amount / period bounds on the Structure's metadata).
139139
140140
The historical-vs-in-scope split is re-derived from the CURRENT fiscal
141-
calendar `closed_through`, so a rebuild re-scopes the schedule to
142-
today's close state. Use this to pick up a fixed generator (e.g. the
141+
calendar (months through its `closed_through`, or before its first
142+
month, are history), so a rebuild re-scopes the schedule to today's
143+
close state. Use this to pick up a fixed generator (e.g. the
143144
roll-forward direction fix) without orphaning obligations.
144145
145146
Raises:
@@ -197,8 +198,9 @@ def sync(
197198
monthly_amount / period bounds on the Structure's metadata).
198199
199200
The historical-vs-in-scope split is re-derived from the CURRENT fiscal
200-
calendar `closed_through`, so a rebuild re-scopes the schedule to
201-
today's close state. Use this to pick up a fixed generator (e.g. the
201+
calendar (months through its `closed_through`, or before its first
202+
month, are history), so a rebuild re-scopes the schedule to today's
203+
close state. Use this to pick up a fixed generator (e.g. the
202204
roll-forward direction fix) without orphaning obligations.
203205
204206
Raises:
@@ -251,8 +253,9 @@ async def asyncio_detailed(
251253
monthly_amount / period bounds on the Structure's metadata).
252254
253255
The historical-vs-in-scope split is re-derived from the CURRENT fiscal
254-
calendar `closed_through`, so a rebuild re-scopes the schedule to
255-
today's close state. Use this to pick up a fixed generator (e.g. the
256+
calendar (months through its `closed_through`, or before its first
257+
month, are history), so a rebuild re-scopes the schedule to today's
258+
close state. Use this to pick up a fixed generator (e.g. the
256259
roll-forward direction fix) without orphaning obligations.
257260
258261
Raises:
@@ -308,8 +311,9 @@ async def asyncio(
308311
monthly_amount / period bounds on the Structure's metadata).
309312
310313
The historical-vs-in-scope split is re-derived from the CURRENT fiscal
311-
calendar `closed_through`, so a rebuild re-scopes the schedule to
312-
today's close state. Use this to pick up a fixed generator (e.g. the
314+
calendar (months through its `closed_through`, or before its first
315+
month, are history), so a rebuild re-scopes the schedule to today's
316+
close state. Use this to pick up a fixed generator (e.g. the
313317
roll-forward direction fix) without orphaning obligations.
314318
315319
Raises:
Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
from http import HTTPStatus
2+
from typing import Any
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.accept_suggestions_request import AcceptSuggestionsRequest
10+
from ...models.error_response import ErrorResponse
11+
from ...models.operation_envelope_accept_suggestions_response import (
12+
OperationEnvelopeAcceptSuggestionsResponse,
13+
)
14+
from ...types import UNSET, Response, Unset
15+
16+
17+
def _get_kwargs(
18+
graph_id: str,
19+
*,
20+
body: AcceptSuggestionsRequest,
21+
idempotency_key: None | str | Unset = UNSET,
22+
) -> dict[str, Any]:
23+
headers: dict[str, Any] = {}
24+
if not isinstance(idempotency_key, Unset):
25+
headers["Idempotency-Key"] = idempotency_key
26+
27+
_kwargs: dict[str, Any] = {
28+
"method": "post",
29+
"url": "/extensions/roboledger/{graph_id}/operations/accept-suggestions".format(
30+
graph_id=quote(str(graph_id), safe=""),
31+
),
32+
}
33+
34+
_kwargs["json"] = body.to_dict()
35+
36+
headers["Content-Type"] = "application/json"
37+
38+
_kwargs["headers"] = headers
39+
return _kwargs
40+
41+
42+
def _parse_response(
43+
*, client: AuthenticatedClient | Client, response: httpx.Response
44+
) -> ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse | None:
45+
if response.status_code == 200:
46+
response_200 = OperationEnvelopeAcceptSuggestionsResponse.from_dict(response.json())
47+
48+
return response_200
49+
50+
if response.status_code == 400:
51+
response_400 = ErrorResponse.from_dict(response.json())
52+
53+
return response_400
54+
55+
if response.status_code == 401:
56+
response_401 = ErrorResponse.from_dict(response.json())
57+
58+
return response_401
59+
60+
if response.status_code == 403:
61+
response_403 = ErrorResponse.from_dict(response.json())
62+
63+
return response_403
64+
65+
if response.status_code == 404:
66+
response_404 = ErrorResponse.from_dict(response.json())
67+
68+
return response_404
69+
70+
if response.status_code == 409:
71+
response_409 = ErrorResponse.from_dict(response.json())
72+
73+
return response_409
74+
75+
if response.status_code == 422:
76+
response_422 = ErrorResponse.from_dict(response.json())
77+
78+
return response_422
79+
80+
if response.status_code == 429:
81+
response_429 = ErrorResponse.from_dict(response.json())
82+
83+
return response_429
84+
85+
if response.status_code == 500:
86+
response_500 = ErrorResponse.from_dict(response.json())
87+
88+
return response_500
89+
90+
if client.raise_on_unexpected_status:
91+
raise errors.UnexpectedStatus(response.status_code, response.content)
92+
else:
93+
return None
94+
95+
96+
def _build_response(
97+
*, client: AuthenticatedClient | Client, response: httpx.Response
98+
) -> Response[ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse]:
99+
return Response(
100+
status_code=HTTPStatus(response.status_code),
101+
content=response.content,
102+
headers=response.headers,
103+
parsed=_parse_response(client=client, response=response),
104+
)
105+
106+
107+
def sync_detailed(
108+
graph_id: str,
109+
*,
110+
client: AuthenticatedClient,
111+
body: AcceptSuggestionsRequest,
112+
idempotency_key: None | str | Unset = UNSET,
113+
) -> Response[ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse]:
114+
"""Accept Suggestions
115+
116+
Take the suggestion on every open bank line the filters select, oldest first: each is classified to
117+
its `suggested_element_id` through the same update a single line goes through, and posted too with
118+
`commit: true`. Select by `source`, `agent_id`, `suggestion_source` (`agent_default` for the learned
119+
ones), a date range, or explicit `event_ids` from a multi-select. A line it cannot take — no
120+
suggestion to take, already classified or posted, a closed month, a choice the handler refuses —
121+
comes back `skipped` with the reason, never forced. `dry_run: true` reports the counts without
122+
writing; `limit` bounds a call and `truncated` says more matched.
123+
124+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
125+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
126+
127+
Args:
128+
graph_id (str):
129+
idempotency_key (None | str | Unset):
130+
body (AcceptSuggestionsRequest): Take the suggestion on every open bank line the filters
131+
select.
132+
133+
Raises:
134+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
135+
httpx.TimeoutException: If the request takes longer than Client.timeout.
136+
137+
Returns:
138+
Response[ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse]
139+
"""
140+
141+
kwargs = _get_kwargs(
142+
graph_id=graph_id,
143+
body=body,
144+
idempotency_key=idempotency_key,
145+
)
146+
147+
response = client.get_httpx_client().request(
148+
**kwargs,
149+
)
150+
151+
return _build_response(client=client, response=response)
152+
153+
154+
def sync(
155+
graph_id: str,
156+
*,
157+
client: AuthenticatedClient,
158+
body: AcceptSuggestionsRequest,
159+
idempotency_key: None | str | Unset = UNSET,
160+
) -> ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse | None:
161+
"""Accept Suggestions
162+
163+
Take the suggestion on every open bank line the filters select, oldest first: each is classified to
164+
its `suggested_element_id` through the same update a single line goes through, and posted too with
165+
`commit: true`. Select by `source`, `agent_id`, `suggestion_source` (`agent_default` for the learned
166+
ones), a date range, or explicit `event_ids` from a multi-select. A line it cannot take — no
167+
suggestion to take, already classified or posted, a closed month, a choice the handler refuses —
168+
comes back `skipped` with the reason, never forced. `dry_run: true` reports the counts without
169+
writing; `limit` bounds a call and `truncated` says more matched.
170+
171+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
172+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
173+
174+
Args:
175+
graph_id (str):
176+
idempotency_key (None | str | Unset):
177+
body (AcceptSuggestionsRequest): Take the suggestion on every open bank line the filters
178+
select.
179+
180+
Raises:
181+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
182+
httpx.TimeoutException: If the request takes longer than Client.timeout.
183+
184+
Returns:
185+
ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse
186+
"""
187+
188+
return sync_detailed(
189+
graph_id=graph_id,
190+
client=client,
191+
body=body,
192+
idempotency_key=idempotency_key,
193+
).parsed
194+
195+
196+
async def asyncio_detailed(
197+
graph_id: str,
198+
*,
199+
client: AuthenticatedClient,
200+
body: AcceptSuggestionsRequest,
201+
idempotency_key: None | str | Unset = UNSET,
202+
) -> Response[ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse]:
203+
"""Accept Suggestions
204+
205+
Take the suggestion on every open bank line the filters select, oldest first: each is classified to
206+
its `suggested_element_id` through the same update a single line goes through, and posted too with
207+
`commit: true`. Select by `source`, `agent_id`, `suggestion_source` (`agent_default` for the learned
208+
ones), a date range, or explicit `event_ids` from a multi-select. A line it cannot take — no
209+
suggestion to take, already classified or posted, a closed month, a choice the handler refuses —
210+
comes back `skipped` with the reason, never forced. `dry_run: true` reports the counts without
211+
writing; `limit` bounds a call and `truncated` says more matched.
212+
213+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
214+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
215+
216+
Args:
217+
graph_id (str):
218+
idempotency_key (None | str | Unset):
219+
body (AcceptSuggestionsRequest): Take the suggestion on every open bank line the filters
220+
select.
221+
222+
Raises:
223+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
224+
httpx.TimeoutException: If the request takes longer than Client.timeout.
225+
226+
Returns:
227+
Response[ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse]
228+
"""
229+
230+
kwargs = _get_kwargs(
231+
graph_id=graph_id,
232+
body=body,
233+
idempotency_key=idempotency_key,
234+
)
235+
236+
response = await client.get_async_httpx_client().request(**kwargs)
237+
238+
return _build_response(client=client, response=response)
239+
240+
241+
async def asyncio(
242+
graph_id: str,
243+
*,
244+
client: AuthenticatedClient,
245+
body: AcceptSuggestionsRequest,
246+
idempotency_key: None | str | Unset = UNSET,
247+
) -> ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse | None:
248+
"""Accept Suggestions
249+
250+
Take the suggestion on every open bank line the filters select, oldest first: each is classified to
251+
its `suggested_element_id` through the same update a single line goes through, and posted too with
252+
`commit: true`. Select by `source`, `agent_id`, `suggestion_source` (`agent_default` for the learned
253+
ones), a date range, or explicit `event_ids` from a multi-select. A line it cannot take — no
254+
suggestion to take, already classified or posted, a closed month, a choice the handler refuses —
255+
comes back `skipped` with the reason, never forced. `dry_run: true` reports the counts without
256+
writing; `limit` bounds a call and `truncated` says more matched.
257+
258+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
259+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
260+
261+
Args:
262+
graph_id (str):
263+
idempotency_key (None | str | Unset):
264+
body (AcceptSuggestionsRequest): Take the suggestion on every open bank line the filters
265+
select.
266+
267+
Raises:
268+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
269+
httpx.TimeoutException: If the request takes longer than Client.timeout.
270+
271+
Returns:
272+
ErrorResponse | OperationEnvelopeAcceptSuggestionsResponse
273+
"""
274+
275+
return (
276+
await asyncio_detailed(
277+
graph_id=graph_id,
278+
client=client,
279+
body=body,
280+
idempotency_key=idempotency_key,
281+
)
282+
).parsed

0 commit comments

Comments
 (0)