WorkLocationBuilder
The `WorkLocationBuilder` is your primary tool for creating the JSON payload needed to create or update `WorkLocation` records with the `WorkLocationsService`. It provides a fluent, chainable interface for setting the fields of a work location, including its address.
Importing the Builder
To get started, import the `WorkLocationBuilder` from the `easy_acumatica.models` module.
from easy_acumatica.models.work_location_builder import WorkLocationBuilder
Builder Methods
Use the shortcut methods to set the most common fields for a work location.
location_payload = (
WorkLocationBuilder()
.work_location_id("MAIN-OFFICE")
.work_location_name("Main Corporate Office")
.active(True)
.address_info(
address_line_1="123 Corporate Way",
city="Someville",
state="CA",
postal_code="90210",
country="US"
)
)
.set(field_name, value)
This is the general-purpose method for setting any other field on the work location record.
builder = WorkLocationBuilder()
builder.set("WorkLocationID", "WAREHOUSE-B")
builder.set("Description", "Secondary Warehouse Location")
.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 location
location_payload = (
WorkLocationBuilder()
.work_location_id("MAIN-OFFICE")
.address_info(city="Someville", state="CA")
)
# Get the final dictionary
json_body = location_payload.to_body()
# The json_body will look like this:
# {
# "WorkLocationID": {"value": "MAIN-OFFICE"},
# "AddressInfo": {
# "City": {"value": "Someville"},
# "State": {"value": "CA"}
# }
# }
Complete Example with WorkLocationsService
Here is a complete example of how to use the `WorkLocationBuilder` to create a new work location record.
from easy_acumatica.models.work_location_builder import WorkLocationBuilder
# 1. Build the work location payload
location_to_create = (
WorkLocationBuilder()
.work_location_id("EAST-WH")
.work_location_name("East Coast Warehouse")
.active(True)
.address_info(
address_line_1="456 Distribution Dr",
city="Eastville",
state="NY",
postal_code="10001",
country="US"
)
)
# 2. Use the payload with the WorkLocationsService to create the record
try:
new_location = client.work_locations.create_work_location(
"24.200.001",
builder=location_to_create
)
print(f"Successfully created work location: {new_location['WorkLocationID']['value']}")
except Exception as e:
print(f"Failed to create work location: {e}")