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
6 changes: 6 additions & 0 deletions robosystems_client/clients/ledger_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,7 @@ def create_journal_entry(
transaction_id: str | None = None,
source: str = "manual",
idempotency_key: str | None = None,
entity_id: str | None = None,
) -> EventBlockEnvelope:
"""Create a journal entry with balanced line items (DR=CR enforced).

Expand All @@ -1958,6 +1959,9 @@ def create_journal_entry(
within 24 hours return the same envelope. Reusing the key with a
different body returns HTTP 409.

``entity_id`` names the entity whose books the entry goes into; omitted,
the group parent's.

Returns the EventBlockEnvelope (event row fields).
"""
metadata: dict[str, Any] = {
Expand All @@ -1976,6 +1980,8 @@ def create_journal_entry(
metadata=metadata,
source=source,
)
if entity_id is not None:
body.entity_id = entity_id
response = op_create_event_block(
graph_id=graph_id,
body=body,
Expand Down
24 changes: 24 additions & 0 deletions tests/test_ledger_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,30 @@ def test_create_journal_entry_basic(self, mock_op, mock_config, graph_id):
assert metadata["type"] == "standard"
assert metadata["status"] == "draft"

@patch("robosystems_client.clients.ledger_client.op_create_event_block")
def test_create_journal_entry_names_its_entity(self, mock_op, mock_config, graph_id):
mock_op.return_value = _mock_response(_envelope("create-event-block", {}))
client = LedgerClient(mock_config)
client.create_journal_entry(
graph_id,
posting_date="2026-03-31",
memo="Opening balance",
line_items=self._LINE_ITEMS,
entity_id="ent_sub",
)
assert mock_op.call_args.kwargs["body"].entity_id == "ent_sub"

@patch("robosystems_client.clients.ledger_client.op_create_event_block")
def test_create_journal_entry_leaves_the_entity_to_the_server(
self, mock_op, mock_config, graph_id
):
mock_op.return_value = _mock_response(_envelope("create-event-block", {}))
client = LedgerClient(mock_config)
client.create_journal_entry(
graph_id, posting_date="2026-03-31", memo="X", line_items=self._LINE_ITEMS
)
assert mock_op.call_args.kwargs["body"].entity_id is UNSET

@patch("robosystems_client.clients.ledger_client.op_create_event_block")
def test_create_journal_entry_idempotency_key_forwarded(
self, mock_op, mock_config, graph_id
Expand Down
Loading