Skip to content

Commit a37a114

Browse files
authored
feat(ledger): allocation share reads and record_acquisition (#276)
## Summary Facade methods for two backend additions in robosystems `feature/group-acquisition`: the allocation share reads behind roboledger-app's allocation-override form, and `recordAcquisition` for a member bought from its owners. ## Changes - `get_allocation_share(graph_id, entity_id, period)` → `AllocationShare | None`: the member's month result, the outside owners' pro-rata share, the override if set, the share the consolidating entries use (`effectiveAmount`), and `closed`. Amounts in cents. - `list_allocation_overrides(graph_id, entity_id)` → `list[AllocationOverride]`, oldest month first. - `record_acquisition(graph_id, entity_id=, consideration=, basis=, nci_fair_value=, allocations=, confirm_bargain_purchase=)`; returns the drafted acquisition with its goodwill. - Regenerated SDK and GraphQL types: `RecordAcquisitionRequest`, `AcquisitionResponse`, `AcquisitionAllocation`, and `cause` on `ConsolidationResidual`. All additive. ## Release Generated tier plus new facade methods, no break: a client **minor**. It waits on the robosystems release that carries `feature/group-acquisition` (after v1.19.6): until then the GraphQL fields and the operation do not exist on the server. The twin of [typescript-client #292](RoboFinSystems/robosystems-typescript-client#292). ## Testing `tests/test_ledger_client.py`: `record_acquisition` sends the body; `get_allocation_share` parses the share and sends the variables; `list_allocation_overrides` unwraps, empty when none. Ruff, basedpyright and the suite (725) pass; the GraphQL schema snapshot refreshed and codegen regenerated. Regenerated against the local API on the backend branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VPxBBHkqhwkZ6Eq8EXSBR6
2 parents a38095e + dd03541 commit a37a114

19 files changed

Lines changed: 1313 additions & 0 deletions
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
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_acquisition_response import (
11+
OperationEnvelopeAcquisitionResponse,
12+
)
13+
from ...models.record_acquisition_request import RecordAcquisitionRequest
14+
from ...types import UNSET, Response, Unset
15+
16+
17+
def _get_kwargs(
18+
graph_id: str,
19+
*,
20+
body: RecordAcquisitionRequest,
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/record-acquisition".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 | OperationEnvelopeAcquisitionResponse | None:
45+
if response.status_code == 200:
46+
response_200 = OperationEnvelopeAcquisitionResponse.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 | OperationEnvelopeAcquisitionResponse]:
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: RecordAcquisitionRequest,
112+
idempotency_key: None | str | Unset = UNSET,
113+
) -> Response[ErrorResponse | OperationEnvelopeAcquisitionResponse]:
114+
"""Record Acquisition
115+
116+
Record a member the parent bought from its outside owners, for a member that joined mid-life
117+
(`joined_on` set) with its balance sheet at acquisition recorded by record-opening-balance. Give the
118+
consideration paid to the sellers in cents and the basis (the purchase agreement, a valuation);
119+
optionally the fair value of the outside owners' interest (`nci_fair_value`, for goodwill on the
120+
whole business) and fair-value step-ups (`allocations`). It writes a draft in the consolidation
121+
entity, dated the join, that its close posts: the excess of the consideration over the parent's
122+
share of the member's equity at acquisition goes to the step-ups and the rest to goodwill. preview-
123+
consolidation-entries then reads the consideration as the parent's investment, so the pre-
124+
acquisition residual clears. A bargain purchase is refused until `confirm_bargain_purchase` is set
125+
after the reassessment ASC 805 asks for. Recording again replaces the draft; a posted acquisition is
126+
reversed first.
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 (RecordAcquisitionRequest): A member bought from its outside owners: what the parent
135+
paid them,
136+
and how the excess over its share of the member's equity at acquisition is
137+
allocated. The engine never invents a fair value; each comes from the
138+
person, with the basis.
139+
140+
Raises:
141+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
142+
httpx.TimeoutException: If the request takes longer than Client.timeout.
143+
144+
Returns:
145+
Response[ErrorResponse | OperationEnvelopeAcquisitionResponse]
146+
"""
147+
148+
kwargs = _get_kwargs(
149+
graph_id=graph_id,
150+
body=body,
151+
idempotency_key=idempotency_key,
152+
)
153+
154+
response = client.get_httpx_client().request(
155+
**kwargs,
156+
)
157+
158+
return _build_response(client=client, response=response)
159+
160+
161+
def sync(
162+
graph_id: str,
163+
*,
164+
client: AuthenticatedClient,
165+
body: RecordAcquisitionRequest,
166+
idempotency_key: None | str | Unset = UNSET,
167+
) -> ErrorResponse | OperationEnvelopeAcquisitionResponse | None:
168+
"""Record Acquisition
169+
170+
Record a member the parent bought from its outside owners, for a member that joined mid-life
171+
(`joined_on` set) with its balance sheet at acquisition recorded by record-opening-balance. Give the
172+
consideration paid to the sellers in cents and the basis (the purchase agreement, a valuation);
173+
optionally the fair value of the outside owners' interest (`nci_fair_value`, for goodwill on the
174+
whole business) and fair-value step-ups (`allocations`). It writes a draft in the consolidation
175+
entity, dated the join, that its close posts: the excess of the consideration over the parent's
176+
share of the member's equity at acquisition goes to the step-ups and the rest to goodwill. preview-
177+
consolidation-entries then reads the consideration as the parent's investment, so the pre-
178+
acquisition residual clears. A bargain purchase is refused until `confirm_bargain_purchase` is set
179+
after the reassessment ASC 805 asks for. Recording again replaces the draft; a posted acquisition is
180+
reversed first.
181+
182+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
183+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
184+
185+
Args:
186+
graph_id (str):
187+
idempotency_key (None | str | Unset):
188+
body (RecordAcquisitionRequest): A member bought from its outside owners: what the parent
189+
paid them,
190+
and how the excess over its share of the member's equity at acquisition is
191+
allocated. The engine never invents a fair value; each comes from the
192+
person, with the basis.
193+
194+
Raises:
195+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
196+
httpx.TimeoutException: If the request takes longer than Client.timeout.
197+
198+
Returns:
199+
ErrorResponse | OperationEnvelopeAcquisitionResponse
200+
"""
201+
202+
return sync_detailed(
203+
graph_id=graph_id,
204+
client=client,
205+
body=body,
206+
idempotency_key=idempotency_key,
207+
).parsed
208+
209+
210+
async def asyncio_detailed(
211+
graph_id: str,
212+
*,
213+
client: AuthenticatedClient,
214+
body: RecordAcquisitionRequest,
215+
idempotency_key: None | str | Unset = UNSET,
216+
) -> Response[ErrorResponse | OperationEnvelopeAcquisitionResponse]:
217+
"""Record Acquisition
218+
219+
Record a member the parent bought from its outside owners, for a member that joined mid-life
220+
(`joined_on` set) with its balance sheet at acquisition recorded by record-opening-balance. Give the
221+
consideration paid to the sellers in cents and the basis (the purchase agreement, a valuation);
222+
optionally the fair value of the outside owners' interest (`nci_fair_value`, for goodwill on the
223+
whole business) and fair-value step-ups (`allocations`). It writes a draft in the consolidation
224+
entity, dated the join, that its close posts: the excess of the consideration over the parent's
225+
share of the member's equity at acquisition goes to the step-ups and the rest to goodwill. preview-
226+
consolidation-entries then reads the consideration as the parent's investment, so the pre-
227+
acquisition residual clears. A bargain purchase is refused until `confirm_bargain_purchase` is set
228+
after the reassessment ASC 805 asks for. Recording again replaces the draft; a posted acquisition is
229+
reversed first.
230+
231+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
232+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
233+
234+
Args:
235+
graph_id (str):
236+
idempotency_key (None | str | Unset):
237+
body (RecordAcquisitionRequest): A member bought from its outside owners: what the parent
238+
paid them,
239+
and how the excess over its share of the member's equity at acquisition is
240+
allocated. The engine never invents a fair value; each comes from the
241+
person, with the basis.
242+
243+
Raises:
244+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
245+
httpx.TimeoutException: If the request takes longer than Client.timeout.
246+
247+
Returns:
248+
Response[ErrorResponse | OperationEnvelopeAcquisitionResponse]
249+
"""
250+
251+
kwargs = _get_kwargs(
252+
graph_id=graph_id,
253+
body=body,
254+
idempotency_key=idempotency_key,
255+
)
256+
257+
response = await client.get_async_httpx_client().request(**kwargs)
258+
259+
return _build_response(client=client, response=response)
260+
261+
262+
async def asyncio(
263+
graph_id: str,
264+
*,
265+
client: AuthenticatedClient,
266+
body: RecordAcquisitionRequest,
267+
idempotency_key: None | str | Unset = UNSET,
268+
) -> ErrorResponse | OperationEnvelopeAcquisitionResponse | None:
269+
"""Record Acquisition
270+
271+
Record a member the parent bought from its outside owners, for a member that joined mid-life
272+
(`joined_on` set) with its balance sheet at acquisition recorded by record-opening-balance. Give the
273+
consideration paid to the sellers in cents and the basis (the purchase agreement, a valuation);
274+
optionally the fair value of the outside owners' interest (`nci_fair_value`, for goodwill on the
275+
whole business) and fair-value step-ups (`allocations`). It writes a draft in the consolidation
276+
entity, dated the join, that its close posts: the excess of the consideration over the parent's
277+
share of the member's equity at acquisition goes to the step-ups and the rest to goodwill. preview-
278+
consolidation-entries then reads the consideration as the parent's investment, so the pre-
279+
acquisition residual clears. A bargain purchase is refused until `confirm_bargain_purchase` is set
280+
after the reassessment ASC 805 asks for. Recording again replaces the draft; a posted acquisition is
281+
reversed first.
282+
283+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
284+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
285+
286+
Args:
287+
graph_id (str):
288+
idempotency_key (None | str | Unset):
289+
body (RecordAcquisitionRequest): A member bought from its outside owners: what the parent
290+
paid them,
291+
and how the excess over its share of the member's equity at acquisition is
292+
allocated. The engine never invents a fair value; each comes from the
293+
person, with the basis.
294+
295+
Raises:
296+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
297+
httpx.TimeoutException: If the request takes longer than Client.timeout.
298+
299+
Returns:
300+
ErrorResponse | OperationEnvelopeAcquisitionResponse
301+
"""
302+
303+
return (
304+
await asyncio_detailed(
305+
graph_id=graph_id,
306+
client=client,
307+
body=body,
308+
idempotency_key=idempotency_key,
309+
)
310+
).parsed

0 commit comments

Comments
 (0)