Skip to content

Commit 89b88ac

Browse files
committed
feat(ledger): bank accounts read and link-bank-account facade
Regenerated from robosystems main after #1722: the link-bank-account operation, the bankAccounts GraphQL field and the schema snapshot. LedgerClient gains list_bank_accounts (the group's bank and card accounts with their entity, source and connection health) and link_bank_account (point a feed account at a chart account, including one in a subsidiary's chart). Claude-Session: https://claude.ai/code/session_01BY3uYE5zMjjFHnjiZfiJu8
1 parent ce83863 commit 89b88ac

14 files changed

Lines changed: 1061 additions & 0 deletions
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
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.error_response import ErrorResponse
10+
from ...models.link_bank_account_request import LinkBankAccountRequest
11+
from ...models.operation_envelope_link_bank_account_response import (
12+
OperationEnvelopeLinkBankAccountResponse,
13+
)
14+
from ...types import UNSET, Response, Unset
15+
16+
17+
def _get_kwargs(
18+
graph_id: str,
19+
*,
20+
body: LinkBankAccountRequest,
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/link-bank-account".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 | OperationEnvelopeLinkBankAccountResponse | None:
45+
if response.status_code == 200:
46+
response_200 = OperationEnvelopeLinkBankAccountResponse.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 | OperationEnvelopeLinkBankAccountResponse]:
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: LinkBankAccountRequest,
112+
idempotency_key: None | str | Unset = UNSET,
113+
) -> Response[ErrorResponse | OperationEnvelopeLinkBankAccountResponse]:
114+
"""Link Bank Account
115+
116+
Point a bank feed's account at a chart account. Name `element_id` for an existing active account, or
117+
`entity_id` alone to create one in that entity's chart. The chart the account is in decides whose
118+
books the feed's lines go into, so this is also how a feed account is bound to a subsidiary. Lines
119+
still in the inbox move with it (across an entity change their suggestion is resolved again on the
120+
new chart, and a classification that named the old entity's account is dropped); posted entries stay
121+
where they were posted. An account another connection already feeds is refused. An account the feed
122+
created and then left stays on its chart as an ordinary account. A sync already in flight when the
123+
link moves can still land a line or two on the old account; running this again moves them. Read the
124+
group's accounts with the `bankAccounts` GraphQL field.
125+
126+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
127+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
128+
129+
Args:
130+
graph_id (str):
131+
idempotency_key (None | str | Unset):
132+
body (LinkBankAccountRequest): Point a bank feed's account at a chart account.
133+
134+
Name `element_id` for an existing active account, or `entity_id` alone to
135+
create one in that entity's chart. The chart the account is in decides
136+
whose books the feed's lines go into, so this is also how a feed account
137+
is bound to a subsidiary. Lines still in the inbox move with it; posted
138+
entries stay where they were posted.
139+
140+
Raises:
141+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
142+
httpx.TimeoutException: If the request takes longer than Client.timeout.
143+
144+
Returns:
145+
Response[ErrorResponse | OperationEnvelopeLinkBankAccountResponse]
146+
"""
147+
148+
kwargs = _get_kwargs(
149+
graph_id=graph_id,
150+
body=body,
151+
idempotency_key=idempotency_key,
152+
)
153+
154+
response = client.get_httpx_client().request(
155+
**kwargs,
156+
)
157+
158+
return _build_response(client=client, response=response)
159+
160+
161+
def sync(
162+
graph_id: str,
163+
*,
164+
client: AuthenticatedClient,
165+
body: LinkBankAccountRequest,
166+
idempotency_key: None | str | Unset = UNSET,
167+
) -> ErrorResponse | OperationEnvelopeLinkBankAccountResponse | None:
168+
"""Link Bank Account
169+
170+
Point a bank feed's account at a chart account. Name `element_id` for an existing active account, or
171+
`entity_id` alone to create one in that entity's chart. The chart the account is in decides whose
172+
books the feed's lines go into, so this is also how a feed account is bound to a subsidiary. Lines
173+
still in the inbox move with it (across an entity change their suggestion is resolved again on the
174+
new chart, and a classification that named the old entity's account is dropped); posted entries stay
175+
where they were posted. An account another connection already feeds is refused. An account the feed
176+
created and then left stays on its chart as an ordinary account. A sync already in flight when the
177+
link moves can still land a line or two on the old account; running this again moves them. Read the
178+
group's accounts with the `bankAccounts` GraphQL field.
179+
180+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
181+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
182+
183+
Args:
184+
graph_id (str):
185+
idempotency_key (None | str | Unset):
186+
body (LinkBankAccountRequest): Point a bank feed's account at a chart account.
187+
188+
Name `element_id` for an existing active account, or `entity_id` alone to
189+
create one in that entity's chart. The chart the account is in decides
190+
whose books the feed's lines go into, so this is also how a feed account
191+
is bound to a subsidiary. Lines still in the inbox move with it; posted
192+
entries stay where they were posted.
193+
194+
Raises:
195+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
196+
httpx.TimeoutException: If the request takes longer than Client.timeout.
197+
198+
Returns:
199+
ErrorResponse | OperationEnvelopeLinkBankAccountResponse
200+
"""
201+
202+
return sync_detailed(
203+
graph_id=graph_id,
204+
client=client,
205+
body=body,
206+
idempotency_key=idempotency_key,
207+
).parsed
208+
209+
210+
async def asyncio_detailed(
211+
graph_id: str,
212+
*,
213+
client: AuthenticatedClient,
214+
body: LinkBankAccountRequest,
215+
idempotency_key: None | str | Unset = UNSET,
216+
) -> Response[ErrorResponse | OperationEnvelopeLinkBankAccountResponse]:
217+
"""Link Bank Account
218+
219+
Point a bank feed's account at a chart account. Name `element_id` for an existing active account, or
220+
`entity_id` alone to create one in that entity's chart. The chart the account is in decides whose
221+
books the feed's lines go into, so this is also how a feed account is bound to a subsidiary. Lines
222+
still in the inbox move with it (across an entity change their suggestion is resolved again on the
223+
new chart, and a classification that named the old entity's account is dropped); posted entries stay
224+
where they were posted. An account another connection already feeds is refused. An account the feed
225+
created and then left stays on its chart as an ordinary account. A sync already in flight when the
226+
link moves can still land a line or two on the old account; running this again moves them. Read the
227+
group's accounts with the `bankAccounts` GraphQL field.
228+
229+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
230+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
231+
232+
Args:
233+
graph_id (str):
234+
idempotency_key (None | str | Unset):
235+
body (LinkBankAccountRequest): Point a bank feed's account at a chart account.
236+
237+
Name `element_id` for an existing active account, or `entity_id` alone to
238+
create one in that entity's chart. The chart the account is in decides
239+
whose books the feed's lines go into, so this is also how a feed account
240+
is bound to a subsidiary. Lines still in the inbox move with it; posted
241+
entries stay where they were posted.
242+
243+
Raises:
244+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
245+
httpx.TimeoutException: If the request takes longer than Client.timeout.
246+
247+
Returns:
248+
Response[ErrorResponse | OperationEnvelopeLinkBankAccountResponse]
249+
"""
250+
251+
kwargs = _get_kwargs(
252+
graph_id=graph_id,
253+
body=body,
254+
idempotency_key=idempotency_key,
255+
)
256+
257+
response = await client.get_async_httpx_client().request(**kwargs)
258+
259+
return _build_response(client=client, response=response)
260+
261+
262+
async def asyncio(
263+
graph_id: str,
264+
*,
265+
client: AuthenticatedClient,
266+
body: LinkBankAccountRequest,
267+
idempotency_key: None | str | Unset = UNSET,
268+
) -> ErrorResponse | OperationEnvelopeLinkBankAccountResponse | None:
269+
"""Link Bank Account
270+
271+
Point a bank feed's account at a chart account. Name `element_id` for an existing active account, or
272+
`entity_id` alone to create one in that entity's chart. The chart the account is in decides whose
273+
books the feed's lines go into, so this is also how a feed account is bound to a subsidiary. Lines
274+
still in the inbox move with it (across an entity change their suggestion is resolved again on the
275+
new chart, and a classification that named the old entity's account is dropped); posted entries stay
276+
where they were posted. An account another connection already feeds is refused. An account the feed
277+
created and then left stays on its chart as an ordinary account. A sync already in flight when the
278+
link moves can still land a line or two on the old account; running this again moves them. Read the
279+
group's accounts with the `bankAccounts` GraphQL field.
280+
281+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
282+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
283+
284+
Args:
285+
graph_id (str):
286+
idempotency_key (None | str | Unset):
287+
body (LinkBankAccountRequest): Point a bank feed's account at a chart account.
288+
289+
Name `element_id` for an existing active account, or `entity_id` alone to
290+
create one in that entity's chart. The chart the account is in decides
291+
whose books the feed's lines go into, so this is also how a feed account
292+
is bound to a subsidiary. Lines still in the inbox move with it; posted
293+
entries stay where they were posted.
294+
295+
Raises:
296+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
297+
httpx.TimeoutException: If the request takes longer than Client.timeout.
298+
299+
Returns:
300+
ErrorResponse | OperationEnvelopeLinkBankAccountResponse
301+
"""
302+
303+
return (
304+
await asyncio_detailed(
305+
graph_id=graph_id,
306+
client=client,
307+
body=body,
308+
idempotency_key=idempotency_key,
309+
)
310+
).parsed

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@
135135
from ..api.robo_ledger_setup.create_entity import (
136136
sync_detailed as op_create_entity,
137137
)
138+
from ..api.robo_ledger_setup.link_bank_account import (
139+
sync_detailed as op_link_bank_account,
140+
)
138141
from ..api.robo_ledger_setup.update_entity import (
139142
sync_detailed as op_update_entity,
140143
)
@@ -224,6 +227,12 @@
224227
from ..graphql.generated.get_ledger_account_tree import (
225228
GetLedgerAccountTreeAccountTree as LedgerAccountTree,
226229
)
230+
from ..graphql.generated.list_ledger_bank_accounts import (
231+
ListLedgerBankAccounts,
232+
)
233+
from ..graphql.generated.list_ledger_bank_accounts import (
234+
ListLedgerBankAccountsBankAccounts as LedgerBankAccountList,
235+
)
227236
from ..graphql.generated.get_ledger_agent import (
228237
GetLedgerAgent,
229238
)
@@ -428,6 +437,7 @@
428437
GET_LEDGER_ACCOUNT_ROLLUPS_GQL,
429438
GET_LEDGER_ACCOUNT_TREE_GQL,
430439
GET_LEDGER_AGENT_GQL,
440+
LIST_LEDGER_BANK_ACCOUNTS_GQL,
431441
GET_LEDGER_CLOSING_BOOK_STRUCTURES_GQL,
432442
GET_LEDGER_ENTITY_GQL,
433443
GET_LEDGER_EVENT_BLOCK_GQL,
@@ -469,6 +479,8 @@
469479
from ..models.auto_map_elements_operation import AutoMapElementsOperation
470480
from ..models.create_agent_request import CreateAgentRequest
471481
from ..models.create_entity_request import CreateEntityRequest
482+
from ..models.link_bank_account_request import LinkBankAccountRequest
483+
from ..models.link_bank_account_response import LinkBankAccountResponse
472484
from ..models.create_event_block_request import CreateEventBlockRequest
473485
from ..models.create_event_block_request_event_category import (
474486
CreateEventBlockRequestEventCategory,
@@ -945,6 +957,41 @@ def get_account_tree(
945957
data = self._query(graph_id, GET_LEDGER_ACCOUNT_TREE_GQL, self._scope(entity_id))
946958
return GetLedgerAccountTree.model_validate(data).account_tree
947959

960+
# ── Bank accounts ───────────────────────────────────────────────────
961+
962+
def list_bank_accounts(
963+
self, graph_id: str, entity_id: str | None = None
964+
) -> LedgerBankAccountList | None:
965+
"""The group's bank and card accounts.
966+
967+
Every chart account a feed books to, or that a source system types as a
968+
bank or card account, with the entity whose chart it is in (the books
969+
its lines go into), what writes to it (``source``: a feed provider,
970+
``quickbooks``, or None for an account kept by hand) and the connection's
971+
status and last sync. ``entity_id`` narrows to one entity; None is the
972+
whole group.
973+
"""
974+
data = self._query(graph_id, LIST_LEDGER_BANK_ACCOUNTS_GQL, {"entityId": entity_id})
975+
return ListLedgerBankAccounts.model_validate(data).bank_accounts
976+
977+
def link_bank_account(
978+
self, graph_id: str, body: dict[str, Any]
979+
) -> LinkBankAccountResponse:
980+
"""Point a bank feed's account at a chart account.
981+
982+
``element_id`` links an existing account (its chart's entity takes the
983+
feed); ``entity_id`` alone creates one in that entity's chart. This is
984+
how a feed account is bound to a subsidiary: lines still in the inbox
985+
move with it, posted entries stay where they were posted. An account
986+
another connection already feeds is refused.
987+
"""
988+
request = LinkBankAccountRequest.from_dict(body)
989+
response = op_link_bank_account(
990+
graph_id=graph_id, body=request, client=self._get_client()
991+
)
992+
envelope = self._call_op("Link bank account", response)
993+
return self._typed_result("Link bank account", envelope, LinkBankAccountResponse)
994+
948995
def get_account_rollups(
949996
self,
950997
graph_id: str,

0 commit comments

Comments
 (0)