Skip to content

Commit ca91779

Browse files
authored
feat(ledger): a journal entry names the entity it is for (#250)
## Summary `create_journal_entry` gains an `entity_id` argument, so a caller can record a manual journal entry for a subsidiary. Without it the server files the entry on the group parent and refuses the subsidiary's accounts. ## Changes - `robosystems_client/clients/ledger_client.py`: `create_journal_entry(..., entity_id=None)` sets `entity_id` on the `CreateEventBlockRequest` when given. Omitted, the request is unchanged. ## Compatibility Additive facade argument: a **client minor**. No server change needed: `create-event-block` already honours `entity_id`. ## Testing Two new tests (the entity is sent; `UNSET` when omitted). `just test-all` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_014Wxgk4yttBxgdE2uBHT71R
2 parents e83c9f7 + 1ef1d05 commit ca91779

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)