Skip to content

Commit dde34e0

Browse files
jfrench9claude
andauthored
Add fiscal calendar management and period closing operations (#85)
## Summary Enhances the `LedgerClient` with comprehensive fiscal calendar and period closing functionalities. This feature introduces new API endpoints, request/response models, and high-level client methods to manage the full lifecycle of fiscal periods — from ledger initialization and schedule management through period closing, reopening, and manual closing entry creation. ## Key Accomplishments ### New API Endpoints (8 added) - **`initialize_ledger`** — Bootstrap a ledger with initial entity data and fiscal calendar configuration - **`get_fiscal_calendar`** — Retrieve the full fiscal calendar with period summaries - **`close_fiscal_period`** — Close a specific fiscal period, finalizing its entries - **`reopen_fiscal_period`** — Reopen a previously closed fiscal period for corrections - **`set_close_target`** — Set the target period for the next closing cycle - **`list_period_drafts`** — List draft entries pending within a fiscal period - **`create_manual_closing_entry`** — Create manual closing/adjusting journal entries - **`truncate_schedule`** — Truncate the fiscal schedule at a given point ### New Models (18 added) - Request models: `ClosePeriodRequest`, `ReopenPeriodRequest`, `SetCloseTargetRequest`, `InitializeLedgerRequest`, `CreateManualClosingEntryRequest`, `TruncateScheduleRequest`, `ManualLineItemRequest` - Response models: `ClosePeriodResponse`, `FiscalCalendarResponse`, `FiscalPeriodSummary`, `InitializeLedgerResponse`, `DraftEntryResponse`, `DraftLineItem`, `PeriodDraftsResponse`, `TruncateScheduleResponse` - Enums: `CreateManualClosingEntryRequestEntryType`, `EntryTemplateRequestEntryType` ### Modified Models & Endpoints - **`ClosingEntryResponse`** — Expanded with additional fields to support richer closing entry data - **`EntryTemplateRequest`** — Added entry type support - **`CreateScheduleRequest`** / **`InitialEntityData`** — Extended with new optional fields - **`get_statement`** — Minor update (removed cash flow statement reference from structure type) - **`CreateStructureRequestStructureType`** — Removed deprecated cash flow statement variant ### Client Extension - `LedgerClient` extended with convenient high-level methods wrapping all new endpoints, providing a clean interface for fiscal calendar operations ## Breaking Changes - **`CreateStructureRequestStructureType`**: The cash flow statement enum variant has been removed. Any consumers referencing this value will need to be updated. - **`ClosingEntryResponse`** model has been significantly refactored with new/changed fields — consumers deserializing this model should verify compatibility. ## Testing - Added comprehensive unit tests in `tests/test_ledger_client.py` (446 lines) covering all new `LedgerClient` fiscal calendar operations including initialization, calendar retrieval, period close/reopen, draft listing, manual entry creation, close target setting, and schedule truncation. - All tests use mocked HTTP responses to validate request construction and response parsing. ## Infrastructure Considerations - No new external dependencies introduced; all new functionality builds on the existing client/model framework. - The 18 new model files and 8 new API endpoint modules increase the package surface area — documentation generation and SDK packaging pipelines should be verified to pick up the new modules. - Model registry (`models/__init__.py`) has been updated to export all new types. --- 🤖 Generated with [Claude Code](https://claude.ai/code) **Branch Info:** - Source: `feature/improved-fiscal-close` - Target: `main` - Type: feature Co-Authored-By: Claude <noreply@anthropic.com>
2 parents f07eb6d + f03c945 commit dde34e0

34 files changed

Lines changed: 4555 additions & 44 deletions
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
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.close_period_request import ClosePeriodRequest
10+
from ...models.close_period_response import ClosePeriodResponse
11+
from ...models.http_validation_error import HTTPValidationError
12+
from ...types import UNSET, Response, Unset
13+
14+
15+
def _get_kwargs(
16+
graph_id: str,
17+
period: str,
18+
*,
19+
body: ClosePeriodRequest | Unset = UNSET,
20+
) -> dict[str, Any]:
21+
headers: dict[str, Any] = {}
22+
23+
_kwargs: dict[str, Any] = {
24+
"method": "post",
25+
"url": "/v1/ledger/{graph_id}/periods/{period}/close".format(
26+
graph_id=quote(str(graph_id), safe=""),
27+
period=quote(str(period), safe=""),
28+
),
29+
}
30+
31+
if not isinstance(body, Unset):
32+
_kwargs["json"] = body.to_dict()
33+
34+
headers["Content-Type"] = "application/json"
35+
36+
_kwargs["headers"] = headers
37+
return _kwargs
38+
39+
40+
def _parse_response(
41+
*, client: AuthenticatedClient | Client, response: httpx.Response
42+
) -> ClosePeriodResponse | HTTPValidationError | None:
43+
if response.status_code == 200:
44+
response_200 = ClosePeriodResponse.from_dict(response.json())
45+
46+
return response_200
47+
48+
if response.status_code == 422:
49+
response_422 = HTTPValidationError.from_dict(response.json())
50+
51+
return response_422
52+
53+
if client.raise_on_unexpected_status:
54+
raise errors.UnexpectedStatus(response.status_code, response.content)
55+
else:
56+
return None
57+
58+
59+
def _build_response(
60+
*, client: AuthenticatedClient | Client, response: httpx.Response
61+
) -> Response[ClosePeriodResponse | HTTPValidationError]:
62+
return Response(
63+
status_code=HTTPStatus(response.status_code),
64+
content=response.content,
65+
headers=response.headers,
66+
parsed=_parse_response(client=client, response=response),
67+
)
68+
69+
70+
def sync_detailed(
71+
graph_id: str,
72+
period: str,
73+
*,
74+
client: AuthenticatedClient,
75+
body: ClosePeriodRequest | Unset = UNSET,
76+
) -> Response[ClosePeriodResponse | HTTPValidationError]:
77+
"""Close Fiscal Period
78+
79+
Close a fiscal period — the final commit action.
80+
81+
All mechanics live in `PeriodCloseService.close()`. This endpoint just
82+
resolves auth + QB sync state, invokes the service, and translates
83+
domain exceptions into HTTP responses.
84+
85+
Args:
86+
graph_id (str):
87+
period (str): Target period in YYYY-MM format
88+
body (ClosePeriodRequest | Unset):
89+
90+
Raises:
91+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
92+
httpx.TimeoutException: If the request takes longer than Client.timeout.
93+
94+
Returns:
95+
Response[ClosePeriodResponse | HTTPValidationError]
96+
"""
97+
98+
kwargs = _get_kwargs(
99+
graph_id=graph_id,
100+
period=period,
101+
body=body,
102+
)
103+
104+
response = client.get_httpx_client().request(
105+
**kwargs,
106+
)
107+
108+
return _build_response(client=client, response=response)
109+
110+
111+
def sync(
112+
graph_id: str,
113+
period: str,
114+
*,
115+
client: AuthenticatedClient,
116+
body: ClosePeriodRequest | Unset = UNSET,
117+
) -> ClosePeriodResponse | HTTPValidationError | None:
118+
"""Close Fiscal Period
119+
120+
Close a fiscal period — the final commit action.
121+
122+
All mechanics live in `PeriodCloseService.close()`. This endpoint just
123+
resolves auth + QB sync state, invokes the service, and translates
124+
domain exceptions into HTTP responses.
125+
126+
Args:
127+
graph_id (str):
128+
period (str): Target period in YYYY-MM format
129+
body (ClosePeriodRequest | Unset):
130+
131+
Raises:
132+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
133+
httpx.TimeoutException: If the request takes longer than Client.timeout.
134+
135+
Returns:
136+
ClosePeriodResponse | HTTPValidationError
137+
"""
138+
139+
return sync_detailed(
140+
graph_id=graph_id,
141+
period=period,
142+
client=client,
143+
body=body,
144+
).parsed
145+
146+
147+
async def asyncio_detailed(
148+
graph_id: str,
149+
period: str,
150+
*,
151+
client: AuthenticatedClient,
152+
body: ClosePeriodRequest | Unset = UNSET,
153+
) -> Response[ClosePeriodResponse | HTTPValidationError]:
154+
"""Close Fiscal Period
155+
156+
Close a fiscal period — the final commit action.
157+
158+
All mechanics live in `PeriodCloseService.close()`. This endpoint just
159+
resolves auth + QB sync state, invokes the service, and translates
160+
domain exceptions into HTTP responses.
161+
162+
Args:
163+
graph_id (str):
164+
period (str): Target period in YYYY-MM format
165+
body (ClosePeriodRequest | Unset):
166+
167+
Raises:
168+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
169+
httpx.TimeoutException: If the request takes longer than Client.timeout.
170+
171+
Returns:
172+
Response[ClosePeriodResponse | HTTPValidationError]
173+
"""
174+
175+
kwargs = _get_kwargs(
176+
graph_id=graph_id,
177+
period=period,
178+
body=body,
179+
)
180+
181+
response = await client.get_async_httpx_client().request(**kwargs)
182+
183+
return _build_response(client=client, response=response)
184+
185+
186+
async def asyncio(
187+
graph_id: str,
188+
period: str,
189+
*,
190+
client: AuthenticatedClient,
191+
body: ClosePeriodRequest | Unset = UNSET,
192+
) -> ClosePeriodResponse | HTTPValidationError | None:
193+
"""Close Fiscal Period
194+
195+
Close a fiscal period — the final commit action.
196+
197+
All mechanics live in `PeriodCloseService.close()`. This endpoint just
198+
resolves auth + QB sync state, invokes the service, and translates
199+
domain exceptions into HTTP responses.
200+
201+
Args:
202+
graph_id (str):
203+
period (str): Target period in YYYY-MM format
204+
body (ClosePeriodRequest | Unset):
205+
206+
Raises:
207+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
208+
httpx.TimeoutException: If the request takes longer than Client.timeout.
209+
210+
Returns:
211+
ClosePeriodResponse | HTTPValidationError
212+
"""
213+
214+
return (
215+
await asyncio_detailed(
216+
graph_id=graph_id,
217+
period=period,
218+
client=client,
219+
body=body,
220+
)
221+
).parsed

0 commit comments

Comments
 (0)