Skip to content

Commit c8e4ba4

Browse files
committed
feat(ledger): a counterparty's default account, and learning defaults from history
Regenerated against robosystems v1.16.14. get_agent and list_agents select the agent's classification; update_agent accepts classification_element_id and classification_mode in its body; learn_classification_defaults is new. Claude-Session: https://claude.ai/code/session_01AQkGGPDmpba9eBV9PkLTfv
1 parent 9b1e5cb commit c8e4ba4

22 files changed

Lines changed: 1128 additions & 9 deletions
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.error_response import ErrorResponse
10+
from ...models.learn_classification_defaults_request import (
11+
LearnClassificationDefaultsRequest,
12+
)
13+
from ...models.operation_envelope_learn_classification_defaults_response import (
14+
OperationEnvelopeLearnClassificationDefaultsResponse,
15+
)
16+
from ...types import UNSET, Response, Unset
17+
18+
19+
def _get_kwargs(
20+
graph_id: str,
21+
*,
22+
body: LearnClassificationDefaultsRequest,
23+
idempotency_key: None | str | Unset = UNSET,
24+
) -> dict[str, Any]:
25+
headers: dict[str, Any] = {}
26+
if not isinstance(idempotency_key, Unset):
27+
headers["Idempotency-Key"] = idempotency_key
28+
29+
_kwargs: dict[str, Any] = {
30+
"method": "post",
31+
"url": "/extensions/roboledger/{graph_id}/operations/learn-classification-defaults".format(
32+
graph_id=quote(str(graph_id), safe=""),
33+
),
34+
}
35+
36+
_kwargs["json"] = body.to_dict()
37+
38+
headers["Content-Type"] = "application/json"
39+
40+
_kwargs["headers"] = headers
41+
return _kwargs
42+
43+
44+
def _parse_response(
45+
*, client: AuthenticatedClient | Client, response: httpx.Response
46+
) -> ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse | None:
47+
if response.status_code == 200:
48+
response_200 = OperationEnvelopeLearnClassificationDefaultsResponse.from_dict(
49+
response.json()
50+
)
51+
52+
return response_200
53+
54+
if response.status_code == 400:
55+
response_400 = ErrorResponse.from_dict(response.json())
56+
57+
return response_400
58+
59+
if response.status_code == 401:
60+
response_401 = ErrorResponse.from_dict(response.json())
61+
62+
return response_401
63+
64+
if response.status_code == 403:
65+
response_403 = ErrorResponse.from_dict(response.json())
66+
67+
return response_403
68+
69+
if response.status_code == 404:
70+
response_404 = ErrorResponse.from_dict(response.json())
71+
72+
return response_404
73+
74+
if response.status_code == 409:
75+
response_409 = ErrorResponse.from_dict(response.json())
76+
77+
return response_409
78+
79+
if response.status_code == 422:
80+
response_422 = ErrorResponse.from_dict(response.json())
81+
82+
return response_422
83+
84+
if response.status_code == 429:
85+
response_429 = ErrorResponse.from_dict(response.json())
86+
87+
return response_429
88+
89+
if response.status_code == 500:
90+
response_500 = ErrorResponse.from_dict(response.json())
91+
92+
return response_500
93+
94+
if client.raise_on_unexpected_status:
95+
raise errors.UnexpectedStatus(response.status_code, response.content)
96+
else:
97+
return None
98+
99+
100+
def _build_response(
101+
*, client: AuthenticatedClient | Client, response: httpx.Response
102+
) -> Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]:
103+
return Response(
104+
status_code=HTTPStatus(response.status_code),
105+
content=response.content,
106+
headers=response.headers,
107+
parsed=_parse_response(client=client, response=response),
108+
)
109+
110+
111+
def sync_detailed(
112+
graph_id: str,
113+
*,
114+
client: AuthenticatedClient,
115+
body: LearnClassificationDefaultsRequest,
116+
idempotency_key: None | str | Unset = UNSET,
117+
) -> Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]:
118+
"""Learn Classification Defaults
119+
120+
Seed each counterparty's default account from the bank lines already committed to the books: the
121+
account most of its lines went to becomes its default, with the lines that agreed counted as
122+
confirmations. A counterparty that already has a default keeps it. Its still-open lines are then
123+
suggested from the default. Run it once on books that were classified before defaults were learned;
124+
after that, every commit teaches the default by itself. `dry_run` reports what would be learned
125+
without writing it.
126+
127+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
128+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
129+
130+
Args:
131+
graph_id (str):
132+
idempotency_key (None | str | Unset):
133+
body (LearnClassificationDefaultsRequest): Seed counterparty defaults from the bank lines
134+
already committed.
135+
136+
Raises:
137+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
138+
httpx.TimeoutException: If the request takes longer than Client.timeout.
139+
140+
Returns:
141+
Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]
142+
"""
143+
144+
kwargs = _get_kwargs(
145+
graph_id=graph_id,
146+
body=body,
147+
idempotency_key=idempotency_key,
148+
)
149+
150+
response = client.get_httpx_client().request(
151+
**kwargs,
152+
)
153+
154+
return _build_response(client=client, response=response)
155+
156+
157+
def sync(
158+
graph_id: str,
159+
*,
160+
client: AuthenticatedClient,
161+
body: LearnClassificationDefaultsRequest,
162+
idempotency_key: None | str | Unset = UNSET,
163+
) -> ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse | None:
164+
"""Learn Classification Defaults
165+
166+
Seed each counterparty's default account from the bank lines already committed to the books: the
167+
account most of its lines went to becomes its default, with the lines that agreed counted as
168+
confirmations. A counterparty that already has a default keeps it. Its still-open lines are then
169+
suggested from the default. Run it once on books that were classified before defaults were learned;
170+
after that, every commit teaches the default by itself. `dry_run` reports what would be learned
171+
without writing it.
172+
173+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
174+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
175+
176+
Args:
177+
graph_id (str):
178+
idempotency_key (None | str | Unset):
179+
body (LearnClassificationDefaultsRequest): Seed counterparty defaults from the bank lines
180+
already committed.
181+
182+
Raises:
183+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
184+
httpx.TimeoutException: If the request takes longer than Client.timeout.
185+
186+
Returns:
187+
ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse
188+
"""
189+
190+
return sync_detailed(
191+
graph_id=graph_id,
192+
client=client,
193+
body=body,
194+
idempotency_key=idempotency_key,
195+
).parsed
196+
197+
198+
async def asyncio_detailed(
199+
graph_id: str,
200+
*,
201+
client: AuthenticatedClient,
202+
body: LearnClassificationDefaultsRequest,
203+
idempotency_key: None | str | Unset = UNSET,
204+
) -> Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]:
205+
"""Learn Classification Defaults
206+
207+
Seed each counterparty's default account from the bank lines already committed to the books: the
208+
account most of its lines went to becomes its default, with the lines that agreed counted as
209+
confirmations. A counterparty that already has a default keeps it. Its still-open lines are then
210+
suggested from the default. Run it once on books that were classified before defaults were learned;
211+
after that, every commit teaches the default by itself. `dry_run` reports what would be learned
212+
without writing it.
213+
214+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
215+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
216+
217+
Args:
218+
graph_id (str):
219+
idempotency_key (None | str | Unset):
220+
body (LearnClassificationDefaultsRequest): Seed counterparty defaults from the bank lines
221+
already committed.
222+
223+
Raises:
224+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
225+
httpx.TimeoutException: If the request takes longer than Client.timeout.
226+
227+
Returns:
228+
Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]
229+
"""
230+
231+
kwargs = _get_kwargs(
232+
graph_id=graph_id,
233+
body=body,
234+
idempotency_key=idempotency_key,
235+
)
236+
237+
response = await client.get_async_httpx_client().request(**kwargs)
238+
239+
return _build_response(client=client, response=response)
240+
241+
242+
async def asyncio(
243+
graph_id: str,
244+
*,
245+
client: AuthenticatedClient,
246+
body: LearnClassificationDefaultsRequest,
247+
idempotency_key: None | str | Unset = UNSET,
248+
) -> ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse | None:
249+
"""Learn Classification Defaults
250+
251+
Seed each counterparty's default account from the bank lines already committed to the books: the
252+
account most of its lines went to becomes its default, with the lines that agreed counted as
253+
confirmations. A counterparty that already has a default keeps it. Its still-open lines are then
254+
suggested from the default. Run it once on books that were classified before defaults were learned;
255+
after that, every commit teaches the default by itself. `dry_run` reports what would be learned
256+
without writing it.
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 (LearnClassificationDefaultsRequest): Seed counterparty defaults from the bank lines
265+
already committed.
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 | OperationEnvelopeLearnClassificationDefaultsResponse
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

‎robosystems_client/api/robo_ledger_ledger_events/update_agent.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def sync_detailed(
115115
116116
Patch counterparty fields. Only supplied fields are updated. Set is_active=false to deactivate
117117
(agents are never deleted — they are reference data referenced by events and transactions).
118+
`classification_element_id` sets the account this counterparty's bank lines are suggested (an empty
119+
string clears it), and `classification_mode='always_ask'` stops suggesting one for a counterparty
120+
whose lines go to different accounts; its still-open lines are re-suggested at once. A default is
121+
also learned as lines are committed, so set one by hand only to correct it.
118122
119123
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
120124
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
@@ -158,6 +162,10 @@ def sync(
158162
159163
Patch counterparty fields. Only supplied fields are updated. Set is_active=false to deactivate
160164
(agents are never deleted — they are reference data referenced by events and transactions).
165+
`classification_element_id` sets the account this counterparty's bank lines are suggested (an empty
166+
string clears it), and `classification_mode='always_ask'` stops suggesting one for a counterparty
167+
whose lines go to different accounts; its still-open lines are re-suggested at once. A default is
168+
also learned as lines are committed, so set one by hand only to correct it.
161169
162170
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
163171
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
@@ -196,6 +204,10 @@ async def asyncio_detailed(
196204
197205
Patch counterparty fields. Only supplied fields are updated. Set is_active=false to deactivate
198206
(agents are never deleted — they are reference data referenced by events and transactions).
207+
`classification_element_id` sets the account this counterparty's bank lines are suggested (an empty
208+
string clears it), and `classification_mode='always_ask'` stops suggesting one for a counterparty
209+
whose lines go to different accounts; its still-open lines are re-suggested at once. A default is
210+
also learned as lines are committed, so set one by hand only to correct it.
199211
200212
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
201213
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
@@ -237,6 +249,10 @@ async def asyncio(
237249
238250
Patch counterparty fields. Only supplied fields are updated. Set is_active=false to deactivate
239251
(agents are never deleted — they are reference data referenced by events and transactions).
252+
`classification_element_id` sets the account this counterparty's bank lines are suggested (an empty
253+
string clears it), and `classification_mode='always_ask'` stops suggesting one for a counterparty
254+
whose lines go to different accounts; its still-open lines are re-suggested at once. A default is
255+
also learned as lines are committed, so set one by hand only to correct it.
240256
241257
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
242258
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.

‎robosystems_client/api/robo_ledger_ledger_events/update_event_block.py‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ def sync_detailed(
121121
captured metadata to produce the GL rows, unless it already wrote them when the event was created; a
122122
bank-feed line with no account chosen and no matching rule is refused. Errors from the handler
123123
(validation, element resolution, closed period, unbalanced lines) surface as 422 here so the inbox
124-
UI can display the failure reason without retry.
124+
UI can display the failure reason without retry. A bank line's flow is a second classification
125+
beside its account, overriding the account's default flow on the cash flow and equity statements:
126+
patch `classified_flow_qname` (or `flow_qname` on each `classified_allocations` part) with an rs-
127+
gaap flow concept such as `rs-gaap:ProceedsFromIssuanceOfLongTermDebt`. On a line that has already
128+
posted, this re-tags its lines in place, in a closed month too, since no balance moves; an empty
129+
string clears it.
125130
126131
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
127132
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
@@ -172,7 +177,12 @@ def sync(
172177
captured metadata to produce the GL rows, unless it already wrote them when the event was created; a
173178
bank-feed line with no account chosen and no matching rule is refused. Errors from the handler
174179
(validation, element resolution, closed period, unbalanced lines) surface as 422 here so the inbox
175-
UI can display the failure reason without retry.
180+
UI can display the failure reason without retry. A bank line's flow is a second classification
181+
beside its account, overriding the account's default flow on the cash flow and equity statements:
182+
patch `classified_flow_qname` (or `flow_qname` on each `classified_allocations` part) with an rs-
183+
gaap flow concept such as `rs-gaap:ProceedsFromIssuanceOfLongTermDebt`. On a line that has already
184+
posted, this re-tags its lines in place, in a closed month too, since no balance moves; an empty
185+
string clears it.
176186
177187
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
178188
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
@@ -218,7 +228,12 @@ async def asyncio_detailed(
218228
captured metadata to produce the GL rows, unless it already wrote them when the event was created; a
219229
bank-feed line with no account chosen and no matching rule is refused. Errors from the handler
220230
(validation, element resolution, closed period, unbalanced lines) surface as 422 here so the inbox
221-
UI can display the failure reason without retry.
231+
UI can display the failure reason without retry. A bank line's flow is a second classification
232+
beside its account, overriding the account's default flow on the cash flow and equity statements:
233+
patch `classified_flow_qname` (or `flow_qname` on each `classified_allocations` part) with an rs-
234+
gaap flow concept such as `rs-gaap:ProceedsFromIssuanceOfLongTermDebt`. On a line that has already
235+
posted, this re-tags its lines in place, in a closed month too, since no balance moves; an empty
236+
string clears it.
222237
223238
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
224239
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
@@ -267,7 +282,12 @@ async def asyncio(
267282
captured metadata to produce the GL rows, unless it already wrote them when the event was created; a
268283
bank-feed line with no account chosen and no matching rule is refused. Errors from the handler
269284
(validation, element resolution, closed period, unbalanced lines) surface as 422 here so the inbox
270-
UI can display the failure reason without retry.
285+
UI can display the failure reason without retry. A bank line's flow is a second classification
286+
beside its account, overriding the account's default flow on the cash flow and equity statements:
287+
patch `classified_flow_qname` (or `flow_qname` on each `classified_allocations` part) with an rs-
288+
gaap flow concept such as `rs-gaap:ProceedsFromIssuanceOfLongTermDebt`. On a line that has already
289+
posted, this re-tags its lines in place, in a closed month too, since no balance moves; an empty
290+
string clears it.
271291
272292
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
273293
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.

0 commit comments

Comments
 (0)