Work Calendars Service
This guide covers the `WorkCalendarsService`, which is your primary tool for creating and retrieving work calendar records through the contract-based API.
According to the service notes, the get_work_calendar endpoint may only return basic information like ID, Description, and Time Zone, not the detailed day-by-day exceptions or schedules.
Importing Helpers
Before you start, import the necessary builders and query helpers.
from easy_acumatica.models.work_calendar_builder import WorkCalendarBuilder
from easy_acumatica.models.query_builder import QueryOptions
from easy_acumatica.filters import F
Service Methods
create_work_calendar(api_version, builder, options=None)
This method creates a new work calendar. You must provide a `WorkCalendarBuilder` instance containing the calendar's details.
# 1. Build the work calendar payload
# This assumes a WorkCalendarBuilder with methods like calendar_id, time_zone, and add_exception
calendar_payload = (
WorkCalendarBuilder()
.calendar_id("US-HOLIDAYS")
.time_zone("CST")
.add_exception(date="2024-12-25", description="Christmas Day")
)
# 2. Use the payload to create the record
try:
new_calendar = client.work_calendars.create_work_calendar("24.200.001", builder=calendar_payload)
print(f"Successfully created Work Calendar: {new_calendar['CalendarID']['value']}")
except Exception as e:
print(f"Failed to create work calendar: {e}")
get_work_calendar(api_version, options=None)
This method retrieves a list of work calendars. You must use `QueryOptions` to filter for the calendar you want.
# 1. Define query options
query = QueryOptions(filter=F.CalendarID == 'US-HOLIDAYS')
# 2. Retrieve the work calendar(s)
try:
calendars = client.work_calendars.get_work_calendar("24.200.001", options=query)
for calendar in calendars:
print(f"ID: {calendar['CalendarID']['value']}, Time Zone: {calendar['TimeZone']['value']}")
except Exception as e:
print(f"Failed to get work calendars: {e}")
ON THIS PAGE
Introduction
Importing Helpers
Service Methods
- create_work_calendar
- get_work_calendar