|
| 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 |
0 commit comments