Skip to content

Commit 350f9fa

Browse files
committed
feat(ledger): information blocks, mappings, reports and schedules take an entity
get_information_block and list_information_blocks take entity_id and the envelope names the entity it read; list_mappings names whose chart each mapping maps and takes entity_id; get_mapping_candidates narrows by the entity's style; create_report and create_schedule pass entity_id through.
1 parent bf85d00 commit 350f9fa

20 files changed

Lines changed: 254 additions & 42 deletions

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,13 +1358,17 @@ def list_structures(
13581358
page = ListLedgerStructures.model_validate(data).structures
13591359
return page.structures if page else []
13601360

1361-
def list_mappings(self, graph_id: str) -> list[ListLedgerMappingsMappingsStructures]:
1361+
def list_mappings(
1362+
self, graph_id: str, *, entity_id: str | None = None
1363+
) -> list[ListLedgerMappingsMappingsStructures]:
13621364
"""List active CoA→reporting mapping structures, the book mapping first.
13631365
13641366
Each carries ``framework``: the reporting framework it maps the chart
1365-
into. A chart holds one mapping per framework.
1367+
into (a chart holds one mapping per framework), and ``entity_id``: the
1368+
entity whose chart it maps from, so whose reports it can produce.
1369+
``entity_id`` keeps that entity's mappings only.
13661370
"""
1367-
data = self._query(graph_id, LIST_LEDGER_MAPPINGS_GQL)
1371+
data = self._query(graph_id, LIST_LEDGER_MAPPINGS_GQL, {"entityId": entity_id})
13681372
page = ListLedgerMappings.model_validate(data).mappings
13691373
return page.structures if page else []
13701374

@@ -1383,16 +1387,19 @@ def get_mapping_coverage(
13831387
return GetLedgerMappingCoverage.model_validate(data).mapping_coverage
13841388

13851389
def get_mapping_candidates(
1386-
self, graph_id: str, classification: str
1390+
self, graph_id: str, classification: str, *, entity_id: str | None = None
13871391
) -> list[MappingCandidatesMappingCandidates]:
13881392
"""rs-gaap concepts a CoA element of the given EFS ``classification``
13891393
(asset / liability / equity / revenue / expense) may map to — limited
1390-
to concepts that render under the graph's active Reporting Style,
1391-
with statement-level subtotals excluded. Use this to populate the
1392-
mapping picker so it never offers an unreachable target.
1394+
to concepts that render under the Reporting Style of the entity whose
1395+
chart is being mapped (``entity_id``, default the group parent), with
1396+
statement-level subtotals excluded. Use this to populate the mapping
1397+
picker so it never offers an unreachable target.
13931398
"""
13941399
data = self._query(
1395-
graph_id, MAPPING_CANDIDATES_GQL, {"classification": classification}
1400+
graph_id,
1401+
MAPPING_CANDIDATES_GQL,
1402+
{"classification": classification, "entityId": entity_id},
13961403
)
13971404
return MappingCandidates.model_validate(data).mapping_candidates
13981405

@@ -1454,6 +1461,7 @@ def get_information_block(
14541461
series: bool | None = None,
14551462
series_history: int | None = None,
14561463
series_forecast: int | None = None,
1464+
entity_id: str | None = None,
14571465
) -> InformationBlock | None:
14581466
"""Fetch an Information Block envelope by id — the cross-block-type read.
14591467
@@ -1474,6 +1482,12 @@ def get_information_block(
14741482
``series_history`` / ``series_forecast`` window the series to its
14751483
seam-adjacent columns — the last N actual columns and the first N
14761484
forecast columns; ``None`` = unbounded.
1485+
1486+
``entity_id`` picks whose books a block shared by the group reads
1487+
(statements, metrics, disclosures); ``None`` = the scenario's entity,
1488+
else the group parent. A schedule, reconciliation or forecast always
1489+
reads its own entity's. The envelope's ``entity_id`` names the entity
1490+
it read.
14771491
"""
14781492
data = self._query(
14791493
graph_id,
@@ -1484,6 +1498,7 @@ def get_information_block(
14841498
"series": series,
14851499
"seriesHistory": series_history,
14861500
"seriesForecast": series_forecast,
1501+
"entityId": entity_id,
14871502
},
14881503
)
14891504
return GetInformationBlock.model_validate(data).information_block
@@ -1497,13 +1512,19 @@ def list_information_blocks(
14971512
limit: int | None = None,
14981513
offset: int | None = None,
14991514
scenario_id: str | None = None,
1515+
entity_id: str | None = None,
15001516
) -> list[ListInformationBlocksInformationBlocks]:
15011517
"""List Information Block envelopes, optionally filtered.
15021518
15031519
Replaces the old ``list_schedules`` method — use
15041520
``block_type='schedule'`` for the same set of blocks.
15051521
``scenario_id`` (a forecast block's structure id) threads into each
15061522
envelope's FactSet binding.
1523+
1524+
``entity_id`` (``None`` = the scenario's entity, else the group
1525+
parent) lists the blocks shared by the group plus that entity's own
1526+
schedules, reconciliations and forecasts, never another entity's;
1527+
shared blocks read its books.
15071528
"""
15081529
data = self._query(
15091530
graph_id,
@@ -1514,6 +1535,7 @@ def list_information_blocks(
15141535
"limit": limit,
15151536
"offset": offset,
15161537
"scenarioId": scenario_id,
1538+
"entityId": entity_id,
15171539
},
15181540
)
15191541
return ListInformationBlocks.model_validate(data).information_blocks
@@ -1604,12 +1626,16 @@ def create_schedule(
16041626
asset_element_id: str | None = None,
16051627
auto_reverse: bool = False,
16061628
booked_on: str | None = None,
1629+
entity_id: str | None = None,
16071630
) -> InformationBlockEnvelope:
16081631
"""Create a new schedule with pre-generated monthly facts.
16091632
16101633
``booked_on`` (``YYYY-MM-DD``) is the day the schedule's cost went on
16111634
the books, when that is before its first period. The schedule
16121635
reconciliation carries the cost from that day.
1636+
1637+
``entity_id`` is the entity whose books the schedule belongs to;
1638+
``None`` = the group parent.
16131639
"""
16141640
payload_dict: dict[str, Any] = {
16151641
"name": name,
@@ -1627,6 +1653,8 @@ def create_schedule(
16271653
}
16281654
if taxonomy_id:
16291655
payload_dict["taxonomy_id"] = taxonomy_id
1656+
if entity_id:
1657+
payload_dict["entity_id"] = entity_id
16301658
schedule_metadata: dict[str, Any] = {}
16311659
if method:
16321660
schedule_metadata["method"] = method
@@ -2636,6 +2664,7 @@ def create_report(
26362664
period_type: str = "quarterly",
26372665
comparative: bool = True,
26382666
periods: list[PeriodSpec | dict[str, Any]] | None = None,
2667+
entity_id: str | None = None,
26392668
) -> ReportResponse:
26402669
"""Generate report facts from the ledger and publish a Report
26412670
definition. Synchronous — returns the published report header.
@@ -2647,6 +2676,10 @@ def create_report(
26472676
``{"start", "end", "label"}`` dicts — for multi-period layouts
26482677
(YTD-by-quarter, multi-year). When given, the server ignores
26492678
``period_start`` / ``period_end`` / ``comparative``.
2679+
2680+
``entity_id`` is the entity the report is for; ``None`` = the entity
2681+
whose chart ``mapping_id`` maps from. Named alongside another entity's
2682+
mapping, the server refuses it.
26502683
"""
26512684
body = CreateReportRequest(
26522685
name=name,
@@ -2661,6 +2694,8 @@ def create_report(
26612694
body.periods = [
26622695
p if isinstance(p, PeriodSpec) else PeriodSpec.from_dict(p) for p in periods
26632696
]
2697+
if entity_id:
2698+
body.entity_id = entity_id
26642699
response = op_create_report(graph_id=graph_id, body=body, client=self._get_client())
26652700
envelope = self._call_op("Create report", response)
26662701
return self._typed_result("Create report", envelope, ReportResponse)

‎robosystems_client/graphql/generated/client.py‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def get_information_block(
250250
scenario_id: Union[Optional[str], UnsetType] = UNSET,
251251
series_history: Union[Optional[int], UnsetType] = UNSET,
252252
series_forecast: Union[Optional[int], UnsetType] = UNSET,
253+
entity_id: Union[Optional[str], UnsetType] = UNSET,
253254
**kwargs: Any,
254255
) -> GetInformationBlock:
255256
variables: dict[str, object] = {
@@ -258,6 +259,7 @@ def get_information_block(
258259
"series": series,
259260
"seriesHistory": series_history,
260261
"seriesForecast": series_forecast,
262+
"entityId": entity_id,
261263
}
262264
response = self.execute(
263265
query=GET_INFORMATION_BLOCK_GQL,
@@ -591,6 +593,7 @@ def list_information_blocks(
591593
limit: Union[Optional[int], UnsetType] = UNSET,
592594
offset: Union[Optional[int], UnsetType] = UNSET,
593595
scenario_id: Union[Optional[str], UnsetType] = UNSET,
596+
entity_id: Union[Optional[str], UnsetType] = UNSET,
594597
**kwargs: Any,
595598
) -> ListInformationBlocks:
596599
variables: dict[str, object] = {
@@ -599,6 +602,7 @@ def list_information_blocks(
599602
"limit": limit,
600603
"offset": offset,
601604
"scenarioId": scenario_id,
605+
"entityId": entity_id,
602606
}
603607
response = self.execute(
604608
query=LIST_INFORMATION_BLOCKS_GQL,
@@ -791,8 +795,10 @@ def list_ledger_journal_entries(
791795
data = self.get_data(response)
792796
return ListLedgerJournalEntries.model_validate(data)
793797

794-
def list_ledger_mappings(self, **kwargs: Any) -> ListLedgerMappings:
795-
variables: dict[str, object] = {}
798+
def list_ledger_mappings(
799+
self, entity_id: Union[Optional[str], UnsetType] = UNSET, **kwargs: Any
800+
) -> ListLedgerMappings:
801+
variables: dict[str, object] = {"entityId": entity_id}
796802
response = self.execute(
797803
query=LIST_LEDGER_MAPPINGS_GQL,
798804
operation_name="ListLedgerMappings",
@@ -916,8 +922,16 @@ def list_ledger_unmapped_elements(
916922
data = self.get_data(response)
917923
return ListLedgerUnmappedElements.model_validate(data)
918924

919-
def mapping_candidates(self, classification: str, **kwargs: Any) -> MappingCandidates:
920-
variables: dict[str, object] = {"classification": classification}
925+
def mapping_candidates(
926+
self,
927+
classification: str,
928+
entity_id: Union[Optional[str], UnsetType] = UNSET,
929+
**kwargs: Any,
930+
) -> MappingCandidates:
931+
variables: dict[str, object] = {
932+
"classification": classification,
933+
"entityId": entity_id,
934+
}
921935
response = self.execute(
922936
query=MAPPING_CANDIDATES_GQL,
923937
operation_name="MappingCandidates",

‎robosystems_client/graphql/generated/get_information_block.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class GetInformationBlockInformationBlock(BaseModel):
1919
category: str
2020
taxonomy_id: Optional[str] = Field(alias="taxonomyId")
2121
taxonomy_name: Optional[str] = Field(alias="taxonomyName")
22+
entity_id: Optional[str] = Field(alias="entityId")
2223
information_model: "GetInformationBlockInformationBlockInformationModel" = Field(
2324
alias="informationModel"
2425
)

‎robosystems_client/graphql/generated/list_information_blocks.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ListInformationBlocksInformationBlocks(BaseModel):
1919
category: str
2020
taxonomy_id: Optional[str] = Field(alias="taxonomyId")
2121
taxonomy_name: Optional[str] = Field(alias="taxonomyName")
22+
entity_id: Optional[str] = Field(alias="entityId")
2223
information_model: "ListInformationBlocksInformationBlocksInformationModel" = Field(
2324
alias="informationModel"
2425
)

‎robosystems_client/graphql/generated/list_ledger_mappings.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ListLedgerMappingsMappingsStructures(BaseModel):
2121
taxonomy_id: str = Field(alias="taxonomyId")
2222
is_active: bool = Field(alias="isActive")
2323
framework: Optional[str]
24+
entity_id: Optional[str] = Field(alias="entityId")
2425

2526

2627
ListLedgerMappings.model_rebuild()

‎robosystems_client/graphql/generated/operations.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,14 @@
279279
"""
280280

281281
GET_INFORMATION_BLOCK_GQL = """
282-
query GetInformationBlock($id: ID!, $scenarioId: String, $series: Boolean! = false, $seriesHistory: Int, $seriesForecast: Int) {
282+
query GetInformationBlock($id: ID!, $scenarioId: String, $series: Boolean! = false, $seriesHistory: Int, $seriesForecast: Int, $entityId: String) {
283283
informationBlock(
284284
id: $id
285285
scenarioId: $scenarioId
286286
series: $series
287287
seriesHistory: $seriesHistory
288288
seriesForecast: $seriesForecast
289+
entityId: $entityId
289290
) {
290291
id
291292
blockType
@@ -294,6 +295,7 @@
294295
category
295296
taxonomyId
296297
taxonomyName
298+
entityId
297299
informationModel {
298300
conceptArrangement
299301
memberArrangement
@@ -1192,13 +1194,14 @@
11921194
"""
11931195

11941196
LIST_INFORMATION_BLOCKS_GQL = """
1195-
query ListInformationBlocks($blockType: String, $category: String, $limit: Int, $offset: Int, $scenarioId: String) {
1197+
query ListInformationBlocks($blockType: String, $category: String, $limit: Int, $offset: Int, $scenarioId: String, $entityId: String) {
11961198
informationBlocks(
11971199
blockType: $blockType
11981200
category: $category
11991201
limit: $limit
12001202
offset: $offset
12011203
scenarioId: $scenarioId
1204+
entityId: $entityId
12021205
) {
12031206
id
12041207
blockType
@@ -1207,6 +1210,7 @@
12071210
category
12081211
taxonomyId
12091212
taxonomyName
1213+
entityId
12101214
informationModel {
12111215
conceptArrangement
12121216
memberArrangement
@@ -1608,8 +1612,8 @@
16081612
"""
16091613

16101614
LIST_LEDGER_MAPPINGS_GQL = """
1611-
query ListLedgerMappings {
1612-
mappings {
1615+
query ListLedgerMappings($entityId: String) {
1616+
mappings(entityId: $entityId) {
16131617
structures {
16141618
id
16151619
name
@@ -1618,6 +1622,7 @@
16181622
taxonomyId
16191623
isActive
16201624
framework
1625+
entityId
16211626
}
16221627
}
16231628
}
@@ -1840,8 +1845,8 @@
18401845
"""
18411846

18421847
MAPPING_CANDIDATES_GQL = """
1843-
query MappingCandidates($classification: String!) {
1844-
mappingCandidates(classification: $classification) {
1848+
query MappingCandidates($classification: String!, $entityId: String) {
1849+
mappingCandidates(classification: $classification, entityId: $entityId) {
18451850
id
18461851
name
18471852
qname

‎robosystems_client/graphql/operations/ledger/GetInformationBlock.graphql‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ query GetInformationBlock(
44
$series: Boolean! = false
55
$seriesHistory: Int
66
$seriesForecast: Int
7+
$entityId: String
78
) {
89
informationBlock(
910
id: $id
1011
scenarioId: $scenarioId
1112
series: $series
1213
seriesHistory: $seriesHistory
1314
seriesForecast: $seriesForecast
15+
entityId: $entityId
1416
) {
1517
id blockType name displayName category
16-
taxonomyId taxonomyName
18+
taxonomyId taxonomyName entityId
1719
informationModel { conceptArrangement memberArrangement }
1820
artifact { topic rendererNote template mechanics }
1921
elements {

‎robosystems_client/graphql/operations/ledger/ListInformationBlocks.graphql‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ query ListInformationBlocks(
44
$limit: Int
55
$offset: Int
66
$scenarioId: String
7+
$entityId: String
78
) {
89
informationBlocks(
910
blockType: $blockType
1011
category: $category
1112
limit: $limit
1213
offset: $offset
1314
scenarioId: $scenarioId
15+
entityId: $entityId
1416
) {
1517
id blockType name displayName category
16-
taxonomyId taxonomyName
18+
taxonomyId taxonomyName entityId
1719
informationModel { conceptArrangement memberArrangement }
1820
artifact { topic rendererNote template mechanics }
1921
elements {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
query ListLedgerMappings {
2-
mappings {
1+
query ListLedgerMappings($entityId: String) {
2+
mappings(entityId: $entityId) {
33
structures {
4-
id name description blockType taxonomyId isActive framework
4+
id name description blockType taxonomyId isActive framework entityId
55
}
66
}
77
}

‎robosystems_client/graphql/operations/ledger/MappingCandidates.graphql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
query MappingCandidates($classification: String!) {
2-
mappingCandidates(classification: $classification) {
1+
query MappingCandidates($classification: String!, $entityId: String) {
2+
mappingCandidates(classification: $classification, entityId: $entityId) {
33
id
44
name
55
qname

0 commit comments

Comments
 (0)