Purchasing¶
PurchasingClient
¶
Source code in src/spyre/purchasing.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
create_purchase_order(purchase_order)
¶
Create a new purchase order.
Sends a POST request to the purchase order endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
purchase_order
|
dict
|
A PurchaseOrder instance containing the purchase order details. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
purchaseOrder |
purchaseOrder
|
The create PurchaseOrder instance. |
Raises:
| Type | Description |
|---|---|
CreateRequestError
|
If the creation fails or response is invalid. |
Source code in src/spyre/purchasing.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
delete_purchase_order(id)
¶
Delete a purchase order by its ID.
Sends a DELETE request to the purchase order endpoint to remove the specified purchase order from the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
The ID of the purchase order to delete. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the sales order was successfully deleted, False otherwise. |
Source code in src/spyre/purchasing.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
get_purchase_order(id=None, PO_number=None)
¶
Retrieve a purchase order by its ID or PO number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
The ID of the purchase order to retrieve. |
None
|
PO_number
|
str
|
The purchase order number of the purchase order to retrieve. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
purchaseOrder |
purchaseOrder
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither id nor PO_number is provided, or if no matching order is found. |
Source code in src/spyre/purchasing.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
issue_purchase_order(id)
¶
Issue a purchase order by its ID.
Sends a request to Spire to change the purchase order's status to “Issued”. Issuing an order typically means it has been confirmed and is ready to be sent to the vendor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
The ID of the purchaseOrder to issue. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
purchaseOrder |
purchaseOrder
|
The updated purchase order object with the status set to "I" (Issued). |
Raises:
| Type | Description |
|---|---|
CreateRequestError
|
If the request fails or the API returns an error status. |
Source code in src/spyre/purchasing.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
query_purchase_order(*, query=None, sort=None, filter=None, all=False, limit=1000, start=0, **extra_params)
¶
Query purchase orders with optional full-text search, filtering, multi-field sorting, and pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Full-text search string. |
None
|
sort
|
dict
|
Dictionary of sorting rules (e.g., {"date": "desc", "number": "asc"}). |
None
|
filter
|
dict
|
Dictionary of filters to apply (will be JSON-encoded and URL-safe). |
None
|
all
|
bool
|
If True, retrieves all pages of results. |
False
|
limit
|
int
|
Number of results per page (max 1000). |
1000
|
start
|
int
|
Starting offset for pagination. |
0
|
**extra_params
|
Any
|
Any additional parameters to include in the query. |
{}
|
Returns:
| Type | Description |
|---|---|
List[purchaseOrder]
|
List[purchaseOrder]: List of wrapped purchase order resources. |
Source code in src/spyre/purchasing.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
receive_purchase_order(id, receiveAll=None)
¶
Receive a purchase order by its ID.
This updates the order in Spire to reflect that items have been received. Typically, this should only be called on purchase orders with status "Issued".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
The ID of the purchaseOrder to receive. |
required |
receiveAll
|
bool
|
An optional boolean to recieve all quantites on the purchase order. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
purchaseOrder |
purchaseOrder
|
The updated purchase order object with the status set to "R" (Received). |
Raises: CreateRequestError: If the request fails or the API returns an error status.
Source code in src/spyre/purchasing.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
update_purchase_order(id, purchase_order)
¶
Update an existing purchase order by ID.
Sends a PUT request to the purchase order endpoint with the provided sales order data
to update the existing record. Returns a wrapped purchaseOrder object containing
the updated information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
The ID of the purchase order to update. |
required |
purchase_order
|
PurchaseOrder
|
A PurchaseOrder instance with the purchase order details. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
purchaseOrder |
purchaseOrder
|
An instance of the purchaseOrder wrapper class initialized with the updated data and client session. |
Source code in src/spyre/purchasing.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
PurchasingHistoryClient
¶
Source code in src/spyre/purchasing.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
get_purchase_history_order(id=None, PO_number=None)
¶
Retrieve an archived purchase order by its ID or PO number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
The ID of the purchase order to retrieve. |
None
|
PO_number
|
str
|
The purchase order number of the purchase order to retrieve. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
purchaseOrder |
purchaseOrder
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither id nor PO_number is provieded, or if no matching purchase order is found. |
Source code in src/spyre/purchasing.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
query_purchase_history_order(*, query=None, sort=None, filter=None, all=False, limit=1000, start=0, **extra_params)
¶
Query archived purchase orders with optional full-text search, filtering, multi-field sorting, and pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Full-text search string. |
None
|
sort
|
dict
|
Dictionary of sorting rules (e.g., {"date": "desc", "number": "asc"}). |
None
|
filter
|
dict
|
Dictionary of filters to apply (will be JSON-encoded and URL-safe). |
None
|
all
|
bool
|
If True, retrieves all pages of results. |
False
|
limit
|
int
|
Number of results per page (max 1000). |
1000
|
start
|
int
|
Starting offset for pagination. |
0
|
**extra_params
|
Any
|
Any additional parameters to include in the query. |
{}
|
Returns:
| Type | Description |
|---|---|
List[purchaseOrder]
|
List[purchaseOrder]: List of wrapped purchase order resources. |
Source code in src/spyre/purchasing.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
purchaseOrder
¶
Bases: APIResource[PurchaseOrder]
Source code in src/spyre/purchasing.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
delete()
¶
Cancels and deletes this purchase order.
Sends a DELETE request to the API to remove the purchase order with the current ID.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the order was successfully deleted (HTTP 204 or 200), False otherwise. |
Source code in src/spyre/purchasing.py
305 306 307 308 309 310 311 312 313 314 | |
issue()
¶
Issue this purchase order.
Sends a POST request to Spire to change the purchase order's status to “I” (Issued). Issuing an order typically means it has been confirmed and is ready to be sent to the vendor.
Returns:
| Name | Type | Description |
|---|---|---|
purchaseOrder |
purchaseOrder
|
The updated purchase order object with the status set to "I" (Issued). |
Raise
CreateRequestError: If the request fails or the API returns an error status.
Source code in src/spyre/purchasing.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
receive(receiveAll=None)
¶
Receive this purchase order.
Sends a POST request to Spire to change the purchase order's status to "R" (Received). Receiving an order typically means the received quantites have been entered and the order is ready to be invoiced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receiveAll
|
bool
|
An optional boolean to recieve all quantites on the purchase order. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
purchaseOrder |
purchaseOrder
|
The updated purchase order object with the status set to "R" (Received). |
Raise
CreateRequestError: If the request fails or the API returns an error status.
Source code in src/spyre/purchasing.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
update(order=None)
¶
Update this sales order.
If no purchase order object is provided, updates the current instance on the server. If a purchase order object is provided, updates the purchase order using the given data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
purchaseOrder
|
An optional purchaseOrder instance to use for the update. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
purchaseOrder |
purchaseOrder
|
The updated purchaseOrder object reflecting the new status. |
Source code in src/spyre/purchasing.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
create_sales_order_from_invoice(invoice)
¶
Creates a Sales Order from an Invoice by copying relevant fields and adjusting quantities and freight charges for order processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice
|
Invoice
|
The invoice object to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SalesOrder |
SalesOrder
|
A new Sales Order instance populated with data from the invoice, including negative freight and order quantities, and duplicated address and item records. |
Notes
- Freight amount is negated.
- Order and committed quantities are negated unless zero.
- Shipping carrier and tracking number fields are reset to None.
- Duplicate records are created for address, shipping address, and items to avoid mutating the original invoice data.
Source code in src/spyre/utils.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |