Skip to content

Commit 1100376

Browse files
authored
feat: add reconciliations to the ledger facade (#228)
## Summary Adds reconciliations to the ledger facade, so a script or an agent can list them, run them, record a statement balance, change a block's policy and sign a period off. Regenerated against robosystems `main` (ed9f4cf2), which carries the reconciliation surface from robosystems #1646, #1649, #1652, #1653 and `booked_on` from #1655. The TypeScript twin is robosystems-typescript-client #243. **Release order: cut the client release only after the robosystems release that contains #1652 and #1653 is deployed.** `list_reconciliations` selects GraphQL fields that only exist from that release (`ledgerBalance`, `independentBalance`, `balanceAsOf`, `components`, `notes`), so the query fails validation against an older server. Merging is safe at any time, and no existing method is affected: the two fields added to the fiscal calendar query are already served. ## Changes **Facade (`clients/ledger_client.py`), stable tier, additive** - `list_reconciliations(graph_id, period)`: every reconciliation block's standing for a period. - `preview_reconciliations(graph_id, period, *, method, include_tied)`: one comparison, nothing recorded. - `refresh_reconciliations(graph_id, period)`: run every check that applies and record the results. `notes` names a check that could not run. - `record_statement_balance(graph_id, *, element_id, as_of, balance, document_id, note)`. - `set_reconciliation_policy(graph_id, structure_id, *, required_for_close, materiality, review_required, separate_reviewer)`: an omitted field keeps its value. - `sign_off_reconciliation(graph_id, structure_id, period, note)`. - `close_period` takes `allow_unreconciled_accounts`; `create_schedule` takes `booked_on`. - `get_fiscal_calendar` carries `unreconciled_account_count` and `unreconciled_account_sample`. - `download_report_bundle` now defaults to the holon (`format="holon-jsonld"`), which carries the whole report. Pass `format="tavi"` for the compiled model. **GraphQL** - `operations/ledger/ListLedgerReconciliations.graphql` (new); `GetLedgerFiscalCalendar.graphql` selects the two unreconciled-account fields. `schema.graphql` refreshed and `generated/` regenerated from it. **Generated tier (`api/`, `models/`)** - Five new operations: `preview_reconciliations`, `refresh_reconciliations`, `record_statement_balance`, `set_reconciliation_policy`, `sign_off_reconciliation`, with their request and response models. - `allow_unreconciled_accounts` on the close and backfill requests; `reconciliation` as a block type; `ReconciliationMechanics`; `booked_on` on the schedule metadata request. - The sync path is what the facade uses; the generated async functions come with the regeneration and were not exercised. ## Compatibility ADDITIVE, plus one facade default that moved: `download_report_bundle` returns the holon unless a format is named. A caller that relied on the default now gets a different file and passes `format="tavi"` to keep the old one. That rides this minor and belongs in the release notes. Otherwise: new facade methods, two new optional keyword arguments, and new generated operations and models. I compared the emitted models: no file was deleted, and no field was removed or became required. The only removed lines are docstrings. A minor. ## Testing - `just test-all`: 609 passed, 17 skipped; format, lint and typecheck clean. - Twelve new facade tests: the read and its variables, a graph with no ledger, the request body of each write (including that unset options are left off), an unknown check being refused, a refusal carrying the server's response, and the two new options on `close_period` and `create_schedule`. - Regenerated against a local stack serving robosystems `main`; `booked_on` and the reconciliation operations were confirmed present in its `/openapi.json` first. An earlier regeneration in this checkout had run against a stale stack and lacked `booked_on`; it was redone. - Not run against a deployed server. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01N4VGnvrpE2cwbBZykz4yGd
2 parents bab204c + 1311e7b commit 1100376

52 files changed

Lines changed: 5386 additions & 42 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
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_reconciliation_preview_response import (
11+
OperationEnvelopeReconciliationPreviewResponse,
12+
)
13+
from ...models.preview_reconciliations_request import PreviewReconciliationsRequest
14+
from ...types import UNSET, Response, Unset
15+
16+
17+
def _get_kwargs(
18+
graph_id: str,
19+
*,
20+
body: PreviewReconciliationsRequest,
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-reconciliations".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 | OperationEnvelopeReconciliationPreviewResponse | None:
45+
if response.status_code == 200:
46+
response_200 = OperationEnvelopeReconciliationPreviewResponse.from_dict(
47+
response.json()
48+
)
49+
50+
return response_200
51+
52+
if response.status_code == 400:
53+
response_400 = ErrorResponse.from_dict(response.json())
54+
55+
return response_400
56+
57+
if response.status_code == 401:
58+
response_401 = ErrorResponse.from_dict(response.json())
59+
60+
return response_401
61+
62+
if response.status_code == 403:
63+
response_403 = ErrorResponse.from_dict(response.json())
64+
65+
return response_403
66+
67+
if response.status_code == 404:
68+
response_404 = ErrorResponse.from_dict(response.json())
69+
70+
return response_404
71+
72+
if response.status_code == 409:
73+
response_409 = ErrorResponse.from_dict(response.json())
74+
75+
return response_409
76+
77+
if response.status_code == 422:
78+
response_422 = ErrorResponse.from_dict(response.json())
79+
80+
return response_422
81+
82+
if response.status_code == 429:
83+
response_429 = ErrorResponse.from_dict(response.json())
84+
85+
return response_429
86+
87+
if response.status_code == 500:
88+
response_500 = ErrorResponse.from_dict(response.json())
89+
90+
return response_500
91+
92+
if client.raise_on_unexpected_status:
93+
raise errors.UnexpectedStatus(response.status_code, response.content)
94+
else:
95+
return None
96+
97+
98+
def _build_response(
99+
*, client: AuthenticatedClient | Client, response: httpx.Response
100+
) -> Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse]:
101+
return Response(
102+
status_code=HTTPStatus(response.status_code),
103+
content=response.content,
104+
headers=response.headers,
105+
parsed=_parse_response(client=client, response=response),
106+
)
107+
108+
109+
def sync_detailed(
110+
graph_id: str,
111+
*,
112+
client: AuthenticatedClient,
113+
body: PreviewReconciliationsRequest,
114+
idempotency_key: None | str | Unset = UNSET,
115+
) -> Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse]:
116+
"""Preview Reconciliations
117+
118+
Compare the ledger at a period end with something outside it, without recording anything. `method`
119+
picks the check. `source_ledger` (the default) reads QuickBooks' own trial balance for the period
120+
end and sets it beside the ledger's, account by account: balance-sheet accounts cumulatively, income
121+
and expense accounts from the start of the fiscal year. A difference there means the ledger's copy
122+
of the books has drifted from the source (a transaction deleted or back-dated there after it was
123+
synced, or activity not yet synced), so run it before trusting any other figure on a synced ledger;
124+
it needs a connected QuickBooks ledger. `schedule_register` compares each asset account a schedule
125+
carries a balance on (a prepaid, accumulated depreciation, a fixed-asset cost account) with what its
126+
schedules say it holds, and lists the schedules behind each figure. A difference there is a balance
127+
with no schedule behind it, or a scheduled amount the ledger does not hold. Each row carries both
128+
balances, the difference, and whether the account ties.
129+
130+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
131+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
132+
133+
Args:
134+
graph_id (str):
135+
idempotency_key (None | str | Unset):
136+
body (PreviewReconciliationsRequest): Compare the ledger's balances at a period end with
137+
an independent source.
138+
139+
Raises:
140+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
141+
httpx.TimeoutException: If the request takes longer than Client.timeout.
142+
143+
Returns:
144+
Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse]
145+
"""
146+
147+
kwargs = _get_kwargs(
148+
graph_id=graph_id,
149+
body=body,
150+
idempotency_key=idempotency_key,
151+
)
152+
153+
response = client.get_httpx_client().request(
154+
**kwargs,
155+
)
156+
157+
return _build_response(client=client, response=response)
158+
159+
160+
def sync(
161+
graph_id: str,
162+
*,
163+
client: AuthenticatedClient,
164+
body: PreviewReconciliationsRequest,
165+
idempotency_key: None | str | Unset = UNSET,
166+
) -> ErrorResponse | OperationEnvelopeReconciliationPreviewResponse | None:
167+
"""Preview Reconciliations
168+
169+
Compare the ledger at a period end with something outside it, without recording anything. `method`
170+
picks the check. `source_ledger` (the default) reads QuickBooks' own trial balance for the period
171+
end and sets it beside the ledger's, account by account: balance-sheet accounts cumulatively, income
172+
and expense accounts from the start of the fiscal year. A difference there means the ledger's copy
173+
of the books has drifted from the source (a transaction deleted or back-dated there after it was
174+
synced, or activity not yet synced), so run it before trusting any other figure on a synced ledger;
175+
it needs a connected QuickBooks ledger. `schedule_register` compares each asset account a schedule
176+
carries a balance on (a prepaid, accumulated depreciation, a fixed-asset cost account) with what its
177+
schedules say it holds, and lists the schedules behind each figure. A difference there is a balance
178+
with no schedule behind it, or a scheduled amount the ledger does not hold. Each row carries both
179+
balances, the difference, and whether the account ties.
180+
181+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
182+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
183+
184+
Args:
185+
graph_id (str):
186+
idempotency_key (None | str | Unset):
187+
body (PreviewReconciliationsRequest): Compare the ledger's balances at a period end with
188+
an independent source.
189+
190+
Raises:
191+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
192+
httpx.TimeoutException: If the request takes longer than Client.timeout.
193+
194+
Returns:
195+
ErrorResponse | OperationEnvelopeReconciliationPreviewResponse
196+
"""
197+
198+
return sync_detailed(
199+
graph_id=graph_id,
200+
client=client,
201+
body=body,
202+
idempotency_key=idempotency_key,
203+
).parsed
204+
205+
206+
async def asyncio_detailed(
207+
graph_id: str,
208+
*,
209+
client: AuthenticatedClient,
210+
body: PreviewReconciliationsRequest,
211+
idempotency_key: None | str | Unset = UNSET,
212+
) -> Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse]:
213+
"""Preview Reconciliations
214+
215+
Compare the ledger at a period end with something outside it, without recording anything. `method`
216+
picks the check. `source_ledger` (the default) reads QuickBooks' own trial balance for the period
217+
end and sets it beside the ledger's, account by account: balance-sheet accounts cumulatively, income
218+
and expense accounts from the start of the fiscal year. A difference there means the ledger's copy
219+
of the books has drifted from the source (a transaction deleted or back-dated there after it was
220+
synced, or activity not yet synced), so run it before trusting any other figure on a synced ledger;
221+
it needs a connected QuickBooks ledger. `schedule_register` compares each asset account a schedule
222+
carries a balance on (a prepaid, accumulated depreciation, a fixed-asset cost account) with what its
223+
schedules say it holds, and lists the schedules behind each figure. A difference there is a balance
224+
with no schedule behind it, or a scheduled amount the ledger does not hold. Each row carries both
225+
balances, the difference, and whether the account ties.
226+
227+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
228+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
229+
230+
Args:
231+
graph_id (str):
232+
idempotency_key (None | str | Unset):
233+
body (PreviewReconciliationsRequest): Compare the ledger's balances at a period end with
234+
an independent source.
235+
236+
Raises:
237+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
238+
httpx.TimeoutException: If the request takes longer than Client.timeout.
239+
240+
Returns:
241+
Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse]
242+
"""
243+
244+
kwargs = _get_kwargs(
245+
graph_id=graph_id,
246+
body=body,
247+
idempotency_key=idempotency_key,
248+
)
249+
250+
response = await client.get_async_httpx_client().request(**kwargs)
251+
252+
return _build_response(client=client, response=response)
253+
254+
255+
async def asyncio(
256+
graph_id: str,
257+
*,
258+
client: AuthenticatedClient,
259+
body: PreviewReconciliationsRequest,
260+
idempotency_key: None | str | Unset = UNSET,
261+
) -> ErrorResponse | OperationEnvelopeReconciliationPreviewResponse | None:
262+
"""Preview Reconciliations
263+
264+
Compare the ledger at a period end with something outside it, without recording anything. `method`
265+
picks the check. `source_ledger` (the default) reads QuickBooks' own trial balance for the period
266+
end and sets it beside the ledger's, account by account: balance-sheet accounts cumulatively, income
267+
and expense accounts from the start of the fiscal year. A difference there means the ledger's copy
268+
of the books has drifted from the source (a transaction deleted or back-dated there after it was
269+
synced, or activity not yet synced), so run it before trusting any other figure on a synced ledger;
270+
it needs a connected QuickBooks ledger. `schedule_register` compares each asset account a schedule
271+
carries a balance on (a prepaid, accumulated depreciation, a fixed-asset cost account) with what its
272+
schedules say it holds, and lists the schedules behind each figure. A difference there is a balance
273+
with no schedule behind it, or a scheduled amount the ledger does not hold. Each row carries both
274+
balances, the difference, and whether the account ties.
275+
276+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
277+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
278+
279+
Args:
280+
graph_id (str):
281+
idempotency_key (None | str | Unset):
282+
body (PreviewReconciliationsRequest): Compare the ledger's balances at a period end with
283+
an independent source.
284+
285+
Raises:
286+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
287+
httpx.TimeoutException: If the request takes longer than Client.timeout.
288+
289+
Returns:
290+
ErrorResponse | OperationEnvelopeReconciliationPreviewResponse
291+
"""
292+
293+
return (
294+
await asyncio_detailed(
295+
graph_id=graph_id,
296+
client=client,
297+
body=body,
298+
idempotency_key=idempotency_key,
299+
)
300+
).parsed

0 commit comments

Comments
 (0)