Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions robosystems_client/clients/ledger_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@
ListLedgerReports,
ListLedgerReportsReportsReports,
)
from ..graphql.generated.list_ledger_journal_entries import (
ListLedgerJournalEntries,
)
from ..graphql.generated.list_ledger_journal_entries import (
ListLedgerJournalEntriesJournalEntries as LedgerJournalEntriesPage,
)
from ..graphql.generated.list_ledger_structures import (
ListLedgerStructures,
ListLedgerStructuresStructuresStructures,
Expand Down Expand Up @@ -403,6 +409,7 @@
LIST_LEDGER_ELEMENTS_GQL,
LIST_LEDGER_ENTITIES_GQL,
LIST_LEDGER_EVENT_BLOCKS_GQL,
LIST_LEDGER_JOURNAL_ENTRIES_GQL,
LIST_LEDGER_MAPPINGS_GQL,
LIST_LEDGER_PUBLISH_LISTS_GQL,
LIST_LEDGER_REPORTS_GQL,
Expand Down Expand Up @@ -871,6 +878,49 @@ def get_transaction(
)
return GetLedgerTransaction.model_validate(data).transaction

# ── Journal entries ─────────────────────────────────────────────────

def list_journal_entries(
self,
graph_id: str,
start_date: str | None = None,
end_date: str | None = None,
status: str | None = None,
type: str | None = None, # noqa: A002 — matches backend arg name
provenance: str | None = None,
transaction_id: str | None = None,
limit: int = 100,
offset: int = 0,
) -> LedgerJournalEntriesPage | None:
"""List journal entries with their line items, newest first.

The entry-centric read. Unlike :meth:`list_transactions`, which walks
transactions and hangs entries off them, this returns an entry
whether or not it has a parent transaction — and entries created by
the schedule engine and the event handlers have none, so they appear
in no transaction-based listing. ``transaction_id`` on each result is
``None`` for such a standalone entry rather than absent data.

Filter by ``provenance`` (``schedule_derived`` for what a period
close posted), ``type`` (``adjusting`` / ``closing``), ``status``, or
a parent ``transaction_id``.
"""
data = self._query(
graph_id,
LIST_LEDGER_JOURNAL_ENTRIES_GQL,
{
"startDate": start_date,
"endDate": end_date,
"status": status,
"type": type,
"provenance": provenance,
"transactionId": transaction_id,
"limit": limit,
"offset": offset,
},
)
return ListLedgerJournalEntries.model_validate(data).journal_entries

# ── Event blocks (inbox surface) ───────────────────────────────────

def list_event_blocks(
Expand Down
14 changes: 14 additions & 0 deletions robosystems_client/graphql/generated/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@
ListLedgerEventBlocks,
ListLedgerEventBlocksEventBlocks,
)
from .list_ledger_journal_entries import (
ListLedgerJournalEntries,
ListLedgerJournalEntriesJournalEntries,
ListLedgerJournalEntriesJournalEntriesEntries,
ListLedgerJournalEntriesJournalEntriesEntriesLineItems,
ListLedgerJournalEntriesJournalEntriesPagination,
)
from .list_ledger_mappings import (
ListLedgerMappings,
ListLedgerMappingsMappings,
Expand Down Expand Up @@ -350,6 +357,7 @@
LIST_LEDGER_ELEMENTS_GQL,
LIST_LEDGER_ENTITIES_GQL,
LIST_LEDGER_EVENT_BLOCKS_GQL,
LIST_LEDGER_JOURNAL_ENTRIES_GQL,
LIST_LEDGER_MAPPINGS_GQL,
LIST_LEDGER_PUBLISH_LISTS_GQL,
LIST_LEDGER_REPORTS_GQL,
Expand Down Expand Up @@ -558,6 +566,7 @@
"LIST_LEDGER_ELEMENTS_GQL",
"LIST_LEDGER_ENTITIES_GQL",
"LIST_LEDGER_EVENT_BLOCKS_GQL",
"LIST_LEDGER_JOURNAL_ENTRIES_GQL",
"LIST_LEDGER_MAPPINGS_GQL",
"LIST_LEDGER_PUBLISH_LISTS_GQL",
"LIST_LEDGER_REPORTS_GQL",
Expand Down Expand Up @@ -618,6 +627,11 @@
"ListLedgerEntitiesEntities",
"ListLedgerEventBlocks",
"ListLedgerEventBlocksEventBlocks",
"ListLedgerJournalEntries",
"ListLedgerJournalEntriesJournalEntries",
"ListLedgerJournalEntriesJournalEntriesEntries",
"ListLedgerJournalEntriesJournalEntriesEntriesLineItems",
"ListLedgerJournalEntriesJournalEntriesPagination",
"ListLedgerMappings",
"ListLedgerMappingsMappings",
"ListLedgerMappingsMappingsStructures",
Expand Down
33 changes: 33 additions & 0 deletions robosystems_client/graphql/generated/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from .list_ledger_elements import ListLedgerElements
from .list_ledger_entities import ListLedgerEntities
from .list_ledger_event_blocks import ListLedgerEventBlocks
from .list_ledger_journal_entries import ListLedgerJournalEntries
from .list_ledger_mappings import ListLedgerMappings
from .list_ledger_publish_lists import ListLedgerPublishLists
from .list_ledger_reports import ListLedgerReports
Expand Down Expand Up @@ -98,6 +99,7 @@
LIST_LEDGER_ELEMENTS_GQL,
LIST_LEDGER_ENTITIES_GQL,
LIST_LEDGER_EVENT_BLOCKS_GQL,
LIST_LEDGER_JOURNAL_ENTRIES_GQL,
LIST_LEDGER_MAPPINGS_GQL,
LIST_LEDGER_PUBLISH_LISTS_GQL,
LIST_LEDGER_REPORTS_GQL,
Expand Down Expand Up @@ -698,6 +700,37 @@ def list_ledger_event_blocks(
data = self.get_data(response)
return ListLedgerEventBlocks.model_validate(data)

def list_ledger_journal_entries(
self,
limit: int,
offset: int,
start_date: Union[Optional[str], UnsetType] = UNSET,
end_date: Union[Optional[str], UnsetType] = UNSET,
status: Union[Optional[str], UnsetType] = UNSET,
type_: Union[Optional[str], UnsetType] = UNSET,
provenance: Union[Optional[str], UnsetType] = UNSET,
transaction_id: Union[Optional[str], UnsetType] = UNSET,
**kwargs: Any,
) -> ListLedgerJournalEntries:
variables: dict[str, object] = {
"startDate": start_date,
"endDate": end_date,
"status": status,
"type": type_,
"provenance": provenance,
"transactionId": transaction_id,
"limit": limit,
"offset": offset,
}
response = self.execute(
query=LIST_LEDGER_JOURNAL_ENTRIES_GQL,
operation_name="ListLedgerJournalEntries",
variables=variables,
**kwargs,
)
data = self.get_data(response)
return ListLedgerJournalEntries.model_validate(data)

def list_ledger_mappings(self, **kwargs: Any) -> ListLedgerMappings:
variables: dict[str, object] = {}
response = self.execute(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from typing import Optional

from pydantic import Field

from .base_model import BaseModel


class ListLedgerJournalEntries(BaseModel):
journal_entries: Optional["ListLedgerJournalEntriesJournalEntries"] = Field(
alias="journalEntries"
)


class ListLedgerJournalEntriesJournalEntries(BaseModel):
entries: list["ListLedgerJournalEntriesJournalEntriesEntries"]
pagination: "ListLedgerJournalEntriesJournalEntriesPagination"


class ListLedgerJournalEntriesJournalEntriesEntries(BaseModel):
id: str
number: Optional[str]
transaction_id: Optional[str] = Field(alias="transactionId")
type_: str = Field(alias="type")
status: str
posting_date: str = Field(alias="postingDate")
memo: Optional[str]
provenance: Optional[str]
source_structure_id: Optional[str] = Field(alias="sourceStructureId")
source_structure_name: Optional[str] = Field(alias="sourceStructureName")
triggered_by_event_id: Optional[str] = Field(alias="triggeredByEventId")
reversal_of: Optional[str] = Field(alias="reversalOf")
posted_at: Optional[str] = Field(alias="postedAt")
total_debit: float = Field(alias="totalDebit")
total_credit: float = Field(alias="totalCredit")
balanced: bool
line_items: list["ListLedgerJournalEntriesJournalEntriesEntriesLineItems"] = Field(
alias="lineItems"
)


class ListLedgerJournalEntriesJournalEntriesEntriesLineItems(BaseModel):
id: str
account_id: str = Field(alias="accountId")
account_name: Optional[str] = Field(alias="accountName")
account_code: Optional[str] = Field(alias="accountCode")
debit_amount: float = Field(alias="debitAmount")
credit_amount: float = Field(alias="creditAmount")
description: Optional[str]
line_order: int = Field(alias="lineOrder")


class ListLedgerJournalEntriesJournalEntriesPagination(BaseModel):
total: int
limit: int
offset: int
has_more: bool = Field(alias="hasMore")


ListLedgerJournalEntries.model_rebuild()
ListLedgerJournalEntriesJournalEntries.model_rebuild()
ListLedgerJournalEntriesJournalEntriesEntries.model_rebuild()
51 changes: 51 additions & 0 deletions robosystems_client/graphql/generated/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"LIST_LEDGER_ELEMENTS_GQL",
"LIST_LEDGER_ENTITIES_GQL",
"LIST_LEDGER_EVENT_BLOCKS_GQL",
"LIST_LEDGER_JOURNAL_ENTRIES_GQL",
"LIST_LEDGER_MAPPINGS_GQL",
"LIST_LEDGER_PUBLISH_LISTS_GQL",
"LIST_LEDGER_REPORTS_GQL",
Expand Down Expand Up @@ -1491,6 +1492,56 @@
}
"""

LIST_LEDGER_JOURNAL_ENTRIES_GQL = """
query ListLedgerJournalEntries($startDate: Date, $endDate: Date, $status: String, $type: String, $provenance: String, $transactionId: String, $limit: Int! = 100, $offset: Int! = 0) {
journalEntries(
startDate: $startDate
endDate: $endDate
status: $status
type: $type
provenance: $provenance
transactionId: $transactionId
limit: $limit
offset: $offset
) {
entries {
id
number
transactionId
type
status
postingDate
memo
provenance
sourceStructureId
sourceStructureName
triggeredByEventId
reversalOf
postedAt
totalDebit
totalCredit
balanced
lineItems {
id
accountId
accountName
accountCode
debitAmount
creditAmount
description
lineOrder
}
}
pagination {
total
limit
offset
hasMore
}
}
}
"""

LIST_LEDGER_MAPPINGS_GQL = """
query ListLedgerMappings {
mappings {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
query ListLedgerJournalEntries(
$startDate: Date
$endDate: Date
$status: String
$type: String
$provenance: String
$transactionId: String
$limit: Int! = 100
$offset: Int! = 0
) {
journalEntries(
startDate: $startDate
endDate: $endDate
status: $status
type: $type
provenance: $provenance
transactionId: $transactionId
limit: $limit
offset: $offset
) {
entries {
id number transactionId type status postingDate memo
provenance sourceStructureId sourceStructureName
triggeredByEventId reversalOf postedAt
totalDebit totalCredit balanced
lineItems {
id accountId accountName accountCode
debitAmount creditAmount description lineOrder
}
}
pagination { total limit offset hasMore }
}
}
Loading