Skip to content

Commit 3e9225d

Browse files
authored
feat: account register, statement sources and the event-entries bridge (#270)
## Summary The account-register surface from robosystems #1891, #1892 and #1893, regenerated, plus a facade for the register: one account's posted lines with a running balance, the accounts behind a live statement figure, and both directions of the event-to-entry link. The Python twin of robosystems-typescript-client #286. **Waits on the robosystems release after v1.19.3**, which carries those three PRs. Against v1.19.3 the new GraphQL fields (`accountRegister`, `EventBlock.triggeredEntries`, `triggeredByEventType`) do not exist and the affected queries fail. ## Changes - **Regenerated:** all from this effort's server changes; no unrelated drift. - OpenAPI models (`robosystems_client/models/`): `include_sources` on `LiveFinancialStatementRequest`, plus `origin` and `sources` on `LiveStatementFactRow`, with the new `StatementRowSource` - GraphQL: the schema snapshot (`schema.graphql`) and the typed models (`graphql/generated/`) - **Operations:** - new `ledger/GetLedgerAccountRegister.graphql` - `ListLedgerJournalEntries` selects `triggeredByEventType` - `GetLedgerEventBlock` selects `triggeredEntries` with each entry's line items - **Facade** (`LedgerClient`): - `get_account_register(graph_id, account_id, start_date=, end_date=, entity_id=, *, dimension_type=, dimension_member_id=, flow_element_id=, include_drafts=, after=, limit=)` - `live_financial_statement` needs nothing new: its request model now carries `include_sources` - `get_event_block` and `list_journal_entries` return the new fields through their regenerated models ## Compatibility ADDITIVE. A new query, a new optional request field, new models. The added selections return new response fields; no existing field changed type or became narrower. ## Testing - Regenerated against the local stack rebuilt from robosystems with #1891 and #1892 merged and #1893 (still open) on top (`just generate-sdk`, `just generate-graphql`). If #1893 changes in review, this regenerates again. - `env -u VIRTUAL_ENV just test-all`: 714 passed, plus lint, format and typecheck. One new facade test for `get_account_register`. The `get_event_block` and journal-entry fixtures gained the new fields, and the event-block test asserts `triggered_entries`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013UXnatpnbiixt1ZVHfdZAP
2 parents cd93d0c + bfbe082 commit 3e9225d

17 files changed

Lines changed: 1031 additions & 90 deletions

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@
380380
from ..graphql.generated.get_ledger_transaction import (
381381
GetLedgerTransactionTransaction as LedgerTransaction,
382382
)
383+
from ..graphql.generated.get_ledger_account_register import (
384+
GetLedgerAccountRegister,
385+
)
386+
from ..graphql.generated.get_ledger_account_register import (
387+
GetLedgerAccountRegisterAccountRegister as AccountRegister,
388+
)
383389
from ..graphql.generated.get_ledger_trial_balance import (
384390
GetLedgerTrialBalance,
385391
)
@@ -493,6 +499,7 @@
493499
)
494500
from ..graphql.generated.operations import (
495501
GET_INFORMATION_BLOCK_GQL,
502+
GET_LEDGER_ACCOUNT_REGISTER_GQL,
496503
GET_LEDGER_ACCOUNT_ROLLUPS_GQL,
497504
GET_LEDGER_ACCOUNT_TREE_GQL,
498505
GET_LEDGER_AGENT_GQL,
@@ -1296,6 +1303,44 @@ def get_trial_balance(
12961303
)
12971304
return GetLedgerTrialBalance.model_validate(data).trial_balance
12981305

1306+
def get_account_register(
1307+
self,
1308+
graph_id: str,
1309+
account_id: str,
1310+
start_date: str | None = None,
1311+
end_date: str | None = None,
1312+
entity_id: str | None = None,
1313+
*,
1314+
dimension_type: str | None = None,
1315+
dimension_member_id: str | None = None,
1316+
flow_element_id: str | None = None,
1317+
include_drafts: bool = False,
1318+
after: str | None = None,
1319+
limit: int | None = None,
1320+
) -> AccountRegister | None:
1321+
"""One entity's posted lines on one account, oldest first, each with the
1322+
balance it leaves, between an opening and a closing balance that agree
1323+
with the trial balance. An income or expense account opens at the fiscal
1324+
year's start. ``after`` takes the last page's ``next_cursor``; a dimension
1325+
pair or ``flow_element_id`` reads one slice, and says so in ``sliced``."""
1326+
data = self._query(
1327+
graph_id,
1328+
GET_LEDGER_ACCOUNT_REGISTER_GQL,
1329+
{
1330+
"accountId": account_id,
1331+
"startDate": start_date,
1332+
"endDate": end_date,
1333+
"entityId": entity_id,
1334+
"dimensionType": dimension_type,
1335+
"dimensionMemberId": dimension_member_id,
1336+
"flowElementId": flow_element_id,
1337+
"includeDrafts": include_drafts,
1338+
"after": after,
1339+
"limit": limit,
1340+
},
1341+
)
1342+
return GetLedgerAccountRegister.model_validate(data).account_register
1343+
12991344
# ── Management dimensions ─────────────────────────────────────────────
13001345

13011346
def get_dimensions(

‎robosystems_client/graphql/generated/__init__.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@
8282
)
8383
from .get_investor_position import GetInvestorPosition, GetInvestorPositionPosition
8484
from .get_investor_security import GetInvestorSecurity, GetInvestorSecuritySecurity
85+
from .get_ledger_account_register import (
86+
GetLedgerAccountRegister,
87+
GetLedgerAccountRegisterAccountRegister,
88+
GetLedgerAccountRegisterAccountRegisterAccount,
89+
GetLedgerAccountRegisterAccountRegisterDrafts,
90+
GetLedgerAccountRegisterAccountRegisterDraftsDimensions,
91+
GetLedgerAccountRegisterAccountRegisterLines,
92+
GetLedgerAccountRegisterAccountRegisterLinesDimensions,
93+
)
8594
from .get_ledger_account_rollups import (
8695
GetLedgerAccountRollups,
8796
GetLedgerAccountRollupsAccountRollups,
@@ -109,7 +118,12 @@
109118
GetLedgerClosingBookStructuresClosingBookStructuresCategoriesItems,
110119
)
111120
from .get_ledger_entity import GetLedgerEntity, GetLedgerEntityEntity
112-
from .get_ledger_event_block import GetLedgerEventBlock, GetLedgerEventBlockEventBlock
121+
from .get_ledger_event_block import (
122+
GetLedgerEventBlock,
123+
GetLedgerEventBlockEventBlock,
124+
GetLedgerEventBlockEventBlockTriggeredEntries,
125+
GetLedgerEventBlockEventBlockTriggeredEntriesLineItems,
126+
)
113127
from .get_ledger_fiscal_calendar import (
114128
GetLedgerFiscalCalendar,
115129
GetLedgerFiscalCalendarFiscalCalendar,
@@ -397,6 +411,7 @@
397411
GET_INVESTOR_PORTFOLIO_BLOCK_GQL,
398412
GET_INVESTOR_POSITION_GQL,
399413
GET_INVESTOR_SECURITY_GQL,
414+
GET_LEDGER_ACCOUNT_REGISTER_GQL,
400415
GET_LEDGER_ACCOUNT_ROLLUPS_GQL,
401416
GET_LEDGER_ACCOUNT_TREE_GQL,
402417
GET_LEDGER_AGENT_GQL,
@@ -501,6 +516,7 @@
501516
"GET_INVESTOR_PORTFOLIO_BLOCK_GQL",
502517
"GET_INVESTOR_POSITION_GQL",
503518
"GET_INVESTOR_SECURITY_GQL",
519+
"GET_LEDGER_ACCOUNT_REGISTER_GQL",
504520
"GET_LEDGER_ACCOUNT_ROLLUPS_GQL",
505521
"GET_LEDGER_ACCOUNT_TREE_GQL",
506522
"GET_LEDGER_AGENT_GQL",
@@ -563,6 +579,13 @@
563579
"GetInvestorPositionPosition",
564580
"GetInvestorSecurity",
565581
"GetInvestorSecuritySecurity",
582+
"GetLedgerAccountRegister",
583+
"GetLedgerAccountRegisterAccountRegister",
584+
"GetLedgerAccountRegisterAccountRegisterAccount",
585+
"GetLedgerAccountRegisterAccountRegisterDrafts",
586+
"GetLedgerAccountRegisterAccountRegisterDraftsDimensions",
587+
"GetLedgerAccountRegisterAccountRegisterLines",
588+
"GetLedgerAccountRegisterAccountRegisterLinesDimensions",
566589
"GetLedgerAccountRollups",
567590
"GetLedgerAccountRollupsAccountRollups",
568591
"GetLedgerAccountRollupsAccountRollupsGroups",
@@ -585,6 +608,8 @@
585608
"GetLedgerEntityEntity",
586609
"GetLedgerEventBlock",
587610
"GetLedgerEventBlockEventBlock",
611+
"GetLedgerEventBlockEventBlockTriggeredEntries",
612+
"GetLedgerEventBlockEventBlockTriggeredEntriesLineItems",
588613
"GetLedgerFiscalCalendar",
589614
"GetLedgerFiscalCalendarFiscalCalendar",
590615
"GetLedgerFiscalCalendarFiscalCalendarPendingObligationSample",

‎robosystems_client/graphql/generated/client.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .get_investor_portfolio_block import GetInvestorPortfolioBlock
1414
from .get_investor_position import GetInvestorPosition
1515
from .get_investor_security import GetInvestorSecurity
16+
from .get_ledger_account_register import GetLedgerAccountRegister
1617
from .get_ledger_account_rollups import GetLedgerAccountRollups
1718
from .get_ledger_account_tree import GetLedgerAccountTree
1819
from .get_ledger_agent import GetLedgerAgent
@@ -79,6 +80,7 @@
7980
GET_INVESTOR_PORTFOLIO_BLOCK_GQL,
8081
GET_INVESTOR_POSITION_GQL,
8182
GET_INVESTOR_SECURITY_GQL,
83+
GET_LEDGER_ACCOUNT_REGISTER_GQL,
8284
GET_LEDGER_ACCOUNT_ROLLUPS_GQL,
8385
GET_LEDGER_ACCOUNT_TREE_GQL,
8486
GET_LEDGER_AGENT_GQL,
@@ -365,6 +367,41 @@ def get_information_block(
365367
data = self.get_data(response)
366368
return GetInformationBlock.model_validate(data)
367369

370+
def get_ledger_account_register(
371+
self,
372+
account_id: str,
373+
include_drafts: bool,
374+
start_date: Union[Optional[str], UnsetType] = UNSET,
375+
end_date: Union[Optional[str], UnsetType] = UNSET,
376+
entity_id: Union[Optional[str], UnsetType] = UNSET,
377+
dimension_type: Union[Optional[str], UnsetType] = UNSET,
378+
dimension_member_id: Union[Optional[str], UnsetType] = UNSET,
379+
flow_element_id: Union[Optional[str], UnsetType] = UNSET,
380+
after: Union[Optional[str], UnsetType] = UNSET,
381+
limit: Union[Optional[int], UnsetType] = UNSET,
382+
**kwargs: Any,
383+
) -> GetLedgerAccountRegister:
384+
variables: dict[str, object] = {
385+
"accountId": account_id,
386+
"startDate": start_date,
387+
"endDate": end_date,
388+
"entityId": entity_id,
389+
"dimensionType": dimension_type,
390+
"dimensionMemberId": dimension_member_id,
391+
"flowElementId": flow_element_id,
392+
"includeDrafts": include_drafts,
393+
"after": after,
394+
"limit": limit,
395+
}
396+
response = self.execute(
397+
query=GET_LEDGER_ACCOUNT_REGISTER_GQL,
398+
operation_name="GetLedgerAccountRegister",
399+
variables=variables,
400+
**kwargs,
401+
)
402+
data = self.get_data(response)
403+
return GetLedgerAccountRegister.model_validate(data)
404+
368405
def get_ledger_account_rollups(
369406
self,
370407
mapping_id: Union[Optional[str], UnsetType] = UNSET,
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from typing import Optional
2+
3+
from pydantic import Field
4+
5+
from .base_model import BaseModel
6+
7+
8+
class GetLedgerAccountRegister(BaseModel):
9+
account_register: Optional["GetLedgerAccountRegisterAccountRegister"] = Field(
10+
alias="accountRegister"
11+
)
12+
13+
14+
class GetLedgerAccountRegisterAccountRegister(BaseModel):
15+
account: "GetLedgerAccountRegisterAccountRegisterAccount"
16+
entity_id: Optional[str] = Field(alias="entityId")
17+
start_date: Optional[str] = Field(alias="startDate")
18+
end_date: Optional[str] = Field(alias="endDate")
19+
opening_from: Optional[str] = Field(alias="openingFrom")
20+
opening_balance: float = Field(alias="openingBalance")
21+
total_debits: float = Field(alias="totalDebits")
22+
total_credits: float = Field(alias="totalCredits")
23+
closing_balance: float = Field(alias="closingBalance")
24+
line_count: int = Field(alias="lineCount")
25+
page_opening_balance: float = Field(alias="pageOpeningBalance")
26+
next_cursor: Optional[str] = Field(alias="nextCursor")
27+
sliced: bool
28+
drafts_truncated: bool = Field(alias="draftsTruncated")
29+
lines: list["GetLedgerAccountRegisterAccountRegisterLines"]
30+
drafts: list["GetLedgerAccountRegisterAccountRegisterDrafts"]
31+
32+
33+
class GetLedgerAccountRegisterAccountRegisterAccount(BaseModel):
34+
id: str
35+
code: Optional[str]
36+
name: str
37+
balance_type: str = Field(alias="balanceType")
38+
trait: Optional[str]
39+
temporary: bool
40+
41+
42+
class GetLedgerAccountRegisterAccountRegisterLines(BaseModel):
43+
line_id: str = Field(alias="lineId")
44+
entry_id: str = Field(alias="entryId")
45+
entry_number: Optional[str] = Field(alias="entryNumber")
46+
posting_date: str = Field(alias="postingDate")
47+
entry_type: str = Field(alias="entryType")
48+
provenance: Optional[str]
49+
status: str
50+
memo: Optional[str]
51+
description: Optional[str]
52+
debit: float
53+
credit: float
54+
balance: Optional[float]
55+
triggered_by_event_id: Optional[str] = Field(alias="triggeredByEventId")
56+
triggered_by_event_type: Optional[str] = Field(alias="triggeredByEventType")
57+
reversal_of: Optional[str] = Field(alias="reversalOf")
58+
reversed_by: Optional[str] = Field(alias="reversedBy")
59+
agent_id: Optional[str] = Field(alias="agentId")
60+
agent_name: Optional[str] = Field(alias="agentName")
61+
flow_element_id: Optional[str] = Field(alias="flowElementId")
62+
dimensions: list["GetLedgerAccountRegisterAccountRegisterLinesDimensions"]
63+
64+
65+
class GetLedgerAccountRegisterAccountRegisterLinesDimensions(BaseModel):
66+
id: str
67+
dimension_type: str = Field(alias="dimensionType")
68+
name: str
69+
70+
71+
class GetLedgerAccountRegisterAccountRegisterDrafts(BaseModel):
72+
line_id: str = Field(alias="lineId")
73+
entry_id: str = Field(alias="entryId")
74+
entry_number: Optional[str] = Field(alias="entryNumber")
75+
posting_date: str = Field(alias="postingDate")
76+
entry_type: str = Field(alias="entryType")
77+
provenance: Optional[str]
78+
status: str
79+
memo: Optional[str]
80+
description: Optional[str]
81+
debit: float
82+
credit: float
83+
balance: Optional[float]
84+
triggered_by_event_id: Optional[str] = Field(alias="triggeredByEventId")
85+
triggered_by_event_type: Optional[str] = Field(alias="triggeredByEventType")
86+
reversal_of: Optional[str] = Field(alias="reversalOf")
87+
reversed_by: Optional[str] = Field(alias="reversedBy")
88+
agent_id: Optional[str] = Field(alias="agentId")
89+
agent_name: Optional[str] = Field(alias="agentName")
90+
flow_element_id: Optional[str] = Field(alias="flowElementId")
91+
dimensions: list["GetLedgerAccountRegisterAccountRegisterDraftsDimensions"]
92+
93+
94+
class GetLedgerAccountRegisterAccountRegisterDraftsDimensions(BaseModel):
95+
id: str
96+
dimension_type: str = Field(alias="dimensionType")
97+
name: str
98+
99+
100+
GetLedgerAccountRegister.model_rebuild()
101+
GetLedgerAccountRegisterAccountRegister.model_rebuild()
102+
GetLedgerAccountRegisterAccountRegisterLines.model_rebuild()
103+
GetLedgerAccountRegisterAccountRegisterDrafts.model_rebuild()

‎robosystems_client/graphql/generated/get_ledger_event_block.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ class GetLedgerEventBlockEventBlock(BaseModel):
3535
document_id: Optional[str] = Field(alias="documentId")
3636
created_at: str = Field(alias="createdAt")
3737
created_by: str = Field(alias="createdBy")
38+
triggered_entries: list["GetLedgerEventBlockEventBlockTriggeredEntries"] = Field(
39+
alias="triggeredEntries"
40+
)
41+
42+
43+
class GetLedgerEventBlockEventBlockTriggeredEntries(BaseModel):
44+
id: str
45+
number: Optional[str]
46+
type_: str = Field(alias="type")
47+
status: str
48+
posting_date: str = Field(alias="postingDate")
49+
memo: Optional[str]
50+
provenance: Optional[str]
51+
total_debit: float = Field(alias="totalDebit")
52+
total_credit: float = Field(alias="totalCredit")
53+
line_items: list["GetLedgerEventBlockEventBlockTriggeredEntriesLineItems"] = Field(
54+
alias="lineItems"
55+
)
56+
57+
58+
class GetLedgerEventBlockEventBlockTriggeredEntriesLineItems(BaseModel):
59+
id: str
60+
account_id: str = Field(alias="accountId")
61+
account_name: Optional[str] = Field(alias="accountName")
62+
account_code: Optional[str] = Field(alias="accountCode")
63+
debit_amount: float = Field(alias="debitAmount")
64+
credit_amount: float = Field(alias="creditAmount")
65+
description: Optional[str]
66+
line_order: int = Field(alias="lineOrder")
3867

3968

4069
GetLedgerEventBlock.model_rebuild()
70+
GetLedgerEventBlockEventBlock.model_rebuild()
71+
GetLedgerEventBlockEventBlockTriggeredEntries.model_rebuild()

‎robosystems_client/graphql/generated/list_ledger_journal_entries.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ListLedgerJournalEntriesJournalEntriesEntries(BaseModel):
2828
source_structure_id: Optional[str] = Field(alias="sourceStructureId")
2929
source_structure_name: Optional[str] = Field(alias="sourceStructureName")
3030
triggered_by_event_id: Optional[str] = Field(alias="triggeredByEventId")
31+
triggered_by_event_type: Optional[str] = Field(alias="triggeredByEventType")
3132
reversal_of: Optional[str] = Field(alias="reversalOf")
3233
posted_at: Optional[str] = Field(alias="postedAt")
3334
total_debit: float = Field(alias="totalDebit")

0 commit comments

Comments
 (0)