Skip to content

Commit ee22858

Browse files
authored
feat: create_journal_entry tags a consolidating entry (#265)
## Summary `create_journal_entry` can now tag a consolidating entry posted in a reporting group's consolidation entity. It names what the entry adjusts (`adjustment_kind`) and the entity whose figures it adjusts (`adjusts_entity_id`). The consolidation engine counts a tagged entry toward what the group already holds, so an elimination posted by hand is not proposed again. Without the tags, it could be proposed and posted twice. The API has accepted and validated both fields since consolidation C2; the facade had no way to send them. ## Changes - Hand-written facade (`robosystems_client/clients/ledger_client.py`): `create_journal_entry` takes optional `adjustment_kind` and `adjusts_entity_id` and carries them in the `journal_entry_recorded` metadata. They're sent only when set. - No generated code changed. There is no async variant of this facade. ## Compatibility ADDITIVE: two new optional keyword arguments, and nothing is sent unless they are passed. The server already accepts both fields in production. ## Testing - `just test-all` passes: 699 passed, 17 skipped; ruff, format, basedpyright clean. - New tests: a tagged entry carries both fields in its metadata, and an untagged entry carries neither. Companion PRs: RoboFinSystems/robosystems-typescript-client (the same option on `createJournalEntry`), RoboFinSystems/roboledger-app (the journal entry modal on the consolidation entity). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents 51cbbe6 + 062bd6e commit ee22858

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,8 @@ def create_journal_entry(
20432043
source: str = "manual",
20442044
idempotency_key: str | None = None,
20452045
entity_id: str | None = None,
2046+
adjustment_kind: str | None = None,
2047+
adjusts_entity_id: str | None = None,
20462048
) -> EventBlockEnvelope:
20472049
"""Create a journal entry with balanced line items (DR=CR enforced).
20482050
@@ -2065,6 +2067,13 @@ def create_journal_entry(
20652067
``entity_id`` names the entity whose books the entry goes into; omitted,
20662068
the group parent's.
20672069
2070+
``adjustment_kind`` tags a consolidating entry in the group's
2071+
consolidation entity (``elimination_intercompany``, ``manual``, ...), with
2072+
``adjusts_entity_id`` the entity whose figures it adjusts (required for
2073+
every kind but ``manual``). Only that entity's books take one; the
2074+
consolidation engine counts a tagged entry toward what it already holds,
2075+
so an elimination posted by hand is not proposed again.
2076+
20682077
A line dict may carry ``flow_qname``, the cash flow row its cash belongs
20692078
to (a ``qname`` from ``get_flow_candidates``): only for a loan drawn or
20702079
repaid, capital put in or taken out, an asset bought or sold. A flow on
@@ -2082,6 +2091,10 @@ def create_journal_entry(
20822091
}
20832092
if transaction_id is not None:
20842093
metadata["transaction_id"] = transaction_id
2094+
if adjustment_kind is not None:
2095+
metadata["adjustment_kind"] = adjustment_kind
2096+
if adjusts_entity_id is not None:
2097+
metadata["adjusts_entity_id"] = adjusts_entity_id
20852098
body = self._build_event_block_request(
20862099
event_type="journal_entry_recorded",
20872100
event_category="adjustment",

‎tests/test_ledger_client.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,38 @@ def test_create_journal_entry_names_its_entity(self, mock_op, mock_config, graph
809809
)
810810
assert mock_op.call_args.kwargs["body"].entity_id == "ent_sub"
811811

812+
@patch("robosystems_client.clients.ledger_client.op_create_event_block")
813+
def test_create_journal_entry_tags_a_consolidating_entry(
814+
self, mock_op, mock_config, graph_id
815+
):
816+
mock_op.return_value = _mock_response(_envelope("create-event-block", {}))
817+
client = LedgerClient(mock_config)
818+
client.create_journal_entry(
819+
graph_id,
820+
posting_date="2026-07-31",
821+
memo="Intercompany receivable",
822+
line_items=self._LINE_ITEMS,
823+
entity_id="ent_cons",
824+
adjustment_kind="elimination_intercompany",
825+
adjusts_entity_id="ent_sub",
826+
)
827+
metadata = mock_op.call_args.kwargs["body"].metadata.to_dict()
828+
assert metadata["adjustment_kind"] == "elimination_intercompany"
829+
assert metadata["adjusts_entity_id"] == "ent_sub"
830+
831+
@patch("robosystems_client.clients.ledger_client.op_create_event_block")
832+
def test_create_journal_entry_sends_no_consolidating_tags_unasked(
833+
self, mock_op, mock_config, graph_id
834+
):
835+
mock_op.return_value = _mock_response(_envelope("create-event-block", {}))
836+
client = LedgerClient(mock_config)
837+
client.create_journal_entry(
838+
graph_id, posting_date="2026-03-31", memo="X", line_items=self._LINE_ITEMS
839+
)
840+
metadata = mock_op.call_args.kwargs["body"].metadata.to_dict()
841+
assert "adjustment_kind" not in metadata
842+
assert "adjusts_entity_id" not in metadata
843+
812844
@patch("robosystems_client.clients.ledger_client.op_create_event_block")
813845
def test_create_journal_entry_leaves_the_entity_to_the_server(
814846
self, mock_op, mock_config, graph_id

0 commit comments

Comments
 (0)