WorkCalendarBuilder
The `WorkCalendarBuilder` is your primary tool for creating the JSON payload needed to create `WorkCalendar` records with the `WorkCalendarsService`.
As noted in the builder's source code, there is currently no public method to add calendar exceptions or define specific workdays through this builder.
Importing the Builder
To get started, import the `WorkCalendarBuilder` from the `easy_acumatica.models` module.
from easy_acumatica.models.work_calendar_builder import WorkCalendarBuilder
Builder Methods
Shortcut Methods
Use the shortcut methods to set the most common fields for a work calendar.
calendar_payload = (
WorkCalendarBuilder()
.work_calendar_id("STANDARD")
.description("Standard Mon-Fri Work Week")
.time_zone("GMTM0600C") # Example: US Central Time
)
.set(field_name, value)
This is the general-purpose method for setting any other field on the work calendar record.
builder = WorkCalendarBuilder()
builder.set("WorkCalendarID", "24-7-OPS")
builder.set("Description", "24/7 Operations Calendar")
.to_body()
Once you have set all the required fields, call `.to_body()` to generate the final dictionary, ready to be sent as the JSON body in your API request.
# Build the work calendar
calendar_payload = (
WorkCalendarBuilder()
.work_calendar_id("STANDARD")
.description("Standard Mon-Fri Work Week")
)
# Get the final dictionary
json_body = calendar_payload.to_body()
# The json_body will look like this:
# {
# "WorkCalendarID": {"value": "STANDARD"},
# "Description": {"value": "Standard Mon-Fri Work Week"}
# }
Complete Example with WorkCalendarsService
Here is a complete example of how to use the `WorkCalendarBuilder` to create a new work calendar record.
from easy_acumatica.models.work_calendar_builder import WorkCalendarBuilder
# 1. Build the work calendar payload
calendar_to_create = (
WorkCalendarBuilder()
.work_calendar_id("24-7-OPS")
.description("24/7 Operations Calendar")
.time_zone("GMT")
)
# 2. Use the payload with the WorkCalendarsService to create the record
try:
new_calendar = client.work_calendars.create_work_calendar(
"24.200.001",
builder=calendar_to_create
)
print(f"Successfully created work calendar: {new_calendar['WorkCalendarID']['value']}")
except Exception as e:
print(f"Failed to create work calendar: {e}")
ON THIS PAGE
Introduction
Importing Builder
Builder Methods
- Shortcut Methods
- .set()
- .to_body()
Complete Example