Skip to content

Commit 062bd6e

Browse files
committed
feat: create_journal_entry tags a consolidating entry (adjustment_kind, adjusts_entity_id)
An entry posted by hand in the group's consolidation entity names what it adjusts and the entity whose figures it adjusts, so the consolidation engine counts it toward what it already holds instead of proposing the elimination again.
1 parent 51cbbe6 commit 062bd6e

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)