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
Expand Up @@ -119,8 +119,7 @@ def sync_detailed(
Args:
graph_id (str):
idempotency_key (None | str | Unset):
body (EvaluateRulesRequest): Request body for the ``evaluate-rules`` operation (Phase
delta.3).
body (EvaluateRulesRequest): Request body for the ``evaluate-rules`` operation.

Runs every rule scoped to ``structure_id`` (plus element/association-
scoped rules for the structure's atoms), binds ``$Variable`` references
Expand Down Expand Up @@ -172,8 +171,7 @@ def sync(
Args:
graph_id (str):
idempotency_key (None | str | Unset):
body (EvaluateRulesRequest): Request body for the ``evaluate-rules`` operation (Phase
delta.3).
body (EvaluateRulesRequest): Request body for the ``evaluate-rules`` operation.

Runs every rule scoped to ``structure_id`` (plus element/association-
scoped rules for the structure's atoms), binds ``$Variable`` references
Expand Down Expand Up @@ -220,8 +218,7 @@ async def asyncio_detailed(
Args:
graph_id (str):
idempotency_key (None | str | Unset):
body (EvaluateRulesRequest): Request body for the ``evaluate-rules`` operation (Phase
delta.3).
body (EvaluateRulesRequest): Request body for the ``evaluate-rules`` operation.

Runs every rule scoped to ``structure_id`` (plus element/association-
scoped rules for the structure's atoms), binds ``$Variable`` references
Expand Down Expand Up @@ -271,8 +268,7 @@ async def asyncio(
Args:
graph_id (str):
idempotency_key (None | str | Unset):
body (EvaluateRulesRequest): Request body for the ``evaluate-rules`` operation (Phase
delta.3).
body (EvaluateRulesRequest): Request body for the ``evaluate-rules`` operation.

Runs every rule scoped to ``structure_id`` (plus element/association-
scoped rules for the structure's atoms), binds ``$Variable`` references
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def sync_detailed(

Top-level fields (name / description / version) apply to the taxonomy
row itself. The delta lists mutate atoms incrementally — the validator
(Phase 2.3) re-runs the seven-phase check across the projected post-
update state before anything commits.
re-runs every create-time check across the projected post-update
state before anything commits.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand Down Expand Up @@ -171,8 +171,8 @@ def sync(

Top-level fields (name / description / version) apply to the taxonomy
row itself. The delta lists mutate atoms incrementally — the validator
(Phase 2.3) re-runs the seven-phase check across the projected post-
update state before anything commits.
re-runs every create-time check across the projected post-update
state before anything commits.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand Down Expand Up @@ -214,8 +214,8 @@ async def asyncio_detailed(

Top-level fields (name / description / version) apply to the taxonomy
row itself. The delta lists mutate atoms incrementally — the validator
(Phase 2.3) re-runs the seven-phase check across the projected post-
update state before anything commits.
re-runs every create-time check across the projected post-update
state before anything commits.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand Down Expand Up @@ -260,8 +260,8 @@ async def asyncio(

Top-level fields (name / description / version) apply to the taxonomy
row itself. The delta lists mutate atoms incrementally — the validator
(Phase 2.3) re-runs the seven-phase check across the projected post-
update state before anything commits.
re-runs every create-time check across the projected post-update
state before anything commits.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand Down
40 changes: 39 additions & 1 deletion robosystems_client/clients/ledger_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
from ..models.create_event_block_request_event_category import (
CreateEventBlockRequestEventCategory,
)
from ..models.create_event_block_request_event_class import (
CreateEventBlockRequestEventClass,
)
from ..models.create_event_block_request_metadata import (
CreateEventBlockRequestMetadata,
)
Expand Down Expand Up @@ -360,6 +363,9 @@ def _build_event_block_request(
occurred_at: str,
metadata: dict[str, Any],
source: str = "native",
event_class: str = "economic",
obligated_by_event_id: str | None = None,
discharges_event_id: str | None = None,
) -> CreateEventBlockRequest:
"""Build a ``CreateEventBlockRequest`` for one of the registered handlers.

Expand All @@ -377,6 +383,13 @@ def _build_event_block_request(
occurred_at=occurred_dt,
apply_handlers=True,
metadata=CreateEventBlockRequestMetadata.from_dict(metadata),
event_class=CreateEventBlockRequestEventClass(event_class),
obligated_by_event_id=obligated_by_event_id
if obligated_by_event_id is not None
else UNSET,
discharges_event_id=discharges_event_id
if discharges_event_id is not None
else UNSET,
)

# ── Entity ──────────────────────────────────────────────────────────
Expand Down Expand Up @@ -1069,6 +1082,30 @@ def reverse_journal_entry(

# ── Event blocks (generic preview + status transitions) ──────────────

def create_event_block(
self,
graph_id: str,
body: dict[str, Any],
idempotency_key: str | None = None,
) -> dict[str, Any]:
"""Create an event block directly from a dict.

Use for support-class events (``event_class='support'``) with categories
``approval``, ``control``, ``reconciliation``, or ``inquiry``, which
are not covered by the specialized helpers. Economic events should
generally go through ``create_journal_entry``, ``create_closing_entry``,
etc., but this method works for those too.
"""
request = CreateEventBlockRequest.from_dict(body)
response = op_create_event_block(
graph_id=graph_id,
body=request,
client=self._get_client(),
idempotency_key=idempotency_key if idempotency_key is not None else UNSET,
)
envelope = self._call_op("Create event block", response)
return envelope.result or {}

def preview_event_block(
self,
graph_id: str,
Expand Down Expand Up @@ -1098,7 +1135,8 @@ def update_event_block(

Use for posting drafts (``classified`` → ``committed`` → ``fulfilled``),
voiding, superseding (correction chains), or patching ``description``,
``effective_at``, or ``metadata``.
``effective_at``, ``metadata``, ``obligated_by_event_id``, or
``discharges_event_id``.
"""
request = UpdateEventBlockRequest.from_dict(body)
response = op_update_event_block(
Expand Down
2 changes: 2 additions & 0 deletions robosystems_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from .create_event_block_request_event_category import (
CreateEventBlockRequestEventCategory,
)
from .create_event_block_request_event_class import CreateEventBlockRequestEventClass
from .create_event_block_request_metadata import CreateEventBlockRequestMetadata
from .create_event_block_request_resource_type_type_0 import (
CreateEventBlockRequestResourceTypeType0,
Expand Down Expand Up @@ -473,6 +474,7 @@
"CreateConnectionRequestProvider",
"CreateEventBlockRequest",
"CreateEventBlockRequestEventCategory",
"CreateEventBlockRequestEventClass",
"CreateEventBlockRequestMetadata",
"CreateEventBlockRequestResourceTypeType0",
"CreateEventHandlerRequest",
Expand Down
75 changes: 73 additions & 2 deletions robosystems_client/models/create_event_block_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from ..models.create_event_block_request_event_category import (
CreateEventBlockRequestEventCategory,
)
from ..models.create_event_block_request_event_class import (
CreateEventBlockRequestEventClass,
)
from ..models.create_event_block_request_resource_type_type_0 import (
CreateEventBlockRequestResourceTypeType0,
)
Expand All @@ -31,10 +34,15 @@ class CreateEventBlockRequest:

Attributes:
event_type (str): Open vocabulary: 'invoice_issued' | 'contract_signed' | 'bank_transaction' | ...
event_category (CreateEventBlockRequestEventCategory): REA economic classification. One of: sales, purchase,
financing, payroll, treasury, adjustment, recognition, other.
event_category (CreateEventBlockRequestEventCategory): REA classification. Economic categories (sales, purchase,
financing, payroll, treasury, adjustment, recognition, other) require event_class='economic'. Support categories
(control, approval, reconciliation, inquiry) require event_class='support'. The DB CHECK rejects mismatched
pairings.
occurred_at (datetime.datetime): When the event happened in the real world
source (str): 'quickbooks' | 'xero' | 'plaid' | 'native' | 'scheduled' | ...
event_class (CreateEventBlockRequestEventClass | Unset): REA event class. 'economic' events change resources and
drive GL postings; 'support' events are audit-trail / value-chain primitives (typically captured with
apply_handlers=False). Default: CreateEventBlockRequestEventClass.ECONOMIC.
agent_id (None | str | Unset): Counterparty agent id
resource_type (CreateEventBlockRequestResourceTypeType0 | None | Unset): REA resource kind. One of: goods,
services, money, right, obligation, information, labor.
Expand All @@ -48,6 +56,10 @@ class CreateEventBlockRequest:
description (None | str | Unset):
metadata (CreateEventBlockRequestMetadata | Unset): Event-type-specific payload
dimension_ids (list[str] | Unset):
obligated_by_event_id (None | str | Unset): Forward-materialization link: the event that scheduled or obligated
this one (e.g. depreciation entries point at the asset_acquired event).
discharges_event_id (None | str | Unset): Settlement link: the obligation this event discharges (e.g.
cash_received pointing at the originating sale_invoiced).
apply_handlers (bool | Unset): When True, resolves the event_type to a handler (Python registry first, then DSL)
and fires it atomically with event creation. Default: False.
"""
Expand All @@ -56,6 +68,9 @@ class CreateEventBlockRequest:
event_category: CreateEventBlockRequestEventCategory
occurred_at: datetime.datetime
source: str
event_class: CreateEventBlockRequestEventClass | Unset = (
CreateEventBlockRequestEventClass.ECONOMIC
)
agent_id: None | str | Unset = UNSET
resource_type: CreateEventBlockRequestResourceTypeType0 | None | Unset = UNSET
resource_element_id: None | str | Unset = UNSET
Expand All @@ -67,6 +82,8 @@ class CreateEventBlockRequest:
description: None | str | Unset = UNSET
metadata: CreateEventBlockRequestMetadata | Unset = UNSET
dimension_ids: list[str] | Unset = UNSET
obligated_by_event_id: None | str | Unset = UNSET
discharges_event_id: None | str | Unset = UNSET
apply_handlers: bool | Unset = False
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

Expand All @@ -79,6 +96,10 @@ def to_dict(self) -> dict[str, Any]:

source = self.source

event_class: str | Unset = UNSET
if not isinstance(self.event_class, Unset):
event_class = self.event_class.value

agent_id: None | str | Unset
if isinstance(self.agent_id, Unset):
agent_id = UNSET
Expand Down Expand Up @@ -141,6 +162,18 @@ def to_dict(self) -> dict[str, Any]:
if not isinstance(self.dimension_ids, Unset):
dimension_ids = self.dimension_ids

obligated_by_event_id: None | str | Unset
if isinstance(self.obligated_by_event_id, Unset):
obligated_by_event_id = UNSET
else:
obligated_by_event_id = self.obligated_by_event_id

discharges_event_id: None | str | Unset
if isinstance(self.discharges_event_id, Unset):
discharges_event_id = UNSET
else:
discharges_event_id = self.discharges_event_id

apply_handlers = self.apply_handlers

field_dict: dict[str, Any] = {}
Expand All @@ -153,6 +186,8 @@ def to_dict(self) -> dict[str, Any]:
"source": source,
}
)
if event_class is not UNSET:
field_dict["event_class"] = event_class
if agent_id is not UNSET:
field_dict["agent_id"] = agent_id
if resource_type is not UNSET:
Expand All @@ -175,6 +210,10 @@ def to_dict(self) -> dict[str, Any]:
field_dict["metadata"] = metadata
if dimension_ids is not UNSET:
field_dict["dimension_ids"] = dimension_ids
if obligated_by_event_id is not UNSET:
field_dict["obligated_by_event_id"] = obligated_by_event_id
if discharges_event_id is not UNSET:
field_dict["discharges_event_id"] = discharges_event_id
if apply_handlers is not UNSET:
field_dict["apply_handlers"] = apply_handlers

Expand All @@ -195,6 +234,13 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:

source = d.pop("source")

_event_class = d.pop("event_class", UNSET)
event_class: CreateEventBlockRequestEventClass | Unset
if isinstance(_event_class, Unset):
event_class = UNSET
else:
event_class = CreateEventBlockRequestEventClass(_event_class)

def _parse_agent_id(data: object) -> None | str | Unset:
if data is None:
return data
Expand Down Expand Up @@ -298,13 +344,36 @@ def _parse_description(data: object) -> None | str | Unset:

dimension_ids = cast(list[str], d.pop("dimension_ids", UNSET))

def _parse_obligated_by_event_id(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)

obligated_by_event_id = _parse_obligated_by_event_id(
d.pop("obligated_by_event_id", UNSET)
)

def _parse_discharges_event_id(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)

discharges_event_id = _parse_discharges_event_id(
d.pop("discharges_event_id", UNSET)
)

apply_handlers = d.pop("apply_handlers", UNSET)

create_event_block_request = cls(
event_type=event_type,
event_category=event_category,
occurred_at=occurred_at,
source=source,
event_class=event_class,
agent_id=agent_id,
resource_type=resource_type,
resource_element_id=resource_element_id,
Expand All @@ -316,6 +385,8 @@ def _parse_description(data: object) -> None | str | Unset:
description=description,
metadata=metadata,
dimension_ids=dimension_ids,
obligated_by_event_id=obligated_by_event_id,
discharges_event_id=discharges_event_id,
apply_handlers=apply_handlers,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

class CreateEventBlockRequestEventCategory(str, Enum):
ADJUSTMENT = "adjustment"
APPROVAL = "approval"
CONTROL = "control"
FINANCING = "financing"
INQUIRY = "inquiry"
OTHER = "other"
PAYROLL = "payroll"
PURCHASE = "purchase"
RECOGNITION = "recognition"
RECONCILIATION = "reconciliation"
SALES = "sales"
TREASURY = "treasury"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from enum import Enum


class CreateEventBlockRequestEventClass(str, Enum):
ECONOMIC = "economic"
SUPPORT = "support"

def __str__(self) -> str:
return str(self.value)
Loading
Loading