Ledgers Sub Service - Nioron07/Easy-Acumatica GitHub Wiki
This guide covers the LedgersService
, which provides a straightforward way to retrieve a list of Ledgers from your Acumatica instance.
1. Importing Helpers
Before you start, import the necessary helpers for building queries.
from easy_acumatica.models.query_builder import QueryOptions
from easy_acumatica.models.filter_builder import F
2. Retrieving Ledgers
get_ledgers(api_version, options=None)
This is the main method for fetching a list of ledger records. It can be used to get all ledgers or a filtered subset by using QueryOptions
.
Example 1: Get all ledgers with expanded details
This example retrieves all ledgers and uses $expand
to also fetch the companies and branches associated with each ledger.
# Use QueryOptions to select specific fields and expand related entities
opts = QueryOptions(
select="LedgerID,Description,Branches/BranchID,Companies/Company",
expand="Branches,Companies"
)
# Fetch the ledgers
ledgers = client.ledgers.get_ledgers("24.200.001", options=opts)
for ledger in ledgers:
print(f"Ledger ID: {ledger['LedgerID']['value']}")
# Print associated branches
for branch in ledger.get("Branches", []):
print(f" - Branch: {branch['BranchID']['value']}")
Example 2: Get a specific ledger by its ID
You can use a filter to retrieve a single, specific ledger.
# Create a filter for the 'ACTUAL' ledger
ledger_filter = (F.LedgerID == 'ACTUAL')
opts = QueryOptions(filter=ledger_filter)
# Fetch the specific ledger
actual_ledger_list = client.ledgers.get_ledgers("24.200.001", options=opts)
if actual_ledger_list:
actual_ledger = actual_ledger_list[0]
print(f"Found ledger: {actual_ledger['Description']['value']}")