Skip to content

Commit 34ff61c

Browse files
committed
feat: reconciling items, the obligation sweep and the close overrides on the ledger facade
Matches the TypeScript client's 2.5.0 facade, so an integrator can clear or pass the close blockers the calendar names. - list_event_blocks takes is_reconciling_item - preview_reconciling_item, resolve_reconciling_item, promote_obligations - close_period sends allow_stranded_obligations, allow_reconciling_items and allow_unposted_source_events beside the two it already sent - the fiscal calendar carries the unposted-source-event count and sample Additive: new parameters are appended and default to unset.
1 parent be67d44 commit 34ff61c

7 files changed

Lines changed: 267 additions & 13 deletions

File tree

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 135 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
from ..api.robo_ledger_fiscal_close.close_period import (
4343
sync_detailed as op_close_period,
4444
)
45+
from ..api.robo_ledger_fiscal_close.promote_obligations import (
46+
sync_detailed as op_promote_obligations,
47+
)
48+
from ..api.robo_ledger_ledger_events.preview_reconciling_item import (
49+
sync_detailed as op_preview_reconciling_item,
50+
)
51+
from ..api.robo_ledger_ledger_events.resolve_reconciling_item import (
52+
sync_detailed as op_resolve_reconciling_item,
53+
)
4554
from ..api.robo_ledger_ledger_events.preview_reconciliations import (
4655
sync_detailed as op_preview_reconciliations,
4756
)
@@ -504,6 +513,18 @@
504513
from ..models.reconciliation_summary import ReconciliationSummary
505514
from ..models.record_statement_balance_request import RecordStatementBalanceRequest
506515
from ..models.refresh_reconciliations_request import RefreshReconciliationsRequest
516+
from ..models.preview_reconciling_item_request import PreviewReconcilingItemRequest
517+
from ..models.promote_obligations_request import PromoteObligationsRequest
518+
from ..models.promote_obligations_response import PromoteObligationsResponse
519+
from ..models.reconciling_item_plan import ReconcilingItemPlan
520+
from ..models.resolve_reconciling_item_request import ResolveReconcilingItemRequest
521+
from ..models.resolve_reconciling_item_request_disposition_type_0 import (
522+
ResolveReconcilingItemRequestDispositionType0,
523+
)
524+
from ..models.resolve_reconciling_item_request_status import (
525+
ResolveReconcilingItemRequestStatus,
526+
)
527+
from ..models.resolve_reconciling_item_response import ResolveReconcilingItemResponse
507528
from ..models.set_reconciliation_policy_request import SetReconciliationPolicyRequest
508529
from ..models.sign_off_reconciliation_request import SignOffReconciliationRequest
509530
from ..models.compute_metrics_request import ComputeMetricsRequest
@@ -579,7 +600,7 @@
579600
from ..models.revoke_report_share_response import RevokeReportShareResponse
580601
from ..models.taxonomy_block_envelope import TaxonomyBlockEnvelope
581602

582-
from ..types import UNSET
603+
from ..types import UNSET, Unset
583604

584605

