Skip to content

Commit fef49cc

Browse files
committed
Enhance LedgerClient with new schedule and closing entry functionalities
- Added methods for creating and listing schedules, retrieving schedule facts, and checking period close status in the LedgerClient. - Introduced a method for creating draft closing entries from schedule facts. - Updated imports to include new API endpoints related to schedules and closing entries. - Removed the old mapping association request model in favor of a more generic association request model. These enhancements improve the LedgerClient's capabilities for managing financial schedules and closing entries.
1 parent 24910e9 commit fef49cc

16 files changed

Lines changed: 4193 additions & 12 deletions

‎robosystems_client/extensions/ledger_client.py‎

Lines changed: 175 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
from typing import Any
1111

1212
from ..api.ledger.auto_map_elements import sync_detailed as auto_map_elements
13+
from ..api.ledger.create_closing_entry import sync_detailed as create_closing_entry
1314
from ..api.ledger.create_mapping_association import (
1415
sync_detailed as create_mapping_association,
1516
)
17+
from ..api.ledger.create_schedule import sync_detailed as create_schedule
1618
from ..api.ledger.create_structure import sync_detailed as create_structure
1719
from ..api.ledger.delete_mapping_association import (
1820
sync_detailed as delete_mapping_association,
1921
)
22+
from ..api.ledger.get_account_rollups import sync_detailed as get_account_rollups
23+
from ..api.ledger.get_closing_book_structures import (
24+
sync_detailed as get_closing_book_structures,
25+
)
2026
from ..api.ledger.get_ledger_account_tree import (
2127
sync_detailed as get_ledger_account_tree,
2228
)
@@ -35,9 +41,13 @@
3541
sync_detailed as get_mapping_coverage,
3642
)
3743
from ..api.ledger.get_mapping_detail import sync_detailed as get_mapping_detail
44+
from ..api.ledger.get_period_close_status import (
45+
sync_detailed as get_period_close_status,
46+
)
3847
from ..api.ledger.get_reporting_taxonomy import (
3948
sync_detailed as get_reporting_taxonomy,
4049
)
50+
from ..api.ledger.get_schedule_facts import sync_detailed as get_schedule_facts
4151
from ..api.ledger.list_elements import sync_detailed as list_elements
4252
from ..api.ledger.list_ledger_accounts import (
4353
sync_detailed as list_ledger_accounts,
@@ -46,6 +56,7 @@
4656
sync_detailed as list_ledger_transactions,
4757
)
4858
from ..api.ledger.list_mappings import sync_detailed as list_mappings
59+
from ..api.ledger.list_schedules import sync_detailed as list_schedules
4960
from ..api.ledger.list_structures import sync_detailed as list_structures
5061
from ..client import AuthenticatedClient
5162

@@ -280,11 +291,9 @@ def create_mapping(
280291
confidence: float = 1.0,
281292
) -> None:
282293
"""Create a manual mapping association (CoA element → GAAP element)."""
283-
from ..models.create_mapping_association_request import (
284-
CreateMappingAssociationRequest,
285-
)
294+
from ..models.create_association_request import CreateAssociationRequest
286295

