Skip to content

Commit 892f339

Browse files
committed
feat(ledger): scope reconciliation calls to an entity; move a calendar's start
record_statement_balance, preview_reconciliations and refresh_reconciliations take an entity_id, so a subsidiary's statement and checks run on its own books rather than the group parent's. change_calendar_start moves an entity's first open month before its first close. Parity with the TypeScript facade. Claude-Session: https://claude.ai/code/session_01AQkGGPDmpba9eBV9PkLTfv
1 parent f1f81b6 commit 892f339

2 files changed

Lines changed: 92 additions & 5 deletions

File tree

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
from ..api.robo_ledger_fiscal_close.set_close_target import (
118118
sync_detailed as op_set_close_target,
119119
)
120+
from ..api.robo_ledger_setup.change_calendar_start import (
121+
sync_detailed as op_change_calendar_start,
122+
)
120123
from ..api.robo_ledger_taxonomy_mapping.create_taxonomy_block import (
121124
sync_detailed as op_create_taxonomy_block,
122125
)
@@ -579,6 +582,8 @@
579582
from ..models.update_publish_list_operation import UpdatePublishListOperation
580583
from ..models.reopen_period_operation import ReopenPeriodOperation
581584
from ..models.set_close_target_operation import SetCloseTargetOperation
585+
from ..models.change_calendar_start_request import ChangeCalendarStartRequest
586+
from ..models.change_calendar_start_response import ChangeCalendarStartResponse
582587
from ..models.bind_text_block_request import BindTextBlockRequest
583588
from ..models.bind_text_block_response import BindTextBlockResponse
584589
from ..models.create_taxonomy_block_request import CreateTaxonomyBlockRequest
@@ -2345,6 +2350,30 @@ def set_close_target(
23452350
envelope = self._call_op("Set close target", response)
23462351
return self._typed_result("Set close target", envelope, FiscalCalendarResponse)
23472352

2353+
def change_calendar_start(
2354+
self,
2355+
graph_id: str,
2356+
first_open_period: str,
2357+
note: str | None = None,
2358+
*,
2359+
entity_id: str | None = None,
2360+
) -> ChangeCalendarStartResponse:
2361+
"""Move the calendar's first open month (YYYY-MM), allowed only until the
2362+
entity's first close. Earlier opens months back to it; later removes the
2363+
leading months, refused while they hold any entry."""
2364+
body = ChangeCalendarStartRequest(
2365+
first_open_period=first_open_period,
2366+
note=note if note is not None else UNSET,
2367+
entity_id=entity_id if entity_id is not None else UNSET,
2368+
)
2369+
response = op_change_calendar_start(
2370+
graph_id=graph_id, body=body, client=self._get_client()
2371+
)
2372+
envelope = self._call_op("Change calendar start", response)
2373+
return self._typed_result(
2374+
"Change calendar start", envelope, ChangeCalendarStartResponse
2375+
)
2376+
23482377
def close_period(
23492378
self,
23502379
graph_id: str,
@@ -2530,19 +2559,22 @@ def preview_reconciliations(
25302559
*,
25312560
method: PreviewReconciliationsRequestMethod | str | None = None,
25322561
include_tied: bool | None = None,
2562+
entity_id: str | None = None,
25332563
) -> ReconciliationPreviewResponse:
25342564
"""Compare the ledger with something outside it. Records nothing.
25352565
25362566
``method`` picks the check: ``source_ledger`` (the default, which needs a
25372567
connected QuickBooks ledger), ``schedule_register`` or ``statement``.
2538-
``include_tied`` also returns the accounts that tie.
2568+
``include_tied`` also returns the accounts that tie. ``entity_id`` checks
2569+
a subsidiary's books; omitted, the group parent's.
25392570
"""
25402571
body = PreviewReconciliationsRequest(
25412572
period=period,
25422573
method=(
25432574
PreviewReconciliationsRequestMethod(method) if method is not None else UNSET
25442575
),
25452576
include_tied=include_tied if include_tied is not None else UNSET,
2577+
entity_id=entity_id if entity_id is not None else UNSET,
25462578
)
25472579
response = op_preview_reconciliations(
25482580
graph_id=graph_id, body=body, client=self._get_client()
@@ -2553,11 +2585,14 @@ def preview_reconciliations(
25532585
)
25542586

25552587
def refresh_reconciliations(
2556-
self, graph_id: str, period: str
2588+
self, graph_id: str, period: str, *, entity_id: str | None = None
25572589
) -> ReconciliationListResponse:
25582590
"""Run every reconciliation that applies at a period end and record each
2559-
result on its block. ``notes`` names any check that could not run."""
2560-
body = RefreshReconciliationsRequest(period=period)
2591+
result on its block. ``notes`` names any check that could not run.
2592+
``entity_id`` runs a subsidiary's; omitted, the group parent's."""
2593+
body = RefreshReconciliationsRequest(
2594+
period=period, entity_id=entity_id if entity_id is not None else UNSET
2595+
)
25612596
response = op_refresh_reconciliations(
25622597
graph_id=graph_id, body=body, client=self._get_client()
25632598
)
@@ -2575,6 +2610,7 @@ def record_statement_balance(
25752610
balance: float,
25762611
document_id: str | None = None,
25772612
note: str | None = None,
2613+
entity_id: str | None = None,
25782614
) -> ReconciliationSummary:
25792615
"""Record a statement's ending balance for a balance-sheet account and
25802616
reconcile the account to it for the period the statement ends in.
@@ -2583,10 +2619,12 @@ def record_statement_balance(
25832619
account's normal direction (money in a bank account, or the amount owed
25842620
on a loan or a card). ``as_of`` is the statement's ending date.
25852621
``document_id`` names the statement itself, as a document already on
2586-
the graph. Writes no books.
2622+
the graph. ``entity_id`` names the subsidiary whose account it is;
2623+
omitted, the group parent. Writes no books.
25872624
"""
25882625
body = RecordStatementBalanceRequest(
25892626
element_id=element_id,
2627+
entity_id=entity_id if entity_id is not None else UNSET,
25902628
as_of=datetime.date.fromisoformat(as_of) if isinstance(as_of, str) else as_of,
25912629
balance=balance,
25922630
document_id=document_id if document_id is not None else UNSET,

‎tests/test_ledger_client.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,6 +3207,55 @@ def test_set_close_target_sends_entity_id(self, mock_op, mock_config, graph_id):
32073207
"entity_id": "ent_2",
32083208
}
32093209

3210+
@patch("robosystems_client.clients.ledger_client.op_change_calendar_start")
3211+
def test_change_calendar_start(self, mock_op, mock_config, graph_id):
3212+
mock_op.return_value = _mock_response(
3213+
_envelope(
3214+
"change-calendar-start",
3215+
{"fiscal_calendar": {}, "periods_created": 7, "periods_removed": 0},
3216+
)
3217+
)
3218+
client = LedgerClient(mock_config)
3219+
result = client.change_calendar_start(
3220+
graph_id, "2026-02", "history from February", entity_id="ent_2"
3221+
)
3222+
assert result["periods_created"] == 7
3223+
assert mock_op.call_args.kwargs["body"].to_dict() == {
3224+
"first_open_period": "2026-02",
3225+
"note": "history from February",
3226+
"entity_id": "ent_2",
3227+
}
3228+
3229+
@patch("robosystems_client.clients.ledger_client.op_record_statement_balance")
3230+
@patch("robosystems_client.clients.ledger_client.op_refresh_reconciliations")
3231+
@patch("robosystems_client.clients.ledger_client.op_preview_reconciliations")
3232+
def test_reconciliation_calls_send_entity_id(
3233+
self, mock_preview, mock_refresh, mock_record, mock_config, graph_id
3234+
):
3235+
mock_preview.return_value = _mock_response(
3236+
_envelope("preview-reconciliations", {"period": "2026-08", "rows": []})
3237+
)
3238+
mock_refresh.return_value = _mock_response(
3239+
_envelope("refresh-reconciliations", {"period": "2026-08", "reconciliations": []})
3240+
)
3241+
mock_record.return_value = _mock_response(
3242+
_envelope("record-statement-balance", _RECONCILIATION)
3243+
)
3244+
client = LedgerClient(mock_config)
3245+
3246+
client.preview_reconciliations(graph_id, "2026-08", entity_id="ent_2")
3247+
client.refresh_reconciliations(graph_id, "2026-08", entity_id="ent_2")
3248+
client.record_statement_balance(
3249+
graph_id,
3250+
element_id="elem_cash",
3251+
as_of="2026-08-31",
3252+
balance=1200.0,
3253+
entity_id="ent_2",
3254+
)
3255+
3256+
for mock in (mock_preview, mock_refresh, mock_record):
3257+
assert mock.call_args.kwargs["body"].entity_id == "ent_2"
3258+
32103259
@patch("robosystems_client.clients.ledger_client.op_reopen_period")
32113260
def test_reopen_period_sends_entity_id(self, mock_op, mock_config, graph_id):
32123261
mock_op.return_value = _mock_response(_envelope("reopen-period", {}))

0 commit comments

Comments
 (0)