585606
# Captures the ``filename`` value from a Content-Disposition header, with
@@ -988,8 +1009,13 @@ def list_event_blocks(
9881009
source: str | None = None,
9891010
limit: int = 50,
9901011
offset: int = 0,
1012+
is_reconciling_item: bool | None = None,
9911013
) -> list[ListLedgerEventBlocksEventBlocks]:
992-
"""List captured event blocks (inbox surface)."""
1014+
"""List captured event blocks (inbox surface).
1015+
1016+
``is_reconciling_item=True`` narrows to posted events whose source
1017+
payload changed afterwards and that await a decision.
1018+
"""
9931019
data = self._query(
9941020
graph_id,
9951021
LIST_LEDGER_EVENT_BLOCKS_GQL,
@@ -999,6 +1025,7 @@ def list_event_blocks(
9991025
"status": status,
10001026
"agentId": agent_id,
10011027
"source": source,
1028+
"isReconcilingItem": is_reconciling_item,
10021029
"limit": limit,
10031030
"offset": offset,
10041031
},
@@ -2173,23 +2200,36 @@ def close_period(
21732200
note: str | None = None,
21742201
allow_stale_sync: bool | None = None,
21752202
allow_unreconciled_accounts: bool | None = None,
2203+
allow_stranded_obligations: bool | None = None,
2204+
allow_reconciling_items: bool | None = None,
2205+
allow_unposted_source_events: bool | None = None,
21762206
) -> ClosePeriodResponse:
21772207
"""Close a fiscal period — the final commit action.
21782208
2179-
``allow_unreconciled_accounts`` closes despite a reconciliation the
2180-
close waits on that is not reconciled for the period. Prefer
2181-
`refresh_reconciliations` and clearing what it reports; the override is
2182-
recorded in the close audit note.
2209+
Each ``allow_*`` flag closes despite one blocker and is recorded in the
2210+
close audit note; prefer clearing the blocker.
2211+
2212+
- ``allow_unreconciled_accounts``: a reconciliation the close waits on
2213+
is not reconciled for the period (`refresh_reconciliations`).
2214+
- ``allow_stranded_obligations``: matured obligations that were never
2215+
drafted (`promote_obligations`).
2216+
- ``allow_reconciling_items``: posted events whose source payload
2217+
changed afterwards (`resolve_reconciling_item`).
2218+
- ``allow_unposted_source_events``: source events dated in the period
2219+
that were never committed, and cannot post into it once it closes.
21832220
"""
2221+
2222+
def flag(value: bool | None) -> bool | Unset:
2223+
return value if value is not None else UNSET
2224+
21842225
body = ClosePeriodOperation(
21852226
period=period,
21862227
note=note if note is not None else UNSET,
2187-
allow_stale_sync=(allow_stale_sync if allow_stale_sync is not None else UNSET),
2188-
allow_unreconciled_accounts=(
2189-
allow_unreconciled_accounts
2190-
if allow_unreconciled_accounts is not None
2191-
else UNSET
2192-
),
2228+
allow_stale_sync=flag(allow_stale_sync),
2229+
allow_unreconciled_accounts=flag(allow_unreconciled_accounts),
2230+
allow_stranded_obligations=flag(allow_stranded_obligations),
2231+
allow_reconciling_items=flag(allow_reconciling_items),
2232+
allow_unposted_source_events=flag(allow_unposted_source_events),
21932233
)
21942234
response = op_close_period(graph_id=graph_id, body=body, client=self._get_client())
21952235
envelope = self._call_op("Close period", response)
@@ -2212,6 +2252,89 @@ def reopen_period(
22122252
envelope = self._call_op("Reopen period", response)
22132253
return self._typed_result("Reopen period", envelope, FiscalCalendarResponse)
22142254

2255+
def promote_obligations(
2256+
self, graph_id: str, *, dispatch_handlers: bool | None = None
2257+
) -> PromoteObligationsResponse:
2258+
"""Draft the closing entry of every matured schedule obligation,
2259+
including ones promoted earlier and never drafted. The drafts post when
2260+
the period closes. Safe to repeat.
2261+
2262+
``dispatch_handlers=False`` only flips the status and drafts nothing,
2263+
which leaves the obligations stranded; the server default drafts.
2264+
"""
2265+
body = PromoteObligationsRequest(
2266+
dispatch_handlers=(dispatch_handlers if dispatch_handlers is not None else UNSET)
2267+
)
2268+
response = op_promote_obligations(
2269+
graph_id=graph_id, body=body, client=self._get_client()
2270+
)
2271+
envelope = self._call_op("Promote obligations", response)
2272+
return self._typed_result(
2273+
"Promote obligations", envelope, PromoteObligationsResponse
2274+
)
2275+
2276+
# ── Reconciling items ───────────────────────────────────────────────
2277+
2278+
def preview_reconciling_item(
2279+
self, graph_id: str, event_id: str
2280+
) -> ReconcilingItemPlan:
2281+
"""What changed on a reconciling item (a posted event whose source
2282+
payload changed afterwards) and what each treatment would do. Writes
2283+
nothing. List the items with ``list_event_blocks(is_reconciling_item=True)``.
2284+
"""
2285+
body = PreviewReconcilingItemRequest(event_id=event_id)
2286+
response = op_preview_reconciling_item(
2287+
graph_id=graph_id, body=body, client=self._get_client()
2288+
)
2289+
envelope = self._call_op("Preview reconciling item", response)
2290+
return self._typed_result("Preview reconciling item", envelope, ReconcilingItemPlan)
2291+
2292+
def resolve_reconciling_item(
2293+
self,
2294+
graph_id: str,
2295+
event_id: str,
2296+
*,
2297+
disposition: str | None = None,
2298+
posting_date: str | datetime.date | None = None,
2299+
status: str | None = None,
2300+
note: str | None = None,
2301+
reference_event_id: str | None = None,
2302+
) -> ResolveReconcilingItemResponse:
2303+
"""Decide one reconciling item.
2304+
2305+
``disposition`` is ``restate`` (rebuild the affected months),
2306+
``catch_up`` (an entry in the open period) or ``acknowledge`` (handled
2307+
elsewhere; ``note`` is required). Omit it to take the default the
2308+
preview reports. ``posting_date`` and ``status`` (``draft`` or
2309+
``posted``) apply to ``catch_up`` only; ``reference_event_id`` to
2310+
``acknowledge`` only.
2311+
"""
2312+
if isinstance(posting_date, str):
2313+
posting_date = datetime.date.fromisoformat(posting_date)
2314+
body = ResolveReconcilingItemRequest(
2315+
event_id=event_id,
2316+
disposition=(
2317+
ResolveReconcilingItemRequestDispositionType0(disposition)
2318+
if disposition is not None
2319+
else UNSET
2320+
),
2321+
posting_date=posting_date if posting_date is not None else UNSET,
2322+
status=(
2323+
ResolveReconcilingItemRequestStatus(status) if status is not None else UNSET
2324+
),
2325+
note=note if note is not None else UNSET,
2326+
reference_event_id=(
2327+
reference_event_id if reference_event_id is not None else UNSET
2328+
),
2329+
)
2330+
response = op_resolve_reconciling_item(
2331+
graph_id=graph_id, body=body, client=self._get_client()
2332+
)
2333+
envelope = self._call_op("Resolve reconciling item", response)
2334+
return self._typed_result(
2335+
"Resolve reconciling item", envelope, ResolveReconcilingItemResponse
2336+
)
2337+
22152338
# ── Reconciliations ─────────────────────────────────────────────────
22162339

22172340
def list_reconciliations(

‎robosystems_client/graphql/generated/client.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ def list_ledger_event_blocks(
695695
status: Union[Optional[str], UnsetType] = UNSET,
696696
agent_id: Union[Optional[str], UnsetType] = UNSET,
697697
source: Union[Optional[str], UnsetType] = UNSET,
698+
is_reconciling_item: Union[Optional[bool], UnsetType] = UNSET,
698699
**kwargs: Any,
699700
) -> ListLedgerEventBlocks:
700701
variables: dict[str, object] = {
@@ -703,6 +704,7 @@ def list_ledger_event_blocks(
703704
"status": status,
704705
"agentId": agent_id,
705706
"source": source,
707+
"isReconcilingItem": is_reconciling_item,
706708
"limit": limit,
707709
"offset": offset,
708710
}

‎robosystems_client/graphql/generated/get_ledger_fiscal_calendar.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class GetLedgerFiscalCalendarFiscalCalendar(BaseModel):
3131
] = Field(alias="strandedObligationSample")
3232
reconciling_item_count: int = Field(alias="reconcilingItemCount")
3333
reconciling_item_sample: list[str] = Field(alias="reconcilingItemSample")
34+
unposted_source_event_count: int = Field(alias="unpostedSourceEventCount")
35+
unposted_source_event_sample: list[str] = Field(alias="unpostedSourceEventSample")
3436
unreconciled_account_count: int = Field(alias="unreconciledAccountCount")
3537
unreconciled_account_sample: list[str] = Field(alias="unreconciledAccountSample")
3638
sync_stale_days: Optional[int] = Field(alias="syncStaleDays")

‎robosystems_client/graphql/generated/operations.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@
654654
}
655655
reconcilingItemCount
656656
reconcilingItemSample
657+
unpostedSourceEventCount
658+
unpostedSourceEventSample
657659
unreconciledAccountCount
658660
unreconciledAccountSample
659661
syncStaleDays
@@ -1469,13 +1471,14 @@
14691471
"""
14701472

14711473
LIST_LEDGER_EVENT_BLOCKS_GQL = """
1472-
query ListLedgerEventBlocks($eventType: String, $eventCategory: String, $status: String, $agentId: String, $source: String, $limit: Int! = 50, $offset: Int! = 0) {
1474+
query ListLedgerEventBlocks($eventType: String, $eventCategory: String, $status: String, $agentId: String, $source: String, $isReconcilingItem: Boolean, $limit: Int! = 50, $offset: Int! = 0) {
14731475
eventBlocks(
14741476
eventType: $eventType
14751477
eventCategory: $eventCategory
14761478
status: $status
14771479
agentId: $agentId
14781480
source: $source
1481+
isReconcilingItem: $isReconcilingItem
14791482
limit: $limit
14801483
offset: $offset
14811484
) {

‎robosystems_client/graphql/operations/ledger/GetLedgerFiscalCalendar.graphql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ query GetLedgerFiscalCalendar {
88
strandedObligationCount
99
strandedObligationSample { eventId scheduleId scheduleName period }
1010
reconcilingItemCount reconcilingItemSample
11+
unpostedSourceEventCount unpostedSourceEventSample
1112
unreconciledAccountCount unreconciledAccountSample
1213
syncStaleDays
1314
lastCloseAt initializedAt lastSyncAt

‎robosystems_client/graphql/operations/ledger/ListLedgerEventBlocks.graphql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ query ListLedgerEventBlocks(
44
$status: String
55
$agentId: String
66
$source: String
7+
$isReconcilingItem: Boolean
78
$limit: Int! = 50
89
$offset: Int! = 0
910
) {
@@ -13,6 +14,7 @@ query ListLedgerEventBlocks(
1314
status: $status
1415
agentId: $agentId
1516
source: $source
17+
isReconcilingItem: $isReconcilingItem
1618
limit: $limit
1719
offset: $offset
1820
) {

0 commit comments

Comments
 (0)