287-
body = CreateMappingAssociationRequest(
296+
body = CreateAssociationRequest(
288297
from_element_id=from_element_id,
289298
to_element_id=to_element_id,
290299
confidence=confidence,
@@ -314,3 +323,165 @@ def auto_map(self, graph_id: str, mapping_id: str) -> dict[str, Any]:
314323
if response.status_code != HTTPStatus.ACCEPTED:
315324
raise RuntimeError(f"Auto-map failed: {response.status_code}")
316325
return response.parsed or {}
326+
327+
# ── Schedules ──────────────────────────────────────────────────────
328+
329+
def create_schedule(
330+
self,
331+
graph_id: str,
332+
*,
333+
name: str,
334+
element_ids: list[str],
335+
period_start: str,
336+
period_end: str,
337+
monthly_amount: int,
338+
debit_element_id: str,
339+
credit_element_id: str,
340+
entry_type: str = "closing",
341+
memo_template: str = "",
342+
taxonomy_id: str | None = None,
343+
method: str | None = None,
344+
original_amount: int | None = None,
345+
residual_value: int | None = None,
346+
useful_life_months: int | None = None,
347+
asset_element_id: str | None = None,
348+
auto_reverse: bool = False,
349+
) -> Any:
350+
"""Create a schedule with pre-generated monthly facts."""
351+
body: dict[str, Any] = {
352+
"name": name,
353+
"element_ids": element_ids,
354+
"period_start": period_start,
355+
"period_end": period_end,
356+
"monthly_amount": monthly_amount,
357+
"entry_template": {
358+
"debit_element_id": debit_element_id,
359+
"credit_element_id": credit_element_id,
360+
"entry_type": entry_type,
361+
"memo_template": memo_template,
362+
"auto_reverse": auto_reverse,
363+
},
364+
}
365+
if taxonomy_id:
366+
body["taxonomy_id"] = taxonomy_id
367+
schedule_metadata: dict[str, Any] = {}
368+
if method:
369+
schedule_metadata["method"] = method
370+
if original_amount is not None:
371+
schedule_metadata["original_amount"] = original_amount
372+
if residual_value is not None:
373+
schedule_metadata["residual_value"] = residual_value
374+
if useful_life_months is not None:
375+
schedule_metadata["useful_life_months"] = useful_life_months
376+
if asset_element_id:
377+
schedule_metadata["asset_element_id"] = asset_element_id
378+
if schedule_metadata:
379+
body["schedule_metadata"] = schedule_metadata
380+
381+
response = create_schedule(graph_id=graph_id, body=body, client=self._get_client())
382+
if response.status_code != HTTPStatus.CREATED:
383+
raise RuntimeError(f"Create schedule failed: {response.status_code}")
384+
return response.parsed
385+
386+
def list_schedules(self, graph_id: str) -> Any:
387+
"""List all active schedule structures."""
388+
response = list_schedules(graph_id=graph_id, client=self._get_client())
389+
if response.status_code != HTTPStatus.OK:
390+
raise RuntimeError(f"List schedules failed: {response.status_code}")
391+
return response.parsed
392+
393+
def get_schedule_facts(
394+
self,
395+
graph_id: str,
396+
structure_id: str,
397+
period_start: str | None = None,
398+
period_end: str | None = None,
399+
) -> Any:
400+
"""Get fact values for a schedule, optionally filtered by period."""
401+
response = get_schedule_facts(
402+
graph_id=graph_id,
403+
structure_id=structure_id,
404+
period_start=period_start,
405+
period_end=period_end,
406+
client=self._get_client(),
407+
)
408+
if response.status_code != HTTPStatus.OK:
409+
raise RuntimeError(f"Get schedule facts failed: {response.status_code}")
410+
return response.parsed
411+
412+
def get_period_close_status(
413+
self,
414+
graph_id: str,
415+
period_start: str,
416+
period_end: str,
417+
) -> Any:
418+
"""Get close status for all schedules in a fiscal period."""
419+
response = get_period_close_status(
420+
graph_id=graph_id,
421+
period_start=period_start,
422+
period_end=period_end,
423+
client=self._get_client(),
424+
)
425+
if response.status_code != HTTPStatus.OK:
426+
raise RuntimeError(f"Get period close status failed: {response.status_code}")
427+
return response.parsed
428+
429+
def create_closing_entry(
430+
self,
431+
graph_id: str,
432+
structure_id: str,
433+
posting_date: str,
434+
period_start: str,
435+
period_end: str,
436+
memo: str | None = None,
437+
) -> Any:
438+
"""Create a draft closing entry from a schedule's facts for a period."""
439+
body: dict[str, Any] = {
440+
"posting_date": posting_date,
441+
"period_start": period_start,
442+
"period_end": period_end,
443+
}
444+
if memo:
445+
body["memo"] = memo
446+
447+
response = create_closing_entry(
448+
graph_id=graph_id,
449+
structure_id=structure_id,
450+
body=body,
451+
client=self._get_client(),
452+
)
453+
if response.status_code != HTTPStatus.CREATED:
454+
raise RuntimeError(f"Create closing entry failed: {response.status_code}")
455+
return response.parsed
456+
457+
# ── Closing Book ─────────────────────────────────────────────────────
458+
459+
def get_closing_book_structures(self, graph_id: str) -> Any:
460+
"""Get all closing book structure categories for the sidebar."""
461+
response = get_closing_book_structures(graph_id=graph_id, client=self._get_client())
462+
if response.status_code != HTTPStatus.OK:
463+
raise RuntimeError(f"Get closing book structures failed: {response.status_code}")
464+
return response.parsed
465+
466+
def get_account_rollups(
467+
self,
468+
graph_id: str,
469+
mapping_id: str | None = None,
470+
start_date: str | None = None,
471+
end_date: str | None = None,
472+
) -> Any:
473+
"""Get account rollups — CoA accounts grouped by reporting element with balances.
474+
475+
Shows how company-specific accounts roll up to standardized reporting lines.
476+
Auto-discovers the mapping structure if mapping_id is not provided.
477+
"""
478+
response = get_account_rollups(
479+
graph_id=graph_id,
480+
mapping_id=mapping_id,
481+
start_date=start_date,
482+
end_date=end_date,
483+
client=self._get_client(),
484+
)
485+
if response.status_code != HTTPStatus.OK:
486+
raise RuntimeError(f"Get account rollups failed: {response.status_code}")
487+
return response.parsed

‎robosystems_client/extensions/tests/__init__.py‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)