Skip to content

Commit a7e9313

Browse files
authored
feat(ledger): list_elements include_inactive, and the schedule surface from #1922 (#278)
## Summary `list_elements(graph_id, include_inactive=True)` returns retired accounts beside the active ones, each with `isActive`, so roboledger-app's chart editor can list and reactivate them. Backend: robosystems [#1923](RoboFinSystems/robosystems#1923). ## Changes **From robosystems [#1923](RoboFinSystems/robosystems#1923) (GraphQL):** - `ListLedgerElements.graphql` takes `$includeInactive: Boolean! = false`; `list_elements` gains `include_inactive`. Default unchanged. Schema snapshot and codegen regenerated. **From robosystems [#1922](RoboFinSystems/robosystems#1922) (OpenAPI, generated tier only):** the `preview_schedule` operation and its models: `LoanTermsRequest`, `ScheduleLegRequest`, `PreviewScheduleRequest`/`Response`, `ScheduleRollForwardRow`, `ScheduleReplacementSummary`; optional legs on the entry template, `loan_terms` on the schedule metadata, rebuild-schedule's editable fields, warnings on the created response, the definition on `ScheduleMechanics`; `monthly_amount` becomes optional on create. Regenerated with OpenAPI from #1922's branch (with main merged in) and GraphQL from #1923's; the base URL is the usual `http://localhost:8000`. ## Release Additive: a client **minor**. It waits on the robosystems release that carries both #1922 and #1923; before it, the server rejects the new argument and has no `preview-schedule`. roboledger-app passes it on the chart page after the bump. The twin of [typescript-client #294](RoboFinSystems/robosystems-typescript-client#294). ## Testing `tests/test_ledger_client.py`: `list_elements` sends `includeInactive` false by default. Ruff, basedpyright and the suite (726) pass; regenerated against the local API on #1923's branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VPxBBHkqhwkZ6Eq8EXSBR6
2 parents 22b5cac + d37987e commit a7e9313

29 files changed

