Skip to content

Commit 903aa64

Browse files
committed
Remove ReportClient references and implement report handling in LedgerClient
This commit removes the `ReportClient` from the `__init__.py` and `facade.py` files, consolidating report-related functionality within the `LedgerClient`. The `LedgerClient` now includes methods for creating, listing, retrieving, regenerating, deleting, and sharing reports, enhancing its capabilities and maintaining backward compatibility through an alias for report handling. Key Changes: - Removed `ReportClient` imports and references. - Added report handling methods to `LedgerClient`, including `create_report`, `list_reports`, `get_report`, `regenerate_report`, `delete_report`, and `share_report`. - Updated internal documentation to reflect the new report handling structure. These changes streamline the client architecture and improve the organization of report-related operations.
1 parent 9e87387 commit 903aa64

3 files changed

Lines changed: 223 additions & 4 deletions

File tree

‎robosystems_client/clients/__init__.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
)
5050
from .investor_client import InvestorClient
5151
from .ledger_client import LedgerClient
52-
from .report_client import ReportClient
5352
from .facade import (
5453
RoboSystemsClients,
5554
RoboSystemsClientConfig,
@@ -168,7 +167,6 @@
168167
# Investor Client
169168
"InvestorClient",
170169
# Report Client
171-
"ReportClient",
172170
# Utilities
173171
"QueryBuilder",
174172
"ResultProcessor",

‎robosystems_client/clients/facade.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from .graph_client import GraphClient
1616
from .investor_client import InvestorClient
1717
from .ledger_client import LedgerClient
18-
from .report_client import ReportClient
1918
from .sse_client import SSEClient
2019

2120

@@ -74,7 +73,7 @@ def __init__(self, config: RoboSystemsClientConfig = None):
7473
self.graphs = GraphClient(self.config)
7574
self.ledger = LedgerClient(self.config)
7675
self.investor = InvestorClient(self.config)
77-
self.reports = ReportClient(self.config)
76+
self.reports = self.ledger # backward compat alias
7877

7978
def monitor_operation(
8079
self, operation_id: str, on_progress: Optional[Callable] = None

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,33 @@
8686
from ..api.extensions_robo_ledger.op_update_taxonomy import (
8787
sync_detailed as op_update_taxonomy,
8888
)
89+
from ..api.extensions_robo_ledger.op_add_publish_list_members import (
90+
sync_detailed as op_add_publish_list_members,
91+
)
92+
from ..api.extensions_robo_ledger.op_create_publish_list import (
93+
sync_detailed as op_create_publish_list,
94+
)
95+
from ..api.extensions_robo_ledger.op_create_report import (
96+
sync_detailed as op_create_report,
97+
)
98+
from ..api.extensions_robo_ledger.op_delete_publish_list import (
99+
sync_detailed as op_delete_publish_list,
100+
)
101+
from ..api.extensions_robo_ledger.op_delete_report import (
102+
sync_detailed as op_delete_report,
103+
)
104+
from ..api.extensions_robo_ledger.op_regenerate_report import (
105+
sync_detailed as op_regenerate_report,
106+
)
107+
from ..api.extensions_robo_ledger.op_remove_publish_list_member import (
108+
sync_detailed as op_remove_publish_list_member,
109+
)
110+
from ..api.extensions_robo_ledger.op_share_report import (
111+
sync_detailed as op_share_report,
112+
)
113+
from ..api.extensions_robo_ledger.op_update_publish_list import (
114+
sync_detailed as op_update_publish_list,
115+
)
89116
from ..api.extensions_robo_ledger.op_create_associations import (
90117
sync_detailed as op_create_associations,
91118
)
@@ -174,6 +201,19 @@
174201
parse_trial_balance,
175202
parse_unmapped_elements,
176203
)
204+
from ..graphql.queries.ledger import (
205+
GET_PUBLISH_LIST_QUERY,
206+
GET_REPORT_QUERY,
207+
GET_STATEMENT_QUERY,
208+
LIST_PUBLISH_LISTS_QUERY,
209+
LIST_REPORTS_QUERY,
210+
parse_publish_list,
211+
parse_publish_lists,
212+
parse_report,
213+
parse_reports,
214+
parse_statement,
215+
)
216+
from ..models.add_publish_list_members_operation import AddPublishListMembersOperation
177217
from ..models.auto_map_elements_operation import AutoMapElementsOperation
178218
from ..models.bulk_association_item import BulkAssociationItem
179219
from ..models.bulk_create_associations_request import BulkCreateAssociationsRequest
@@ -214,7 +254,17 @@
214254
)
215255
from ..models.initialize_ledger_request import InitializeLedgerRequest
216256
from ..models.manual_line_item_request import ManualLineItemRequest
257+
from ..models.create_publish_list_request import CreatePublishListRequest
258+
from ..models.create_report_request import CreateReportRequest
259+
from ..models.delete_publish_list_operation import DeletePublishListOperation
260+
from ..models.delete_report_operation import DeleteReportOperation
217261
from ..models.operation_envelope import OperationEnvelope
262+
from ..models.regenerate_report_operation import RegenerateReportOperation
263+
from ..models.remove_publish_list_member_operation import (
264+
RemovePublishListMemberOperation,
265+
)
266+
from ..models.share_report_operation import ShareReportOperation
267+
from ..models.update_publish_list_operation import UpdatePublishListOperation
218268
from ..models.reopen_period_operation import ReopenPeriodOperation
219269
from ..models.set_close_target_operation import SetCloseTargetOperation
220270
from ..models.truncate_schedule_operation import TruncateScheduleOperation
@@ -1142,3 +1192,175 @@ def reopen_period(
11421192
response = op_reopen_period(graph_id=graph_id, body=body, client=self._get_client())
11431193
envelope = self._call_op("Reopen period", response)
11441194
return envelope.result or {}
1195+
1196+
# ── Reports ─────────────────────────────────────────────────────────
1197+
1198+
def create_report(
1199+
self,
1200+
graph_id: str,
1201+
name: str,
1202+
mapping_id: str,
1203+
period_start: str,
1204+
period_end: str,
1205+
taxonomy_id: str = "tax_usgaap_reporting",
1206+
period_type: str = "quarterly",
1207+
comparative: bool = True,
1208+
) -> dict[str, Any]:
1209+
"""Kick off report creation (async). Returns an operation ack."""
1210+
body = CreateReportRequest(
1211+
name=name,
1212+
mapping_id=mapping_id,
1213+
period_start=period_start,
1214+
period_end=period_end,
1215+
taxonomy_id=taxonomy_id,
1216+
period_type=period_type,
1217+
comparative=comparative,
1218+
)
1219+
response = op_create_report(graph_id=graph_id, body=body, client=self._get_client())
1220+
envelope = self._call_op("Create report", response)
1221+
return {"operation_id": envelope.operation_id, "status": envelope.status}
1222+
1223+
def list_reports(self, graph_id: str) -> list[dict[str, Any]]:
1224+
"""List all reports for a graph (includes received shared reports)."""
1225+
data = self._query(graph_id, LIST_REPORTS_QUERY)
1226+
return parse_reports(data)
1227+
1228+
def get_report(self, graph_id: str, report_id: str) -> dict[str, Any] | None:
1229+
"""Get a single report with its period list + available structures."""
1230+
data = self._query(graph_id, GET_REPORT_QUERY, {"reportId": report_id})
1231+
return parse_report(data)
1232+
1233+
def get_statement(
1234+
self, graph_id: str, report_id: str, structure_type: str
1235+
) -> dict[str, Any] | None:
1236+
"""Render a financial statement — facts viewed through a structure.
1237+
1238+
`structure_type`: income_statement, balance_sheet, cash_flow_statement, ...
1239+
"""
1240+
data = self._query(
1241+
graph_id,
1242+
GET_STATEMENT_QUERY,
1243+
{"reportId": report_id, "structureType": structure_type},
1244+
)
1245+
return parse_statement(data)
1246+
1247+
def regenerate_report(
1248+
self,
1249+
graph_id: str,
1250+
report_id: str,
1251+
period_start: str | None = None,
1252+
period_end: str | None = None,
1253+
) -> dict[str, Any]:
1254+
"""Regenerate an existing report (async). Returns an operation ack."""
1255+
body = RegenerateReportOperation(
1256+
report_id=report_id,
1257+
period_start=period_start if period_start is not None else UNSET,
1258+
period_end=period_end if period_end is not None else UNSET,
1259+
)
1260+
response = op_regenerate_report(
1261+
graph_id=graph_id, body=body, client=self._get_client()
1262+
)
1263+
envelope = self._call_op("Regenerate report", response)
1264+
return {"operation_id": envelope.operation_id, "status": envelope.status}
1265+
1266+
def delete_report(self, graph_id: str, report_id: str) -> None:
1267+
"""Delete a report and its generated facts."""
1268+
body = DeleteReportOperation(report_id=report_id)
1269+
response = op_delete_report(graph_id=graph_id, body=body, client=self._get_client())
1270+
self._call_op("Delete report", response)
1271+
1272+
def share_report(
1273+
self, graph_id: str, report_id: str, publish_list_id: str
1274+
) -> dict[str, Any]:
1275+
"""Share a published report to every member of a publish list (async)."""
1276+
body = ShareReportOperation(report_id=report_id, publish_list_id=publish_list_id)
1277+
response = op_share_report(graph_id=graph_id, body=body, client=self._get_client())
1278+
envelope = self._call_op("Share report", response)
1279+
return {"operation_id": envelope.operation_id, "status": envelope.status}
1280+
1281+
def is_shared_report(self, report: dict[str, Any] | Any) -> bool:
1282+
"""Check if a report was received via sharing (vs locally created)."""
1283+
if isinstance(report, dict):
1284+
return report.get("source_graph_id") is not None
1285+
return getattr(report, "source_graph_id", None) is not None
1286+
1287+
# ── Publish Lists ────────────────────────────────────────────────────
1288+
1289+
def list_publish_lists(
1290+
self, graph_id: str, limit: int = 100, offset: int = 0
1291+
) -> dict[str, Any] | None:
1292+
"""List publish lists with pagination."""
1293+
data = self._query(
1294+
graph_id, LIST_PUBLISH_LISTS_QUERY, {"limit": limit, "offset": offset}
1295+
)
1296+
return parse_publish_lists(data)
1297+
1298+
def get_publish_list(self, graph_id: str, list_id: str) -> dict[str, Any] | None:
1299+
"""Get a single publish list with its full member list."""
1300+
data = self._query(graph_id, GET_PUBLISH_LIST_QUERY, {"listId": list_id})
1301+
return parse_publish_list(data)
1302+
1303+
def create_publish_list(
1304+
self, graph_id: str, name: str, description: str | None = None
1305+
) -> dict[str, Any]:
1306+
"""Create a new publish list."""
1307+
body = CreatePublishListRequest(
1308+
name=name,
1309+
description=description if description is not None else UNSET,
1310+
)
1311+
response = op_create_publish_list(
1312+
graph_id=graph_id, body=body, client=self._get_client()
1313+
)
1314+
envelope = self._call_op("Create publish list", response)
1315+
return envelope.result or {}
1316+
1317+
def update_publish_list(
1318+
self,
1319+
graph_id: str,
1320+
list_id: str,
1321+
name: str | None = None,
1322+
description: str | None = None,
1323+
) -> dict[str, Any]:
1324+
"""Update a publish list's name or description."""
1325+
body = UpdatePublishListOperation(
1326+
list_id=list_id,
1327+
name=name if name is not None else UNSET,
1328+
description=description if description is not None else UNSET,
1329+
)
1330+
response = op_update_publish_list(
1331+
graph_id=graph_id, body=body, client=self._get_client()
1332+
)
1333+
envelope = self._call_op("Update publish list", response)
1334+
return envelope.result or {}
1335+
1336+
def delete_publish_list(self, graph_id: str, list_id: str) -> None:
1337+
"""Delete a publish list."""
1338+
body = DeletePublishListOperation(list_id=list_id)
1339+
response = op_delete_publish_list(
1340+
graph_id=graph_id, body=body, client=self._get_client()
1341+
)
1342+
self._call_op("Delete publish list", response)
1343+
1344+
def add_publish_list_members(
1345+
self, graph_id: str, list_id: str, target_graph_ids: list[str]
1346+
) -> dict[str, Any]:
1347+
"""Add target graphs as members of a publish list."""
1348+
body = AddPublishListMembersOperation(
1349+
list_id=list_id, target_graph_ids=target_graph_ids
1350+
)
1351+
response = op_add_publish_list_members(
1352+
graph_id=graph_id, body=body, client=self._get_client()
1353+
)
1354+
envelope = self._call_op("Add publish list members", response)
1355+
return envelope.result or {}
1356+
1357+
def remove_publish_list_member(
1358+
self, graph_id: str, list_id: str, member_id: str
1359+
) -> dict[str, Any]:
1360+
"""Remove a single member from a publish list."""
1361+
body = RemovePublishListMemberOperation(list_id=list_id, member_id=member_id)
1362+
response = op_remove_publish_list_member(
1363+
graph_id=graph_id, body=body, client=self._get_client()
1364+
)
1365+
envelope = self._call_op("Remove publish list member", response)
1366+
return envelope.result if envelope.result is not None else {"deleted": True}

0 commit comments

Comments
 (0)