Skip to content

Commit 1ef1d05

Browse files
committed
feat(ledger): a journal entry names the entity it is for
Claude-Session: https://claude.ai/code/session_014Wxgk4yttBxgdE2uBHT71R
1 parent e83c9f7 commit 1ef1d05

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,7 @@ def create_journal_entry(
19391939
transaction_id: str | None = None,
19401940
source: str = "manual",
19411941
idempotency_key: str | None = None,
1942+
entity_id: str | None = None,
19421943
) -> EventBlockEnvelope:
19431944
"""Create a journal entry with balanced line items (DR=CR enforced).
19441945
@@ -1958,6 +1959,9 @@ def create_journal_entry(
19581959
within 24 hours return the same envelope. Reusing the key with a
19591960
different body returns HTTP 409.
19601961
1962+
``entity_id`` names the entity whose books the entry goes into; omitted,
1963+
the group parent's.
1964+
19611965
Returns the EventBlockEnvelope (event row fields).
19621966
"""
19631967
metadata: dict[str, Any] = {
@@ -1976,6 +1980,8 @@ def create_journal_entry(
19761980
metadata=metadata,
19771981
source=source,
19781982
)
1983+
if entity_id is not None:
1984+
body.entity_id = entity_id
19791985
response = op_create_event_block(
19801986
graph_id=graph_id,
19811987
body=body,

‎tests/test_ledger_client.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,30 @@ def test_create_journal_entry_basic(self, mock_op, mock_config, graph_id):
766766
assert metadata["type"] == "standard"
767767
assert metadata["status"] == "draft"
768768

769+
@patch("robosystems_client.clients.ledger_client.op_create_event_block")
770+
def test_create_journal_entry_names_its_entity(self, mock_op, mock_config, graph_id):
771+
mock_op.return_value = _mock_response(_envelope("create-event-block", {}))
772+
client = LedgerClient(mock_config)
773+
client.create_journal_entry(
774+
graph_id,
775+
posting_date="2026-03-31",
776+
memo="Opening balance",
777+
line_items=self._LINE_ITEMS,
778+
entity_id="ent_sub",
779+
)
780+
assert mock_op.call_args.kwargs["body"].entity_id == "ent_sub"
781+
782+
@patch("robosystems_client.clients.ledger_client.op_create_event_block")
783+
def test_create_journal_entry_leaves_the_entity_to_the_server(
784+
self, mock_op, mock_config, graph_id
785+
):
786+
mock_op.return_value = _mock_response(_envelope("create-event-block", {}))
787+
client = LedgerClient(mock_config)
788+
client.create_journal_entry(
789+
graph_id, posting_date="2026-03-31", memo="X", line_items=self._LINE_ITEMS
790+
)
791+
assert mock_op.call_args.kwargs["body"].entity_id is UNSET
792+
769793
@patch("robosystems_client.clients.ledger_client.op_create_event_block")
770794
def test_create_journal_entry_idempotency_key_forwarded(
771795
self, mock_op, mock_config, graph_id

0 commit comments

Comments
 (0)