Lines changed: 2087 additions & 20 deletions
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
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.operation_envelope_preview_schedule_response import (
11+
OperationEnvelopePreviewScheduleResponse,
12+
)
13+
from ...models.preview_schedule_request import PreviewScheduleRequest
14+
from ...types import UNSET, Response, Unset
15+
16+
17+
def _get_kwargs(
18+
graph_id: str,
19+
*,
20+
body: PreviewScheduleRequest,
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/preview-schedule".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 | OperationEnvelopePreviewScheduleResponse | None:
45+
if response.status_code == 200:
46+
response_200 = OperationEnvelopePreviewScheduleResponse.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 | OperationEnvelopePreviewScheduleResponse]:
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: PreviewScheduleRequest,
112+
idempotency_key: None | str | Unset = UNSET,
113+
) -> Response[ErrorResponse | OperationEnvelopePreviewScheduleResponse]:
114+
"""Preview Schedule
115+
116+
Generate a schedule from a definition without keeping it: the same generator and guards as creating
117+
one (block_type='schedule' on create-information-block), run and rolled back. Returns the envelope
118+
create would leave (its ids provisional) and the period-by-period roll-forward: the balance the
119+
schedule carries on the account it credits (a loan's: the note), opening, the period's amount,
120+
closing, and for a loan the interest, payment, principal and current portion. Show it to the person
121+
before asking to create. A definition create would refuse (a roll-forward that climbs where it
122+
should fall, legs that do not balance) is refused here with the period that breaks. `warnings` names
123+
any active schedule already posting the same accounts in the same months. With
124+
`replaces_structure_id`, `replaces` says what the schedule being edited or recreated has posted, by
125+
month, and the path the change takes: `rebuild` (rebuild-schedule with the new definition) while
126+
nothing has posted, `terminate_and_succeed` after.
127+
128+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
129+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
130+
131+
Args:
132+
graph_id (str):
133+
idempotency_key (None | str | Unset):
134+
body (PreviewScheduleRequest): A schedule's definition, generated without being kept.
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 | OperationEnvelopePreviewScheduleResponse]
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: PreviewScheduleRequest,
162+
idempotency_key: None | str | Unset = UNSET,
163+
) -> ErrorResponse | OperationEnvelopePreviewScheduleResponse | None:
164+
"""Preview Schedule
165+
166+
Generate a schedule from a definition without keeping it: the same generator and guards as creating
167+
one (block_type='schedule' on create-information-block), run and rolled back. Returns the envelope
168+
create would leave (its ids provisional) and the period-by-period roll-forward: the balance the
169+
schedule carries on the account it credits (a loan's: the note), opening, the period's amount,
170+
closing, and for a loan the interest, payment, principal and current portion. Show it to the person
171+
before asking to create. A definition create would refuse (a roll-forward that climbs where it
172+
should fall, legs that do not balance) is refused here with the period that breaks. `warnings` names
173+
any active schedule already posting the same accounts in the same months. With
174+
`replaces_structure_id`, `replaces` says what the schedule being edited or recreated has posted, by
175+
month, and the path the change takes: `rebuild` (rebuild-schedule with the new definition) while
176+
nothing has posted, `terminate_and_succeed` after.
177+
178+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
179+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
180+
181+
Args:
182+
graph_id (str):
183+
idempotency_key (None | str | Unset):
184+
body (PreviewScheduleRequest): A schedule's definition, generated without being kept.
185+
186+
Raises:
187+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
188+
httpx.TimeoutException: If the request takes longer than Client.timeout.
189+
190+
Returns:
191+
ErrorResponse | OperationEnvelopePreviewScheduleResponse
192+
"""
193+
194+
return sync_detailed(
195+
graph_id=graph_id,
196+
client=client,
197+
body=body,
198+
idempotency_key=idempotency_key,
199+
).parsed
200+
201+
202+
async def asyncio_detailed(
203+
graph_id: str,
204+
*,
205+
client: AuthenticatedClient,
206+
body: PreviewScheduleRequest,
207+
idempotency_key: None | str | Unset = UNSET,
208+
) -> Response[ErrorResponse | OperationEnvelopePreviewScheduleResponse]:
209+
"""Preview Schedule
210+
211+
Generate a schedule from a definition without keeping it: the same generator and guards as creating
212+
one (block_type='schedule' on create-information-block), run and rolled back. Returns the envelope
213+
create would leave (its ids provisional) and the period-by-period roll-forward: the balance the
214+
schedule carries on the account it credits (a loan's: the note), opening, the period's amount,
215+
closing, and for a loan the interest, payment, principal and current portion. Show it to the person
216+
before asking to create. A definition create would refuse (a roll-forward that climbs where it
217+
should fall, legs that do not balance) is refused here with the period that breaks. `warnings` names
218+
any active schedule already posting the same accounts in the same months. With
219+
`replaces_structure_id`, `replaces` says what the schedule being edited or recreated has posted, by
220+
month, and the path the change takes: `rebuild` (rebuild-schedule with the new definition) while
221+
nothing has posted, `terminate_and_succeed` after.
222+
223+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
224+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
225+
226+
Args:
227+
graph_id (str):
228+
idempotency_key (None | str | Unset):
229+
body (PreviewScheduleRequest): A schedule's definition, generated without being kept.
230+
231+
Raises:
232+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
233+
httpx.TimeoutException: If the request takes longer than Client.timeout.
234+
235+
Returns:
236+
Response[ErrorResponse | OperationEnvelopePreviewScheduleResponse]
237+
"""
238+
239+
kwargs = _get_kwargs(
240+
graph_id=graph_id,
241+
body=body,
242+
idempotency_key=idempotency_key,
243+
)
244+
245+
response = await client.get_async_httpx_client().request(**kwargs)
246+
247+
return _build_response(client=client, response=response)
248+
249+
250+
async def asyncio(
251+
graph_id: str,
252+
*,
253+
client: AuthenticatedClient,
254+
body: PreviewScheduleRequest,
255+
idempotency_key: None | str | Unset = UNSET,
256+
) -> ErrorResponse | OperationEnvelopePreviewScheduleResponse | None:
257+
"""Preview Schedule
258+
259+
Generate a schedule from a definition without keeping it: the same generator and guards as creating
260+
one (block_type='schedule' on create-information-block), run and rolled back. Returns the envelope
261+
create would leave (its ids provisional) and the period-by-period roll-forward: the balance the
262+
schedule carries on the account it credits (a loan's: the note), opening, the period's amount,
263+
closing, and for a loan the interest, payment, principal and current portion. Show it to the person
264+
before asking to create. A definition create would refuse (a roll-forward that climbs where it
265+
should fall, legs that do not balance) is refused here with the period that breaks. `warnings` names
266+
any active schedule already posting the same accounts in the same months. With
267+
`replaces_structure_id`, `replaces` says what the schedule being edited or recreated has posted, by
268+
month, and the path the change takes: `rebuild` (rebuild-schedule with the new definition) while
269+
nothing has posted, `terminate_and_succeed` after.
270+
271+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
272+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
273+
274+
Args:
275+
graph_id (str):
276+
idempotency_key (None | str | Unset):
277+
body (PreviewScheduleRequest): A schedule's definition, generated without being kept.
278+
279+
Raises:
280+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
281+
httpx.TimeoutException: If the request takes longer than Client.timeout.
282+
283+
Returns:
284+
ErrorResponse | OperationEnvelopePreviewScheduleResponse
285+
"""
286+
287+
return (
288+
await asyncio_detailed(
289+
graph_id=graph_id,
290+
client=client,
291+
body=body,
292+
idempotency_key=idempotency_key,
293+
)
294+
).parsed

0 commit comments

Comments
 (0)