Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
from http import HTTPStatus
from typing import Any
from urllib.parse import quote

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.error_response import ErrorResponse
from ...models.learn_classification_defaults_request import (
LearnClassificationDefaultsRequest,
)
from ...models.operation_envelope_learn_classification_defaults_response import (
OperationEnvelopeLearnClassificationDefaultsResponse,
)
from ...types import UNSET, Response, Unset


def _get_kwargs(
graph_id: str,
*,
body: LearnClassificationDefaultsRequest,
idempotency_key: None | str | Unset = UNSET,
) -> dict[str, Any]:
headers: dict[str, Any] = {}
if not isinstance(idempotency_key, Unset):
headers["Idempotency-Key"] = idempotency_key

_kwargs: dict[str, Any] = {
"method": "post",
"url": "/extensions/roboledger/{graph_id}/operations/learn-classification-defaults".format(
graph_id=quote(str(graph_id), safe=""),
),
}

_kwargs["json"] = body.to_dict()

headers["Content-Type"] = "application/json"

_kwargs["headers"] = headers
return _kwargs


def _parse_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse | None:
if response.status_code == 200:
response_200 = OperationEnvelopeLearnClassificationDefaultsResponse.from_dict(
response.json()
)

return response_200

if response.status_code == 400:
response_400 = ErrorResponse.from_dict(response.json())

return response_400

if response.status_code == 401:
response_401 = ErrorResponse.from_dict(response.json())

return response_401

if response.status_code == 403:
response_403 = ErrorResponse.from_dict(response.json())

return response_403

if response.status_code == 404:
response_404 = ErrorResponse.from_dict(response.json())

return response_404

if response.status_code == 409:
response_409 = ErrorResponse.from_dict(response.json())

return response_409

if response.status_code == 422:
response_422 = ErrorResponse.from_dict(response.json())

return response_422

if response.status_code == 429:
response_429 = ErrorResponse.from_dict(response.json())

return response_429

if response.status_code == 500:
response_500 = ErrorResponse.from_dict(response.json())

return response_500

if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
graph_id: str,
*,
client: AuthenticatedClient,
body: LearnClassificationDefaultsRequest,
idempotency_key: None | str | Unset = UNSET,
) -> Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]:
"""Learn Classification Defaults

Seed each counterparty's default account from the bank lines already committed to the books: the
account most of its lines went to becomes its default, with the lines that agreed counted as
confirmations. A counterparty that already has a default keeps it. Its still-open lines are then
suggested from the default. Run it once on books that were classified before defaults were learned;
after that, every commit teaches the default by itself. `dry_run` reports what would be learned
without writing it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.

Args:
graph_id (str):
idempotency_key (None | str | Unset):
body (LearnClassificationDefaultsRequest): Seed counterparty defaults from the bank lines
already committed.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]
"""

kwargs = _get_kwargs(
graph_id=graph_id,
body=body,
idempotency_key=idempotency_key,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
graph_id: str,
*,
client: AuthenticatedClient,
body: LearnClassificationDefaultsRequest,
idempotency_key: None | str | Unset = UNSET,
) -> ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse | None:
"""Learn Classification Defaults

Seed each counterparty's default account from the bank lines already committed to the books: the
account most of its lines went to becomes its default, with the lines that agreed counted as
confirmations. A counterparty that already has a default keeps it. Its still-open lines are then
suggested from the default. Run it once on books that were classified before defaults were learned;
after that, every commit teaches the default by itself. `dry_run` reports what would be learned
without writing it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.

Args:
graph_id (str):
idempotency_key (None | str | Unset):
body (LearnClassificationDefaultsRequest): Seed counterparty defaults from the bank lines
already committed.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse
"""

return sync_detailed(
graph_id=graph_id,
client=client,
body=body,
idempotency_key=idempotency_key,
).parsed


async def asyncio_detailed(
graph_id: str,
*,
client: AuthenticatedClient,
body: LearnClassificationDefaultsRequest,
idempotency_key: None | str | Unset = UNSET,
) -> Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]:
"""Learn Classification Defaults

Seed each counterparty's default account from the bank lines already committed to the books: the
account most of its lines went to becomes its default, with the lines that agreed counted as
confirmations. A counterparty that already has a default keeps it. Its still-open lines are then
suggested from the default. Run it once on books that were classified before defaults were learned;
after that, every commit teaches the default by itself. `dry_run` reports what would be learned
without writing it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.

Args:
graph_id (str):
idempotency_key (None | str | Unset):
body (LearnClassificationDefaultsRequest): Seed counterparty defaults from the bank lines
already committed.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse]
"""

kwargs = _get_kwargs(
graph_id=graph_id,
body=body,
idempotency_key=idempotency_key,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
graph_id: str,
*,
client: AuthenticatedClient,
body: LearnClassificationDefaultsRequest,
idempotency_key: None | str | Unset = UNSET,
) -> ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse | None:
"""Learn Classification Defaults

Seed each counterparty's default account from the bank lines already committed to the books: the
account most of its lines went to becomes its default, with the lines that agreed counted as
confirmations. A counterparty that already has a default keeps it. Its still-open lines are then
suggested from the default. Run it once on books that were classified before defaults were learned;
after that, every commit teaches the default by itself. `dry_run` reports what would be learned
without writing it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.

Args:
graph_id (str):
idempotency_key (None | str | Unset):
body (LearnClassificationDefaultsRequest): Seed counterparty defaults from the bank lines
already committed.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
ErrorResponse | OperationEnvelopeLearnClassificationDefaultsResponse
"""

