Skip to content

Commit c34f3ed

Browse files
authored
feat: entity scope on the ledger facade (entity_id, create_entity) (#240)
## Summary Threads the multi-entity step 2 server surface (robosystems #1714, v1.16.4) through the `LedgerClient` facade, so a caller can read and close one entity of a reporting group without dropping to the generated tier. Additive; no existing signature changes. Ships as a patch on 2.8: the minor for this effort was 2.8.0. Twin of robosystems-typescript-client #255. ## Changes - **`entity_id=None`** on every GraphQL-backed read whose server field takes it: `get_entity`, `get_summary`, `list_accounts`, `get_account_tree`, `get_account_rollups`, `list_transactions`, `list_journal_entries`, `list_event_blocks`, `get_trial_balance`, `get_period_close_status`, `list_period_drafts`, `get_closing_book_structures`, `get_fiscal_calendar`, `list_reconciliations`, `list_reports`. Omitted, a call is about the group parent and sends exactly what it sent before (`None` variables are stripped, as the facade already did). - **Close writes carry `entity_id`** (keyword): `close_period`, `set_close_target`, `reopen_period`, `initialize_ledger`, `initialize_chart_of_accounts`. Left out, the field stays `UNSET` and off the wire. - **`create_entity(graph_id, body)`** beside `update_entity`, returning `LedgerEntityResponse`. - **Entity shape**: `reportingStyleId` and `ownershipPct` selected on `entity`; `ownershipPct` on `entities`; `entityId` on `summary`, `fiscalCalendar`, `reports` and `report`. - **Generated models** regenerated with `just generate-graphql` from the checked-in schema (already at the v1.16.4 shape since 2.8.0), so the drift gate is clean. - `live_financial_statement` needed nothing: its body already carries `entity_id` and `consolidated` from 2.8.0. ## Breaking Changes None. Stable tier grows; nothing moves or is removed. The integration template's emit path is untouched. ## Testing `just test-all` (664 passed, ruff format and lint, basedpyright) passes locally. New tests cover the `entityId` variable on reads (and its absence by default), `entity_id` on the close writes, and `create_entity`'s body and envelope. Five existing mocks gained the keys the regenerated models now require (`reportingStyleId`, `ownershipPct`, `entityId`), as the server returns them. ## Rollout The documents select fields and pass arguments that exist from server v1.16.4. Marked ready with the v1.16.4 production deploy in flight; the apps pin the client by lockfile, so nothing moves until a bump. ## Certification - [x] I have the right to submit this work under the Apache 2.0 license, and do so. Where any part of it is owned by my employer, I have their permission. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01BY3uYE5zMjjFHnjiZfiJu8
2 parents 51d30e2 + 7df8874 commit c34f3ed

27 files changed

Lines changed: 392 additions & 92 deletions

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 110 additions & 24 deletions
Large diffs are not rendered by default.

‎robosystems_client/graphql/generated/client.py‎

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,14 @@ def get_ledger_account_rollups(
271271
mapping_id: Union[Optional[str], UnsetType] = UNSET,
272272
start_date: Union[Optional[str], UnsetType] = UNSET,
273273
end_date: Union[Optional[str], UnsetType] = UNSET,
274+
entity_id: Union[Optional[str], UnsetType] = UNSET,
274275
**kwargs: Any,
275276
) -> GetLedgerAccountRollups:
276277
variables: dict[str, object] = {
277278
"mappingId": mapping_id,
278279
"startDate": start_date,
279280
"endDate": end_date,
281+
"entityId": entity_id,
280282
}
281283
response = self.execute(
282284
query=GET_LEDGER_ACCOUNT_ROLLUPS_GQL,
@@ -287,8 +289,10 @@ def get_ledger_account_rollups(
287289
data = self.get_data(response)
288290
return GetLedgerAccountRollups.model_validate(data)
289291

290-
def get_ledger_account_tree(self, **kwargs: Any) -> GetLedgerAccountTree:
291-
variables: dict[str, object] = {}
292+
def get_ledger_account_tree(
293+
self, entity_id: Union[Optional[str], UnsetType] = UNSET, **kwargs: Any
294+
) -> GetLedgerAccountTree:
295+
variables: dict[str, object] = {"entityId": entity_id}
292296
response = self.execute(
293297
query=GET_LEDGER_ACCOUNT_TREE_GQL,
294298
operation_name="GetLedgerAccountTree",
@@ -310,9 +314,9 @@ def get_ledger_agent(self, id: str, **kwargs: Any) -> GetLedgerAgent:
310314
return GetLedgerAgent.model_validate(data)
311315

312316
def get_ledger_closing_book_structures(
313-
self, **kwargs: Any
317+
self, entity_id: Union[Optional[str], UnsetType] = UNSET, **kwargs: Any
314318
) -> GetLedgerClosingBookStructures:
315-
variables: dict[str, object] = {}
319+
variables: dict[str, object] = {"entityId": entity_id}
316320
response = self.execute(
317321
query=GET_LEDGER_CLOSING_BOOK_STRUCTURES_GQL,
318322
operation_name="GetLedgerClosingBookStructures",
@@ -322,8 +326,10 @@ def get_ledger_closing_book_structures(
322326
data = self.get_data(response)
323327
return GetLedgerClosingBookStructures.model_validate(data)
324328

325-
def get_ledger_entity(self, **kwargs: Any) -> GetLedgerEntity:
326-
variables: dict[str, object] = {}
329+
def get_ledger_entity(
330+
self, entity_id: Union[Optional[str], UnsetType] = UNSET, **kwargs: Any
331+
) -> GetLedgerEntity:
332+
variables: dict[str, object] = {"entityId": entity_id}
327333
response = self.execute(
328334
query=GET_LEDGER_ENTITY_GQL,
329335
operation_name="GetLedgerEntity",
@@ -344,8 +350,10 @@ def get_ledger_event_block(self, id: str, **kwargs: Any) -> GetLedgerEventBlock:
344350
data = self.get_data(response)
345351
return GetLedgerEventBlock.model_validate(data)
346352

347-
def get_ledger_fiscal_calendar(self, **kwargs: Any) -> GetLedgerFiscalCalendar:
348-
variables: dict[str, object] = {}
353+
def get_ledger_fiscal_calendar(
354+
self, entity_id: Union[Optional[str], UnsetType] = UNSET, **kwargs: Any
355+
) -> GetLedgerFiscalCalendar:
356+
variables: dict[str, object] = {"entityId": entity_id}
349357
response = self.execute(
350358
query=GET_LEDGER_FISCAL_CALENDAR_GQL,
351359
operation_name="GetLedgerFiscalCalendar",
@@ -401,11 +409,16 @@ def get_ledger_mapping_coverage(
401409
return GetLedgerMappingCoverage.model_validate(data)
402410

403411
def get_ledger_period_close_status(
404-
self, period_start: str, period_end: str, **kwargs: Any
412+
self,
413+
period_start: str,
414+
period_end: str,
415+
entity_id: Union[Optional[str], UnsetType] = UNSET,
416+
**kwargs: Any,
405417
) -> GetLedgerPeriodCloseStatus:
406418
variables: dict[str, object] = {
407419
"periodStart": period_start,
408420
"periodEnd": period_end,
421+
"entityId": entity_id,
409422
}
410423
response = self.execute(
411424
query=GET_LEDGER_PERIOD_CLOSE_STATUS_GQL,
@@ -417,9 +430,9 @@ def get_ledger_period_close_status(
417430
return GetLedgerPeriodCloseStatus.model_validate(data)
418431

419432
def get_ledger_period_drafts(
420-
self, period: str, **kwargs: Any
433+
self, period: str, entity_id: Union[Optional[str], UnsetType] = UNSET, **kwargs: Any
421434
) -> GetLedgerPeriodDrafts:
422-
variables: dict[str, object] = {"period": period}
435+
variables: dict[str, object] = {"period": period, "entityId": entity_id}
423436
response = self.execute(
424437
query=GET_LEDGER_PERIOD_DRAFTS_GQL,
425438
operation_name="GetLedgerPeriodDrafts",
@@ -511,8 +524,10 @@ def get_ledger_statement(
511524
data = self.get_data(response)
512525
return GetLedgerStatement.model_validate(data)
513526

514-
def get_ledger_summary(self, **kwargs: Any) -> GetLedgerSummary:
515-
variables: dict[str, object] = {}
527+
def get_ledger_summary(
528+
self, entity_id: Union[Optional[str], UnsetType] = UNSET, **kwargs: Any
529+
) -> GetLedgerSummary:
530+
variables: dict[str, object] = {"entityId": entity_id}
516531
response = self.execute(
517532
query=GET_LEDGER_SUMMARY_GQL,
518533
operation_name="GetLedgerSummary",
@@ -539,9 +554,14 @@ def get_ledger_trial_balance(
539554
self,
540555
start_date: Union[Optional[str], UnsetType] = UNSET,
541556
end_date: Union[Optional[str], UnsetType] = UNSET,
557+
entity_id: Union[Optional[str], UnsetType] = UNSET,
542558
**kwargs: Any,
543559
) -> GetLedgerTrialBalance:
544-
variables: dict[str, object] = {"startDate": start_date, "endDate": end_date}
560+
variables: dict[str, object] = {
561+
"startDate": start_date,
562+
"endDate": end_date,
563+
"entityId": entity_id,
564+
}
545565
response = self.execute(
546566
query=GET_LEDGER_TRIAL_BALANCE_GQL,
547567
operation_name="GetLedgerTrialBalance",
@@ -593,13 +613,15 @@ def list_ledger_accounts(
593613
offset: int,
594614
classification: Union[Optional[str], UnsetType] = UNSET,
595615
is_active: Union[Optional[bool], UnsetType] = UNSET,
616+
entity_id: Union[Optional[str], UnsetType] = UNSET,
596617
**kwargs: Any,
597618
) -> ListLedgerAccounts:
598619
variables: dict[str, object] = {
599620
"classification": classification,
600621
"isActive": is_active,
601622
"limit": limit,
602623
"offset": offset,
624+
"entityId": entity_id,
603625
}
604626
response = self.execute(
605627
query=LIST_LEDGER_ACCOUNTS_GQL,
@@ -698,6 +720,7 @@ def list_ledger_event_blocks(
698720
agent_id: Union[Optional[str], UnsetType] = UNSET,
699721
source: Union[Optional[str], UnsetType] = UNSET,
700722
is_reconciling_item: Union[Optional[bool], UnsetType] = UNSET,
723+
entity_id: Union[Optional[str], UnsetType] = UNSET,
701724
**kwargs: Any,
702725
) -> ListLedgerEventBlocks:
703726
variables: dict[str, object] = {
@@ -709,6 +732,7 @@ def list_ledger_event_blocks(
709732
"isReconcilingItem": is_reconciling_item,
710733
"limit": limit,
711734
"offset": offset,
735+
"entityId": entity_id,
712736
}
713737
response = self.execute(
714738
query=LIST_LEDGER_EVENT_BLOCKS_GQL,
@@ -729,6 +753,7 @@ def list_ledger_journal_entries(
729753
type_: Union[Optional[str], UnsetType] = UNSET,
730754
provenance: Union[Optional[str], UnsetType] = UNSET,
731755
transaction_id: Union[Optional[str], UnsetType] = UNSET,
756+
entity_id: Union[Optional[str], UnsetType] = UNSET,
732757
**kwargs: Any,
733758
) -> ListLedgerJournalEntries:
734759
variables: dict[str, object] = {
@@ -740,6 +765,7 @@ def list_ledger_journal_entries(
740765
"transactionId": transaction_id,
741766
"limit": limit,
742767
"offset": offset,
768+
"entityId": entity_id,
743769
}
744770
response = self.execute(
745771
query=LIST_LEDGER_JOURNAL_ENTRIES_GQL,
@@ -775,9 +801,9 @@ def list_ledger_publish_lists(
775801
return ListLedgerPublishLists.model_validate(data)
776802

777803
def list_ledger_reconciliations(
778-
self, period: str, **kwargs: Any
804+
self, period: str, entity_id: Union[Optional[str], UnsetType] = UNSET, **kwargs: Any
779805
) -> ListLedgerReconciliations:
780-
variables: dict[str, object] = {"period": period}
806+
variables: dict[str, object] = {"period": period, "entityId": entity_id}
781807
response = self.execute(
782808
query=LIST_LEDGER_RECONCILIATIONS_GQL,
783809
operation_name="ListLedgerReconciliations",
@@ -788,9 +814,12 @@ def list_ledger_reconciliations(
788814
return ListLedgerReconciliations.model_validate(data)
789815

790816
def list_ledger_reports(
791-
self, lifecycle: Union[Optional[ReportLifecycle], UnsetType] = UNSET, **kwargs: Any
817+
self,
818+
lifecycle: Union[Optional[ReportLifecycle], UnsetType] = UNSET,
819+
entity_id: Union[Optional[str], UnsetType] = UNSET,
820+
**kwargs: Any,
792821
) -> ListLedgerReports:
793-
variables: dict[str, object] = {"lifecycle": lifecycle}
822+
variables: dict[str, object] = {"lifecycle": lifecycle, "entityId": entity_id}
794823
response = self.execute(
795824
query=LIST_LEDGER_REPORTS_GQL,
796825
operation_name="ListLedgerReports",
@@ -839,6 +868,7 @@ def list_ledger_transactions(
839868
type_: Union[Optional[str], UnsetType] = UNSET,
840869
start_date: Union[Optional[str], UnsetType] = UNSET,
841870
end_date: Union[Optional[str], UnsetType] = UNSET,
871+
entity_id: Union[Optional[str], UnsetType] = UNSET,
842872
**kwargs: Any,
843873
) -> ListLedgerTransactions:
844874
variables: dict[str, object] = {
@@ -847,6 +877,7 @@ def list_ledger_transactions(
847877
"endDate": end_date,
848878
"limit": limit,
849879
"offset": offset,
880+
"entityId": entity_id,
850881
}
851882
response = self.execute(
852883
query=LIST_LEDGER_TRANSACTIONS_GQL,

‎robosystems_client/graphql/generated/get_ledger_entity.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ class GetLedgerEntityEntity(BaseModel):
2626
lei: Optional[str]
2727
industry: Optional[str]
2828
entity_type: Optional[str] = Field(alias="entityType")
29+
reporting_style_id: Optional[str] = Field(alias="reportingStyleId")
2930
phone: Optional[str]
3031
website: Optional[str]
3132
status: str
3233
is_parent: bool = Field(alias="isParent")
3334
parent_entity_id: Optional[str] = Field(alias="parentEntityId")
35+
ownership_pct: Optional[float] = Field(alias="ownershipPct")
3436
source: str
3537
source_id: Optional[str] = Field(alias="sourceId")
3638
source_graph_id: Optional[str] = Field(alias="sourceGraphId")

‎robosystems_client/graphql/generated/get_ledger_fiscal_calendar.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class GetLedgerFiscalCalendar(BaseModel):
1313

1414
class GetLedgerFiscalCalendarFiscalCalendar(BaseModel):
1515
graph_id: str = Field(alias="graphId")
16+
entity_id: Optional[str] = Field(alias="entityId")
1617
fiscal_year_start_month: int = Field(alias="fiscalYearStartMonth")
1718
closed_through: Optional[str] = Field(alias="closedThrough")
1819
close_target: Optional[str] = Field(alias="closeTarget")

‎robosystems_client/graphql/generated/get_ledger_report.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class GetLedgerReport(BaseModel):
1111

1212
class GetLedgerReportReport(BaseModel):
1313
id: str
14+
entity_id: Optional[str] = Field(alias="entityId")
1415
name: str
1516
taxonomy_id: str = Field(alias="taxonomyId")
1617
generation_status: str = Field(alias="generationStatus")

‎robosystems_client/graphql/generated/get_ledger_summary.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class GetLedgerSummary(BaseModel):
1111

1212
class GetLedgerSummarySummary(BaseModel):
1313
graph_id: str = Field(alias="graphId")
14+
entity_id: Optional[str] = Field(alias="entityId")
1415
account_count: int = Field(alias="accountCount")
1516
transaction_count: int = Field(alias="transactionCount")
1617
entry_count: int = Field(alias="entryCount")

‎robosystems_client/graphql/generated/list_ledger_entities.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ListLedgerEntitiesEntities(BaseModel):
2020
status: str
2121
is_parent: bool = Field(alias="isParent")
2222
parent_entity_id: Optional[str] = Field(alias="parentEntityId")
23+
ownership_pct: Optional[float] = Field(alias="ownershipPct")
2324
source: str
2425
source_graph_id: Optional[str] = Field(alias="sourceGraphId")
2526
connection_id: Optional[str] = Field(alias="connectionId")

‎robosystems_client/graphql/generated/list_ledger_reports.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ListLedgerReportsReports(BaseModel):
1515

1616
class ListLedgerReportsReportsReports(BaseModel):
1717
id: str
18+
entity_id: Optional[str] = Field(alias="entityId")
1819
name: str
1920
taxonomy_id: str = Field(alias="taxonomyId")
2021
generation_status: str = Field(alias="generationStatus")

0 commit comments

Comments
 (0)