Skip to content

Commit 843f18f

Browse files
committed
Enhance LedgerClient with fiscal calendar functionalities
- Introduced new methods in the LedgerClient for managing fiscal periods, including `initialize_ledger`, `get_fiscal_calendar`, `set_close_target`, `close_period`, `reopen_period`, and `list_period_drafts`. - Added corresponding request and response models to support these operations, enhancing the client’s capabilities for fiscal management. - Updated imports to include new API endpoints related to fiscal calendar operations. These changes improve the LedgerClient's functionality for handling fiscal periods and streamline the workflow for closing and reopening periods.
1 parent f07eb6d commit 843f18f

31 files changed

Lines changed: 4125 additions & 39 deletions
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
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+
In a single transaction:
82+
1. Validates closeable gates
83+
2. Transitions all draft entries in the period to 'posted'
84+
3. Verifies BS equation balances
85+
4. Transitions the FiscalPeriod to 'closed'
86+
5. Advances closed_through; auto-advances close_target if reached
87+
88+
This is synchronous in v1. With QB writeback (future) it will become async.
89+
90+
Args:
91+
graph_id (str):
92+
period (str): Target period in YYYY-MM format
93+
body (ClosePeriodRequest | Unset):
94+
95+
Raises:
96+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
97+
httpx.TimeoutException: If the request takes longer than Client.timeout.
98+
99+
Returns:
100+
Response[ClosePeriodResponse | HTTPValidationError]
101+
"""
102+
103+
kwargs = _get_kwargs(
104+
graph_id=graph_id,
105+
period=period,
106+
body=body,
107+
)
108+
109+
response = client.get_httpx_client().request(
110+
**kwargs,
111+
)
112+
113+
return _build_response(client=client, response=response)
114+
115+
116+
def sync(
117+
graph_id: str,
118+
period: str,
119+
*,
120+
client: AuthenticatedClient,
121+
body: ClosePeriodRequest | Unset = UNSET,
122+
) -> ClosePeriodResponse | HTTPValidationError | None:
123+
"""Close Fiscal Period
124+
125+
Close a fiscal period — the final commit action.
126+
127+
In a single transaction:
128+
1. Validates closeable gates
129+
2. Transitions all draft entries in the period to 'posted'
130+
3. Verifies BS equation balances
131+
4. Transitions the FiscalPeriod to 'closed'
132+
5. Advances closed_through; auto-advances close_target if reached
133+
134+
This is synchronous in v1. With QB writeback (future) it will become async.
135+
136+
Args:
137+
graph_id (str):
138+
period (str): Target period in YYYY-MM format
139+
body (ClosePeriodRequest | Unset):
140+
141+
Raises:
142+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
143+
httpx.TimeoutException: If the request takes longer than Client.timeout.
144+
145+
Returns:
146+
ClosePeriodResponse | HTTPValidationError
147+
"""
148+
149+
return sync_detailed(
150+
graph_id=graph_id,
151+
period=period,
152+
client=client,
153+
body=body,
154+
).parsed
155+
156+
157+
async def asyncio_detailed(
158+
graph_id: str,
159+
period: str,
160+
*,
161+
client: AuthenticatedClient,
162+
body: ClosePeriodRequest | Unset = UNSET,
163+
) -> Response[ClosePeriodResponse | HTTPValidationError]:
164+
"""Close Fiscal Period
165+
166+
Close a fiscal period — the final commit action.
167+
168+
In a single transaction:
169+
1. Validates closeable gates
170+
2. Transitions all draft entries in the period to 'posted'
171+
3. Verifies BS equation balances
172+
4. Transitions the FiscalPeriod to 'closed'
173+
5. Advances closed_through; auto-advances close_target if reached
174+
175+
This is synchronous in v1. With QB writeback (future) it will become async.
176+
177+
Args:
178+
graph_id (str):
179+
period (str): Target period in YYYY-MM format
180+
body (ClosePeriodRequest | Unset):
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+
Response[ClosePeriodResponse | HTTPValidationError]
188+
"""
189+
190+
kwargs = _get_kwargs(
191+
graph_id=graph_id,
192+
period=period,
193+
body=body,
194+
)
195+
196+
response = await client.get_async_httpx_client().request(**kwargs)
197+
198+
return _build_response(client=client, response=response)
199+
200+
201+
async def asyncio(
202+
graph_id: str,
203+
period: str,
204+
*,
205+
client: AuthenticatedClient,
206+
body: ClosePeriodRequest | Unset = UNSET,
207+
) -> ClosePeriodResponse | HTTPValidationError | None:
208+
"""Close Fiscal Period
209+
210+
Close a fiscal period — the final commit action.
211+
212+
In a single transaction:
213+
1. Validates closeable gates
214+
2. Transitions all draft entries in the period to 'posted'
215+
3. Verifies BS equation balances
216+
4. Transitions the FiscalPeriod to 'closed'
217+
5. Advances closed_through; auto-advances close_target if reached
218+
219+
This is synchronous in v1. With QB writeback (future) it will become async.
220+
221+
Args:
222+
graph_id (str):
223+
period (str): Target period in YYYY-MM format
224+
body (ClosePeriodRequest | Unset):
225+
226+
Raises:
227+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
228+
httpx.TimeoutException: If the request takes longer than Client.timeout.
229+
230+
Returns:
231+
ClosePeriodResponse | HTTPValidationError
232+
"""
233+
234+
return (
235+
await asyncio_detailed(
236+
graph_id=graph_id,
237+
period=period,
238+
client=client,
239+
body=body,
240+
)
241+
).parsed

0 commit comments

Comments
 (0)