return (
await asyncio_detailed(
graph_id=graph_id,
client=client,
body=body,
idempotency_key=idempotency_key,
)
).parsed
16 changes: 16 additions & 0 deletions robosystems_client/api/robo_ledger_ledger_events/update_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def sync_detailed(

Patch counterparty fields. Only supplied fields are updated. Set is_active=false to deactivate
(agents are never deleted — they are reference data referenced by events and transactions).
`classification_element_id` sets the account this counterparty's bank lines are suggested (an empty
string clears it), and `classification_mode='always_ask'` stops suggesting one for a counterparty
whose lines go to different accounts; its still-open lines are re-suggested at once. A default is
also learned as lines are committed, so set one by hand only to correct it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
Expand Down Expand Up @@ -158,6 +162,10 @@ def sync(

Patch counterparty fields. Only supplied fields are updated. Set is_active=false to deactivate
(agents are never deleted — they are reference data referenced by events and transactions).
`classification_element_id` sets the account this counterparty's bank lines are suggested (an empty
string clears it), and `classification_mode='always_ask'` stops suggesting one for a counterparty
whose lines go to different accounts; its still-open lines are re-suggested at once. A default is
also learned as lines are committed, so set one by hand only to correct it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
Expand Down Expand Up @@ -196,6 +204,10 @@ async def asyncio_detailed(

Patch counterparty fields. Only supplied fields are updated. Set is_active=false to deactivate
(agents are never deleted — they are reference data referenced by events and transactions).
`classification_element_id` sets the account this counterparty's bank lines are suggested (an empty
string clears it), and `classification_mode='always_ask'` stops suggesting one for a counterparty
whose lines go to different accounts; its still-open lines are re-suggested at once. A default is
also learned as lines are committed, so set one by hand only to correct it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
Expand Down Expand Up @@ -237,6 +249,10 @@ async def asyncio(

Patch counterparty fields. Only supplied fields are updated. Set is_active=false to deactivate
(agents are never deleted — they are reference data referenced by events and transactions).
`classification_element_id` sets the account this counterparty's bank lines are suggested (an empty
string clears it), and `classification_mode='always_ask'` stops suggesting one for a counterparty
whose lines go to different accounts; its still-open lines are re-suggested at once. A default is
also learned as lines are committed, so set one by hand only to correct it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ def sync_detailed(
captured metadata to produce the GL rows, unless it already wrote them when the event was created; a
bank-feed line with no account chosen and no matching rule is refused. Errors from the handler
(validation, element resolution, closed period, unbalanced lines) surface as 422 here so the inbox
UI can display the failure reason without retry.
UI can display the failure reason without retry. A bank line's flow is a second classification
beside its account, overriding the account's default flow on the cash flow and equity statements:
patch `classified_flow_qname` (or `flow_qname` on each `classified_allocations` part) with an rs-
gaap flow concept such as `rs-gaap:ProceedsFromIssuanceOfLongTermDebt`. On a line that has already
posted, this re-tags its lines in place, in a closed month too, since no balance moves; an empty
string clears it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
Expand Down Expand Up @@ -172,7 +177,12 @@ def sync(
captured metadata to produce the GL rows, unless it already wrote them when the event was created; a
bank-feed line with no account chosen and no matching rule is refused. Errors from the handler
(validation, element resolution, closed period, unbalanced lines) surface as 422 here so the inbox
UI can display the failure reason without retry.
UI can display the failure reason without retry. A bank line's flow is a second classification
beside its account, overriding the account's default flow on the cash flow and equity statements:
patch `classified_flow_qname` (or `flow_qname` on each `classified_allocations` part) with an rs-
gaap flow concept such as `rs-gaap:ProceedsFromIssuanceOfLongTermDebt`. On a line that has already
posted, this re-tags its lines in place, in a closed month too, since no balance moves; an empty
string clears it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
Expand Down Expand Up @@ -218,7 +228,12 @@ async def asyncio_detailed(
captured metadata to produce the GL rows, unless it already wrote them when the event was created; a
bank-feed line with no account chosen and no matching rule is refused. Errors from the handler
(validation, element resolution, closed period, unbalanced lines) surface as 422 here so the inbox
UI can display the failure reason without retry.
UI can display the failure reason without retry. A bank line's flow is a second classification
beside its account, overriding the account's default flow on the cash flow and equity statements:
patch `classified_flow_qname` (or `flow_qname` on each `classified_allocations` part) with an rs-
gaap flow concept such as `rs-gaap:ProceedsFromIssuanceOfLongTermDebt`. On a line that has already
posted, this re-tags its lines in place, in a closed month too, since no balance moves; an empty
string clears it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
Expand Down Expand Up @@ -267,7 +282,12 @@ async def asyncio(
captured metadata to produce the GL rows, unless it already wrote them when the event was created; a
bank-feed line with no account chosen and no matching rule is refused. Errors from the handler
(validation, element resolution, closed period, unbalanced lines) surface as 422 here so the inbox
UI can display the failure reason without retry.
UI can display the failure reason without retry. A bank line's flow is a second classification
beside its account, overriding the account's default flow on the cash flow and equity statements:
patch `classified_flow_qname` (or `flow_qname` on each `classified_allocations` part) with an rs-
gaap flow concept such as `rs-gaap:ProceedsFromIssuanceOfLongTermDebt`. On a line that has already
posted, this re-tags its lines in place, in a closed month too, since no balance moves; an empty
string clears it.

**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
Expand Down
Loading
Loading