Skip to content

Commit 3330c69

Browse files
committed
Update journal entry request handling and introduce status management
- Modified the `CreateJournalEntryRequest` to default to `status='draft'` for ongoing entries, with an option to set `status='posted'` for historical data imports. - Enhanced documentation to clarify the workflow for creating journal entries and the implications of different statuses. - Added `CreateJournalEntryRequestStatus` model to manage entry statuses, improving code organization and clarity. - Updated imports in `__init__.py` to include the new status model. These changes improve the flexibility and clarity of journal entry creation in the API.
1 parent 0bf171d commit 3330c69

8 files changed

Lines changed: 481 additions & 37 deletions

‎robosystems_client/api/extensions_robo_ledger/op_create_journal_entry.py‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ def sync_detailed(
120120
idempotency_key (None | str | Unset):
121121
body (CreateJournalEntryRequest): Create a new journal entry with balanced line items.
122122
123-
The entry is always created as `status='draft'`. Posting a draft
124-
happens via `close-period` (for batch month-end posting) or — in
125-
the future — an individual `post-journal-entry` op. This matches
126-
the existing `create-manual-closing-entry` behavior.
123+
Defaults to `status='draft'` for ongoing native writes (the normal
124+
workflow: draft → review → post via close-period). Pass
125+
`status='posted'` for historical data import where entries represent
126+
already-happened business events that don't need review.
127127
128128
Total debit amount must equal total credit amount or the request
129129
is rejected with 422. `line_items` must contain at least two rows
@@ -171,10 +171,10 @@ def sync(
171171
idempotency_key (None | str | Unset):
172172
body (CreateJournalEntryRequest): Create a new journal entry with balanced line items.
173173
174-
The entry is always created as `status='draft'`. Posting a draft
175-
happens via `close-period` (for batch month-end posting) or — in
176-
the future — an individual `post-journal-entry` op. This matches
177-
the existing `create-manual-closing-entry` behavior.
174+
Defaults to `status='draft'` for ongoing native writes (the normal
175+
workflow: draft → review → post via close-period). Pass
176+
`status='posted'` for historical data import where entries represent
177+
already-happened business events that don't need review.
178178
179179
Total debit amount must equal total credit amount or the request
180180
is rejected with 422. `line_items` must contain at least two rows
@@ -217,10 +217,10 @@ async def asyncio_detailed(
217217
idempotency_key (None | str | Unset):
218218
body (CreateJournalEntryRequest): Create a new journal entry with balanced line items.
219219
220-
The entry is always created as `status='draft'`. Posting a draft
221-
happens via `close-period` (for batch month-end posting) or — in
222-
the future — an individual `post-journal-entry` op. This matches
223-
the existing `create-manual-closing-entry` behavior.
220+
Defaults to `status='draft'` for ongoing native writes (the normal
221+
workflow: draft → review → post via close-period). Pass
222+
`status='posted'` for historical data import where entries represent
223+
already-happened business events that don't need review.
224224
225225
Total debit amount must equal total credit amount or the request
226226
is rejected with 422. `line_items` must contain at least two rows
@@ -266,10 +266,10 @@ async def asyncio(
266266
idempotency_key (None | str | Unset):
267267
body (CreateJournalEntryRequest): Create a new journal entry with balanced line items.
268268
269-
The entry is always created as `status='draft'`. Posting a draft
270-
happens via `close-period` (for batch month-end posting) or — in
271-
the future — an individual `post-journal-entry` op. This matches
272-
the existing `create-manual-closing-entry` behavior.
269+
Defaults to `status='draft'` for ongoing native writes (the normal
270+
workflow: draft → review → post via close-period). Pass
271+
`status='posted'` for historical data import where entries represent
272+
already-happened business events that don't need review.
273273
274274
Total debit amount must equal total credit amount or the request
275275
is rejected with 422. `line_items` must contain at least two rows
Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
from http import HTTPStatus
2+
from typing import Any, cast
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.http_validation_error import HTTPValidationError
10+
from ...models.link_entity_taxonomy_request import LinkEntityTaxonomyRequest
11+
from ...models.operation_envelope import OperationEnvelope
12+
from ...models.operation_error import OperationError
13+
from ...types import UNSET, Response, Unset
14+
15+
16+
def _get_kwargs(
17+
graph_id: str,
18+
*,
19+
body: LinkEntityTaxonomyRequest,
20+
idempotency_key: None | str | Unset = UNSET,
21+
) -> dict[str, Any]:
22+
headers: dict[str, Any] = {}
23+
if not isinstance(idempotency_key, Unset):
24+
headers["Idempotency-Key"] = idempotency_key
25+
26+
_kwargs: dict[str, Any] = {
27+
"method": "post",
28+
"url": "/extensions/roboledger/{graph_id}/operations/link-entity-taxonomy".format(
29+
graph_id=quote(str(graph_id), safe=""),
30+
),
31+
}
32+
33+
_kwargs["json"] = body.to_dict()
34+
35+
headers["Content-Type"] = "application/json"
36+
37+
_kwargs["headers"] = headers
38+
return _kwargs
39+
40+
41+
def _parse_response(
42+
*, client: AuthenticatedClient | Client, response: httpx.Response
43+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
44+
if response.status_code == 200:
45+
response_200 = OperationEnvelope.from_dict(response.json())
46+
47+
return response_200
48+
49+
if response.status_code == 400:
50+
response_400 = OperationError.from_dict(response.json())
51+
52+
return response_400
53+
54+
if response.status_code == 401:
55+
response_401 = cast(Any, None)
56+
return response_401
57+
58+
if response.status_code == 403:
59+
response_403 = cast(Any, None)
60+
return response_403
61+
62+
if response.status_code == 404:
63+
response_404 = OperationError.from_dict(response.json())
64+
65+
return response_404
66+
67+
if response.status_code == 409:
68+
response_409 = OperationError.from_dict(response.json())
69+
70+
return response_409
71+
72+
if response.status_code == 422:
73+
response_422 = HTTPValidationError.from_dict(response.json())
74+
75+
return response_422
76+
77+
if response.status_code == 429:
78+
response_429 = cast(Any, None)
79+
return response_429
80+
81+
if response.status_code == 500:
82+
response_500 = cast(Any, None)
83+
return response_500
84+
85+
if client.raise_on_unexpected_status:
86+
raise errors.UnexpectedStatus(response.status_code, response.content)
87+
else:
88+
return None
89+
90+
91+
def _build_response(
92+
*, client: AuthenticatedClient | Client, response: httpx.Response
93+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
94+
return Response(
95+
status_code=HTTPStatus(response.status_code),
96+
content=response.content,
97+
headers=response.headers,
98+
parsed=_parse_response(client=client, response=response),
99+
)
100+
101+
102+
def sync_detailed(
103+
graph_id: str,
104+
*,
105+
client: AuthenticatedClient,
106+
body: LinkEntityTaxonomyRequest,
107+
idempotency_key: None | str | Unset = UNSET,
108+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
109+
"""Link Entity to Taxonomy
110+
111+
Link the graph's entity to a taxonomy (creates the ENTITY_HAS_TAXONOMY edge). Idempotent — returns
112+
existing linkage if it already exists. Required after creating a CoA taxonomy so the platform knows
113+
which chart of accounts the entity reports under.
114+
115+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
116+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
117+
118+
Args:
119+
graph_id (str):
120+
idempotency_key (None | str | Unset):
121+
body (LinkEntityTaxonomyRequest): Link an entity to a taxonomy (creates the
122+
ENTITY_HAS_TAXONOMY edge).
123+
124+
This is how a graph declares "this entity reports under this taxonomy."
125+
For chart_of_accounts taxonomies, this tells the platform which CoA the
126+
entity uses. For reporting taxonomies, which standard (us-gaap, ifrs).
127+
128+
Raises:
129+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
130+
httpx.TimeoutException: If the request takes longer than Client.timeout.
131+
132+
Returns:
133+
Response[Any | HTTPValidationError | OperationEnvelope | OperationError]
134+
"""
135+
136+
kwargs = _get_kwargs(
137+
graph_id=graph_id,
138+
body=body,
139+
idempotency_key=idempotency_key,
140+
)
141+
142+
response = client.get_httpx_client().request(
143+
**kwargs,
144+
)
145+
146+
return _build_response(client=client, response=response)
147+
148+
149+
def sync(
150+
graph_id: str,
151+
*,
152+
client: AuthenticatedClient,
153+
body: LinkEntityTaxonomyRequest,
154+
idempotency_key: None | str | Unset = UNSET,
155+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
156+
"""Link Entity to Taxonomy
157+
158+
Link the graph's entity to a taxonomy (creates the ENTITY_HAS_TAXONOMY edge). Idempotent — returns
159+
existing linkage if it already exists. Required after creating a CoA taxonomy so the platform knows
160+
which chart of accounts the entity reports under.
161+
162+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
163+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
164+
165+
Args:
166+
graph_id (str):
167+
idempotency_key (None | str | Unset):
168+
body (LinkEntityTaxonomyRequest): Link an entity to a taxonomy (creates the
169+
ENTITY_HAS_TAXONOMY edge).
170+
171+
This is how a graph declares "this entity reports under this taxonomy."
172+
For chart_of_accounts taxonomies, this tells the platform which CoA the
173+
entity uses. For reporting taxonomies, which standard (us-gaap, ifrs).
174+
175+
Raises:
176+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
177+
httpx.TimeoutException: If the request takes longer than Client.timeout.
178+
179+
Returns:
180+
Any | HTTPValidationError | OperationEnvelope | OperationError
181+
"""
182+
183+
return sync_detailed(
184+
graph_id=graph_id,
185+
client=client,
186+
body=body,
187+
idempotency_key=idempotency_key,
188+
).parsed
189+
190+
191+
async def asyncio_detailed(
192+
graph_id: str,
193+
*,
194+
client: AuthenticatedClient,
195+
body: LinkEntityTaxonomyRequest,
196+
idempotency_key: None | str | Unset = UNSET,
197+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
198+
"""Link Entity to Taxonomy
199+
200+
Link the graph's entity to a taxonomy (creates the ENTITY_HAS_TAXONOMY edge). Idempotent — returns
201+
existing linkage if it already exists. Required after creating a CoA taxonomy so the platform knows
202+
which chart of accounts the entity reports under.
203+
204+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
205+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
206+
207+
Args:
208+
graph_id (str):
209+
idempotency_key (None | str | Unset):
210+
body (LinkEntityTaxonomyRequest): Link an entity to a taxonomy (creates the
211+
ENTITY_HAS_TAXONOMY edge).
212+
213+
This is how a graph declares "this entity reports under this taxonomy."
214+
For chart_of_accounts taxonomies, this tells the platform which CoA the
215+
entity uses. For reporting taxonomies, which standard (us-gaap, ifrs).
216+
217+
Raises:
218+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
219+
httpx.TimeoutException: If the request takes longer than Client.timeout.
220+
221+
Returns:
222+
Response[Any | HTTPValidationError | OperationEnvelope | OperationError]
223+
"""
224+
225+
kwargs = _get_kwargs(
226+
graph_id=graph_id,
227+
body=body,
228+
idempotency_key=idempotency_key,
229+
)
230+
231+
response = await client.get_async_httpx_client().request(**kwargs)
232+
233+
return _build_response(client=client, response=response)
234+
235+
236+
async def asyncio(
237+
graph_id: str,
238+
*,
239+
client: AuthenticatedClient,
240+
body: LinkEntityTaxonomyRequest,
241+
idempotency_key: None | str | Unset = UNSET,
242+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
243+
"""Link Entity to Taxonomy
244+
245+
Link the graph's entity to a taxonomy (creates the ENTITY_HAS_TAXONOMY edge). Idempotent — returns
246+
existing linkage if it already exists. Required after creating a CoA taxonomy so the platform knows
247+
which chart of accounts the entity reports under.
248+
249+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
250+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
251+
252+
Args:
253+
graph_id (str):
254+
idempotency_key (None | str | Unset):
255+
body (LinkEntityTaxonomyRequest): Link an entity to a taxonomy (creates the
256+
ENTITY_HAS_TAXONOMY edge).
257+
258+
This is how a graph declares "this entity reports under this taxonomy."
259+
For chart_of_accounts taxonomies, this tells the platform which CoA the
260+
entity uses. For reporting taxonomies, which standard (us-gaap, ifrs).
261+
262+
Raises:
263+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
264+
httpx.TimeoutException: If the request takes longer than Client.timeout.
265+
266+
Returns:
267+
Any | HTTPValidationError | OperationEnvelope | OperationError
268+
"""
269+
270+
return (
271+
await asyncio_detailed(
272+
graph_id=graph_id,
273+
client=client,
274+
body=body,
275+
idempotency_key=idempotency_key,
276+
)
277+
).parsed

0 commit comments

Comments
 (0)