Skip to content

Commit db43ed2

Browse files
authored
feat(ledger): record_ownership_change (#277)
## Summary `record_ownership_change` for robosystems [#1921](RoboFinSystems/robosystems#1921): the parent buying more of a member from its outside owners, staying on full consolidation. ## Changes - `record_ownership_change(graph_id, entity_id=, period=, ownership_pct=, consideration=, basis=)`: `entity_id`, `period` (the first month the new share holds), `ownership_pct`, `consideration` in cents and `basis`. Returns the share before and after, the book value and earnings moved, the equity adjustment, and the drafted entry. - Regenerated SDK and GraphQL schema snapshot: `RecordOwnershipChangeRequest`, `OwnershipChangeResponse`, and `ownership_change` among the adjustment kinds. All additive. ## Release Generated tier plus one facade method: a client **minor**. It waits on the robosystems release that carries #1921 (migration 0062); until then the operation does not exist on the server. The twin of [typescript-client #293](RoboFinSystems/robosystems-typescript-client#293). ## Testing `tests/test_ledger_client.py`: `record_ownership_change` sends the body. Ruff, basedpyright and the suite (726) pass; the schema snapshot also takes `allocationShare`'s description from #1919. Regenerated against the local API on #1921's branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VPxBBHkqhwkZ6Eq8EXSBR6
2 parents ebb0511 + 155546a commit db43ed2

10 files changed

Lines changed: 807 additions & 4 deletions
Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
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_ownership_change_response import (
11+
OperationEnvelopeOwnershipChangeResponse,
12+
)
13+
from ...models.record_ownership_change_request import RecordOwnershipChangeRequest
14+
from ...types import UNSET, Response, Unset
15+
16+
17+
def _get_kwargs(
18+
graph_id: str,
19+
*,
20+
body: RecordOwnershipChangeRequest,
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-ownership-change".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 | OperationEnvelopeOwnershipChangeResponse | None:
45+
if response.status_code == 200:
46+
response_200 = OperationEnvelopeOwnershipChangeResponse.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 | OperationEnvelopeOwnershipChangeResponse]:
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: RecordOwnershipChangeRequest,
112+
idempotency_key: None | str | Unset = UNSET,
113+
) -> Response[ErrorResponse | OperationEnvelopeOwnershipChangeResponse]:
114+
"""Record Ownership Change
115+
116+
Record the parent buying more of a member consolidated in full from its outside owners: the share it
117+
holds from a month (`ownership_pct`, staying 50 or more) and what it paid them in cents, with the
118+
basis. It sets the member's share from that month and writes a draft in the consolidation entity,
119+
dated the month's first day, that its close posts: ASC 810 makes it an equity transaction, so the
120+
price above the book value of the capital bought goes against the investment, the share bought of
121+
the member's results since it joined comes out of the outside owners' interest, and the difference
122+
is the parent's equity, with no gain or loss. preview-consolidation-entries then reads the price as
123+
part of the parent's investment and the new share from that month. Changes are recorded in order;
124+
recording a month again replaces its draft, and a posted one is reversed first. A sale, or a change
125+
across consolidation methods, is not supported yet.
126+
127+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
128+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
129+
130+
Args:
131+
graph_id (str):
132+
idempotency_key (None | str | Unset):
133+
body (RecordOwnershipChangeRequest): The parent buys more of a member from its outside
134+
owners, staying on the
135+
same consolidation method: the share it holds from a month, and what it
136+
paid. ASC 810 makes it an equity transaction, never a gain or loss.
137+
138+
Raises:
139+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
140+
httpx.TimeoutException: If the request takes longer than Client.timeout.
141+
142+
Returns:
143+
Response[ErrorResponse | OperationEnvelopeOwnershipChangeResponse]
144+
"""
145+
146+
kwargs = _get_kwargs(
147+
graph_id=graph_id,
148+
body=body,
149+
idempotency_key=idempotency_key,
150+
)
151+
152+
response = client.get_httpx_client().request(
153+
**kwargs,
154+
)
155+
156+
return _build_response(client=client, response=response)
157+
158+
159+
def sync(
160+
graph_id: str,
161+
*,
162+
client: AuthenticatedClient,
163+
body: RecordOwnershipChangeRequest,
164+
idempotency_key: None | str | Unset = UNSET,
165+
) -> ErrorResponse | OperationEnvelopeOwnershipChangeResponse | None:
166+
"""Record Ownership Change
167+
168+
Record the parent buying more of a member consolidated in full from its outside owners: the share it
169+
holds from a month (`ownership_pct`, staying 50 or more) and what it paid them in cents, with the
170+
basis. It sets the member's share from that month and writes a draft in the consolidation entity,
171+
dated the month's first day, that its close posts: ASC 810 makes it an equity transaction, so the
172+
price above the book value of the capital bought goes against the investment, the share bought of
173+
the member's results since it joined comes out of the outside owners' interest, and the difference
174+
is the parent's equity, with no gain or loss. preview-consolidation-entries then reads the price as
175+
part of the parent's investment and the new share from that month. Changes are recorded in order;
176+
recording a month again replaces its draft, and a posted one is reversed first. A sale, or a change
177+
across consolidation methods, is not supported yet.
178+
179+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
180+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
181+
182+
Args:
183+
graph_id (str):
184+
idempotency_key (None | str | Unset):
185+
body (RecordOwnershipChangeRequest): The parent buys more of a member from its outside
186+
owners, staying on the
187+
same consolidation method: the share it holds from a month, and what it
188+
paid. ASC 810 makes it an equity transaction, never a gain or loss.
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 | OperationEnvelopeOwnershipChangeResponse
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: RecordOwnershipChangeRequest,
211+
idempotency_key: None | str | Unset = UNSET,
212+
) -> Response[ErrorResponse | OperationEnvelopeOwnershipChangeResponse]:
213+
"""Record Ownership Change
214+
215+
Record the parent buying more of a member consolidated in full from its outside owners: the share it
216+
holds from a month (`ownership_pct`, staying 50 or more) and what it paid them in cents, with the
217+
basis. It sets the member's share from that month and writes a draft in the consolidation entity,
218+
dated the month's first day, that its close posts: ASC 810 makes it an equity transaction, so the
219+
price above the book value of the capital bought goes against the investment, the share bought of
220+
the member's results since it joined comes out of the outside owners' interest, and the difference
221+
is the parent's equity, with no gain or loss. preview-consolidation-entries then reads the price as
222+
part of the parent's investment and the new share from that month. Changes are recorded in order;
223+
recording a month again replaces its draft, and a posted one is reversed first. A sale, or a change
224+
across consolidation methods, is not supported yet.
225+
226+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
227+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
228+
229+
Args:
230+
graph_id (str):
231+
idempotency_key (None | str | Unset):
232+
body (RecordOwnershipChangeRequest): The parent buys more of a member from its outside
233+
owners, staying on the
234+
same consolidation method: the share it holds from a month, and what it
235+
paid. ASC 810 makes it an equity transaction, never a gain or loss.
236+
237+
Raises:
238+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
239+
httpx.TimeoutException: If the request takes longer than Client.timeout.
240+
241+
Returns:
242+
Response[ErrorResponse | OperationEnvelopeOwnershipChangeResponse]
243+
"""
244+
245+
kwargs = _get_kwargs(
246+
graph_id=graph_id,
247+
body=body,
248+
idempotency_key=idempotency_key,
249+
)
250+
251+
response = await client.get_async_httpx_client().request(**kwargs)
252+
253+
return _build_response(client=client, response=response)
254+
255+
256+
async def asyncio(
257+
graph_id: str,
258+
*,
259+
client: AuthenticatedClient,
260+
body: RecordOwnershipChangeRequest,
261+
idempotency_key: None | str | Unset = UNSET,
262+
) -> ErrorResponse | OperationEnvelopeOwnershipChangeResponse | None:
263+
"""Record Ownership Change
264+
265+
Record the parent buying more of a member consolidated in full from its outside owners: the share it
266+
holds from a month (`ownership_pct`, staying 50 or more) and what it paid them in cents, with the
267+
basis. It sets the member's share from that month and writes a draft in the consolidation entity,
268+
dated the month's first day, that its close posts: ASC 810 makes it an equity transaction, so the
269+
price above the book value of the capital bought goes against the investment, the share bought of
270+
the member's results since it joined comes out of the outside owners' interest, and the difference
271+
is the parent's equity, with no gain or loss. preview-consolidation-entries then reads the price as
272+
part of the parent's investment and the new share from that month. Changes are recorded in order;
273+
recording a month again replaces its draft, and a posted one is reversed first. A sale, or a change
274+
across consolidation methods, is not supported yet.
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 (RecordOwnershipChangeRequest): The parent buys more of a member from its outside
283+
owners, staying on the
284+
same consolidation method: the share it holds from a month, and what it
285+
paid. ASC 810 makes it an equity transaction, never a gain or loss.
286+
287+
Raises:
288+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
289+
httpx.TimeoutException: If the request takes longer than Client.timeout.
290+
291+
Returns:
292+
ErrorResponse | OperationEnvelopeOwnershipChangeResponse
293+
"""
294+
295+
return (
296+
await asyncio_detailed(
297+
graph_id=graph_id,
298+
client=client,
299+
body=body,
300+
idempotency_key=idempotency_key,
301+
)
302+
).parsed

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
from ..api.robo_ledger_ledger_events.record_acquisition import (
6767
sync_detailed as op_record_acquisition,
6868
)
69+
from ..api.robo_ledger_ledger_events.record_ownership_change import (
70+
sync_detailed as op_record_ownership_change,
71+
)
6972
from ..api.robo_ledger_ledger_events.record_statement_balance import (
7073
sync_detailed as op_record_statement_balance,
7174
)
@@ -622,6 +625,8 @@
622625
from ..models.acquisition_allocation import AcquisitionAllocation
623626
from ..models.acquisition_response import AcquisitionResponse
624627
from ..models.record_acquisition_request import RecordAcquisitionRequest
628+
from ..models.ownership_change_response import OwnershipChangeResponse
629+
from ..models.record_ownership_change_request import RecordOwnershipChangeRequest
625630
from ..models.live_financial_statement_request import LiveFinancialStatementRequest
626631
from ..models.financial_statement_analysis_response import (
627632
FinancialStatementAnalysisResponse,
@@ -2489,6 +2494,36 @@ def record_acquisition(
24892494
envelope = self._call_op("Record acquisition", response)
24902495
return self._typed_result("Record acquisition", envelope, AcquisitionResponse)
24912496

2497+
def record_ownership_change(
2498+
self,
2499+
graph_id: str,
2500+
*,
2501+
entity_id: str,
2502+
period: str,
2503+
ownership_pct: float,
2504+
consideration: int,
2505+
basis: str,
2506+
) -> OwnershipChangeResponse:
2507+
"""Record the parent buying more of a member from its outside owners,
2508+
staying on full consolidation: the share it holds from ``period``
2509+
(``YYYY-MM``) and the price paid in cents, with the ``basis``. Sets the
2510+
member's share from that month and writes a draft in the consolidation
2511+
entity that its close posts — an equity transaction under ASC 810."""
2512+
body = RecordOwnershipChangeRequest(
2513+
entity_id=entity_id,
2514+
period=period,
2515+
ownership_pct=ownership_pct,
2516+
consideration=consideration,
2517+
basis=basis,
2518+
)
2519+
response = op_record_ownership_change(
2520+
graph_id=graph_id, body=body, client=self._get_client()
2521+
)
2522+
envelope = self._call_op("Record ownership change", response)
2523+
return self._typed_result(
2524+
"Record ownership change", envelope, OwnershipChangeResponse
2525+
)
2526+
24922527
# ── Event blocks (generic preview + status transitions) ──────────────
24932528

24942529
def create_event_block(

‎robosystems_client/graphql/schema.graphql‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,12 @@ type Query {
815815
): PublishListDetail
816816

817817
"""
818-
The outside owners' share of a member's result for one month: the
819-
pro-rata figure its ownership gives, the override set with
820-
`set-allocation-override` if any, and the share the consolidating
821-
entries use.
818+
The outside owners' share of a member's result for one month.
819+
820+
The pro-rata figure its ownership gives, the override set with
821+
`set-allocation-override` if any, and the share the consolidating entries
822+
use. Null for an entity that is not a member consolidated in full that
823+
month: its outside owners have no share the engine allocates.
822824
"""
823825
allocationShare(
824826
"""The member."""

0 commit comments

Comments
 (0)