Purchase Orders Sub Service - Nioron07/Easy-Acumatica GitHub Wiki
This guide covers the PurchaseOrdersService
, which is your primary tool for creating purchase order records through the contract-based API.
1. Importing Helpers
Before you start, import the necessary builders and query helpers. The PurchaseOrdersService
methods rely on these to construct payloads and define query parameters.
from easy_acumatica.models.purchase_order_builder import PurchaseOrderBuilder
from easy_acumatica.models.query_builder import QueryOptions
2. Understanding the Service's Purpose
The PurchaseOrdersService
provides a method for creating new purchase orders in Acumatica. It acts as the main interface for sending PUT
requests to the PurchaseOrder
endpoint.
3. PurchaseOrdersService Methods
The following table summarizes the primary method available in the PurchaseOrdersService
.
Method | Description | Key Parameters |
---|---|---|
.create_purchase_order() |
Creates a new purchase order record. | api_version , builder , options |
4. Creating a Purchase Order
The primary function of this service is to create new purchase orders.
create_purchase_order(api_version, builder, options)
This method creates a new purchase order. You must provide a PurchaseOrderBuilder
instance containing the order's details. You can also provide QueryOptions
to customize the response, for example by expanding related records.
Example: Create a new purchase order
# 1. Build the purchase order payload
po_payload = (
PurchaseOrderBuilder()
.order_type("Normal")
.vendor("V000000001")
.description("Annual supply of raw materials")
.add_detail(inventory_id="RAW-MAT-01", order_qty=500, unit_cost=12.50)
.add_detail(inventory_id="RAW-MAT-02", order_qty=200, unit_cost=35.75)
)
# 2. Define options to expand the details in the response
query_options = QueryOptions(expand=["Details"])
# 3. Use the payload to create the record
try:
new_po = client.purchase_orders.create_purchase_order(
"24.200.001",
builder=po_payload,
options=query_options
)
print(f"Successfully created PO: {new_po['OrderNbr']['value']}")
except Exception as e:
print(f"Failed to create purchase order: {e}")