|
| 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_reconciliation_preview_response import ( |
| 11 | + OperationEnvelopeReconciliationPreviewResponse, |
| 12 | +) |
| 13 | +from ...models.preview_reconciliations_request import PreviewReconciliationsRequest |
| 14 | +from ...types import UNSET, Response, Unset |
| 15 | + |
| 16 | + |
| 17 | +def _get_kwargs( |
| 18 | + graph_id: str, |
| 19 | + *, |
| 20 | + body: PreviewReconciliationsRequest, |
| 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/preview-reconciliations".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 | OperationEnvelopeReconciliationPreviewResponse | None: |
| 45 | + if response.status_code == 200: |
| 46 | + response_200 = OperationEnvelopeReconciliationPreviewResponse.from_dict( |
| 47 | + response.json() |
| 48 | + ) |
| 49 | + |
| 50 | + return response_200 |
| 51 | + |
| 52 | + if response.status_code == 400: |
| 53 | + response_400 = ErrorResponse.from_dict(response.json()) |
| 54 | + |
| 55 | + return response_400 |
| 56 | + |
| 57 | + if response.status_code == 401: |
| 58 | + response_401 = ErrorResponse.from_dict(response.json()) |
| 59 | + |
| 60 | + return response_401 |
| 61 | + |
| 62 | + if response.status_code == 403: |
| 63 | + response_403 = ErrorResponse.from_dict(response.json()) |
| 64 | + |
| 65 | + return response_403 |
| 66 | + |
| 67 | + if response.status_code == 404: |
| 68 | + response_404 = ErrorResponse.from_dict(response.json()) |
| 69 | + |
| 70 | + return response_404 |
| 71 | + |
| 72 | + if response.status_code == 409: |
| 73 | + response_409 = ErrorResponse.from_dict(response.json()) |
| 74 | + |
| 75 | + return response_409 |
| 76 | + |
| 77 | + if response.status_code == 422: |
| 78 | + response_422 = ErrorResponse.from_dict(response.json()) |
| 79 | + |
| 80 | + return response_422 |
| 81 | + |
| 82 | + if response.status_code == 429: |
| 83 | + response_429 = ErrorResponse.from_dict(response.json()) |
| 84 | + |
| 85 | + return response_429 |
| 86 | + |
| 87 | + if response.status_code == 500: |
| 88 | + response_500 = ErrorResponse.from_dict(response.json()) |
| 89 | + |
| 90 | + return response_500 |
| 91 | + |
| 92 | + if client.raise_on_unexpected_status: |
| 93 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 94 | + else: |
| 95 | + return None |
| 96 | + |
| 97 | + |
| 98 | +def _build_response( |
| 99 | + *, client: AuthenticatedClient | Client, response: httpx.Response |
| 100 | +) -> Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse]: |
| 101 | + return Response( |
| 102 | + status_code=HTTPStatus(response.status_code), |
| 103 | + content=response.content, |
| 104 | + headers=response.headers, |
| 105 | + parsed=_parse_response(client=client, response=response), |
| 106 | + ) |
| 107 | + |
| 108 | + |
| 109 | +def sync_detailed( |
| 110 | + graph_id: str, |
| 111 | + *, |
| 112 | + client: AuthenticatedClient, |
| 113 | + body: PreviewReconciliationsRequest, |
| 114 | + idempotency_key: None | str | Unset = UNSET, |
| 115 | +) -> Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse]: |
| 116 | + """Preview Reconciliations |
| 117 | +
|
| 118 | + Compare the ledger at a period end with something outside it, without recording anything. `method` |
| 119 | + picks the check. `source_ledger` (the default) reads QuickBooks' own trial balance for the period |
| 120 | + end and sets it beside the ledger's, account by account: balance-sheet accounts cumulatively, income |
| 121 | + and expense accounts from the start of the fiscal year. A difference there means the ledger's copy |
| 122 | + of the books has drifted from the source (a transaction deleted or back-dated there after it was |
| 123 | + synced, or activity not yet synced), so run it before trusting any other figure on a synced ledger; |
| 124 | + it needs a connected QuickBooks ledger. `schedule_register` compares each asset account a schedule |
| 125 | + carries a balance on (a prepaid, accumulated depreciation, a fixed-asset cost account) with what its |
| 126 | + schedules say it holds, and lists the schedules behind each figure. A difference there is a balance |
| 127 | + with no schedule behind it, or a scheduled amount the ledger does not hold. Each row carries both |
| 128 | + balances, the difference, and whether the account ties. |
| 129 | +
|
| 130 | + **Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours |
| 131 | + return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict. |
| 132 | +
|
| 133 | + Args: |
| 134 | + graph_id (str): |
| 135 | + idempotency_key (None | str | Unset): |
| 136 | + body (PreviewReconciliationsRequest): Compare the ledger's balances at a period end with |
| 137 | + an independent source. |
| 138 | +
|
| 139 | + Raises: |
| 140 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 141 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 142 | +
|
| 143 | + Returns: |
| 144 | + Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse] |
| 145 | + """ |
| 146 | + |
| 147 | + kwargs = _get_kwargs( |
| 148 | + graph_id=graph_id, |
| 149 | + body=body, |
| 150 | + idempotency_key=idempotency_key, |
| 151 | + ) |
| 152 | + |
| 153 | + response = client.get_httpx_client().request( |
| 154 | + **kwargs, |
| 155 | + ) |
| 156 | + |
| 157 | + return _build_response(client=client, response=response) |
| 158 | + |
| 159 | + |
| 160 | +def sync( |
| 161 | + graph_id: str, |
| 162 | + *, |
| 163 | + client: AuthenticatedClient, |
| 164 | + body: PreviewReconciliationsRequest, |
| 165 | + idempotency_key: None | str | Unset = UNSET, |
| 166 | +) -> ErrorResponse | OperationEnvelopeReconciliationPreviewResponse | None: |
| 167 | + """Preview Reconciliations |
| 168 | +
|
| 169 | + Compare the ledger at a period end with something outside it, without recording anything. `method` |
| 170 | + picks the check. `source_ledger` (the default) reads QuickBooks' own trial balance for the period |
| 171 | + end and sets it beside the ledger's, account by account: balance-sheet accounts cumulatively, income |
| 172 | + and expense accounts from the start of the fiscal year. A difference there means the ledger's copy |
| 173 | + of the books has drifted from the source (a transaction deleted or back-dated there after it was |
| 174 | + synced, or activity not yet synced), so run it before trusting any other figure on a synced ledger; |
| 175 | + it needs a connected QuickBooks ledger. `schedule_register` compares each asset account a schedule |
| 176 | + carries a balance on (a prepaid, accumulated depreciation, a fixed-asset cost account) with what its |
| 177 | + schedules say it holds, and lists the schedules behind each figure. A difference there is a balance |
| 178 | + with no schedule behind it, or a scheduled amount the ledger does not hold. Each row carries both |
| 179 | + balances, the difference, and whether the account ties. |
| 180 | +
|
| 181 | + **Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours |
| 182 | + return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict. |
| 183 | +
|
| 184 | + Args: |
| 185 | + graph_id (str): |
| 186 | + idempotency_key (None | str | Unset): |
| 187 | + body (PreviewReconciliationsRequest): Compare the ledger's balances at a period end with |
| 188 | + an independent source. |
| 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 | OperationEnvelopeReconciliationPreviewResponse |
| 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: PreviewReconciliationsRequest, |
| 211 | + idempotency_key: None | str | Unset = UNSET, |
| 212 | +) -> Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse]: |
| 213 | + """Preview Reconciliations |
| 214 | +
|
| 215 | + Compare the ledger at a period end with something outside it, without recording anything. `method` |
| 216 | + picks the check. `source_ledger` (the default) reads QuickBooks' own trial balance for the period |
| 217 | + end and sets it beside the ledger's, account by account: balance-sheet accounts cumulatively, income |
| 218 | + and expense accounts from the start of the fiscal year. A difference there means the ledger's copy |
| 219 | + of the books has drifted from the source (a transaction deleted or back-dated there after it was |
| 220 | + synced, or activity not yet synced), so run it before trusting any other figure on a synced ledger; |
| 221 | + it needs a connected QuickBooks ledger. `schedule_register` compares each asset account a schedule |
| 222 | + carries a balance on (a prepaid, accumulated depreciation, a fixed-asset cost account) with what its |
| 223 | + schedules say it holds, and lists the schedules behind each figure. A difference there is a balance |
| 224 | + with no schedule behind it, or a scheduled amount the ledger does not hold. Each row carries both |
| 225 | + balances, the difference, and whether the account ties. |
| 226 | +
|
| 227 | + **Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours |
| 228 | + return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict. |
| 229 | +
|
| 230 | + Args: |
| 231 | + graph_id (str): |
| 232 | + idempotency_key (None | str | Unset): |
| 233 | + body (PreviewReconciliationsRequest): Compare the ledger's balances at a period end with |
| 234 | + an independent source. |
| 235 | +
|
| 236 | + Raises: |
| 237 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 238 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 239 | +
|
| 240 | + Returns: |
| 241 | + Response[ErrorResponse | OperationEnvelopeReconciliationPreviewResponse] |
| 242 | + """ |
| 243 | + |
| 244 | + kwargs = _get_kwargs( |
| 245 | + graph_id=graph_id, |
| 246 | + body=body, |
| 247 | + idempotency_key=idempotency_key, |
| 248 | + ) |
| 249 | + |
| 250 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 251 | + |
| 252 | + return _build_response(client=client, response=response) |
| 253 | + |
| 254 | + |
| 255 | +async def asyncio( |
| 256 | + graph_id: str, |
| 257 | + *, |
| 258 | + client: AuthenticatedClient, |
| 259 | + body: PreviewReconciliationsRequest, |
| 260 | + idempotency_key: None | str | Unset = UNSET, |
| 261 | +) -> ErrorResponse | OperationEnvelopeReconciliationPreviewResponse | None: |
| 262 | + """Preview Reconciliations |
| 263 | +
|
| 264 | + Compare the ledger at a period end with something outside it, without recording anything. `method` |
| 265 | + picks the check. `source_ledger` (the default) reads QuickBooks' own trial balance for the period |
| 266 | + end and sets it beside the ledger's, account by account: balance-sheet accounts cumulatively, income |
| 267 | + and expense accounts from the start of the fiscal year. A difference there means the ledger's copy |
| 268 | + of the books has drifted from the source (a transaction deleted or back-dated there after it was |
| 269 | + synced, or activity not yet synced), so run it before trusting any other figure on a synced ledger; |
| 270 | + it needs a connected QuickBooks ledger. `schedule_register` compares each asset account a schedule |
| 271 | + carries a balance on (a prepaid, accumulated depreciation, a fixed-asset cost account) with what its |
| 272 | + schedules say it holds, and lists the schedules behind each figure. A difference there is a balance |
| 273 | + with no schedule behind it, or a scheduled amount the ledger does not hold. Each row carries both |
| 274 | + balances, the difference, and whether the account ties. |
| 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 (PreviewReconciliationsRequest): Compare the ledger's balances at a period end with |
| 283 | + an independent source. |
| 284 | +
|
| 285 | + Raises: |
| 286 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 287 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 288 | +
|
| 289 | + Returns: |
| 290 | + ErrorResponse | OperationEnvelopeReconciliationPreviewResponse |
| 291 | + """ |
| 292 | + |
| 293 | + return ( |
| 294 | + await asyncio_detailed( |
| 295 | + graph_id=graph_id, |
| 296 | + client=client, |
| 297 | + body=body, |
| 298 | + idempotency_key=idempotency_key, |
| 299 | + ) |
| 300 | + ).parsed |
0 commit comments