Sale and order states
| Document | What it is | In the admin panel |
|---|---|---|
sale-order | A customer's order: an intention, not yet a sale | CRM › Orders |
trade | The sale itself: it affects stock, money and the customer balance | Sale › Sales |
On both, state is the status and state_id is the pipeline (kanban) column. To list the columns:
POST /states/get-all
{ "type": "saleOrders", "organization_id": "6712f0a9c4d1e87b3a0f9911" }For sales, type is trades. Each column comes with _id, default_key and is_default. An integration with declared permissions cannot call this method.
Sale (trade)
state | Stock | Can move to |
|---|---|---|
new | Goods reserved: amount is down, booked is up | in_progress, done, canceled |
in_progress | Reserved the same way | done, canceled |
done | Goods sold, reservation released | canceled |
canceled | Goods returned | nowhere |
payments are posted to the cashbox when the sale is created, whatever the state.
| Action | Call |
|---|---|
| Create | POST /trade/create, state: new, in_progress or done |
| Change state | PUT /trade/set-state: { "_id", "state" } |
| Move to a pipeline column | PUT /trade/set-state-id: { "_id", "state_id" }. A default column sets its own state, any other sets in_progress |
| Refund | POST /trade/refund — a new trade (is_refund: true, done); recipe |
A move that is not in the table returns code: 149002; sending the current state again changes nothing. Moving to done with a debt checks the debt-sale rules.
The Integration API has no method to edit or delete a sale.
Cancel a sale
PUT /trade/set-state
{
"_id": "6712f0a9c4d1e87b3a0f9988",
"state": "canceled",
"with_transactions": true,
"with_cashbacks": true
}- The goods return to the warehouse.
with_transactions: truecancels the payment transactions too. For a sale with a customer, if you leave it out the money stays in the cashbox. For a sale without a customer the payment is always canceled.with_cashbacks: truereverses cashback as well.- A sale that has a refund cannot be canceled (
149009).
Order (sale-order)
state | Meaning |
|---|---|
in_progress | Being worked on. An order created by an integration lands in the first regular column with this state |
new | New (a default column) |
accepted, draft | May appear in API responses |
done | Sold |
canceled | Canceled |
| Action | Call |
|---|---|
| Create | POST /sale-order/create |
| Take into work | PUT /sale-order/accept/{id} — in_progress, first regular column |
| Change column, cancel | POST /sale-order/update-status-many: { "ids": [], "state_id" } |
| Edit contents | PUT /sale-order/update |
| Sell | POST /trade/create with order_id |
| Delete | DELETE /sale-order/delete/{id} — soft delete |
Details that matter:
create: an order cannot be created ascanceled. If duplicate control is on in CRM settings, the response may be an existing order rather than a new one.accept: do not call it on adoneorcanceledorder.update-status-many: to cancel, send the column withdefault_key: "canceled". An order cannot be moved into thenewcolumn; acanceledorder does not change; fromdoneonly tocanceled; only an order that has a sale can enter thedonecolumn. The work runs in the background and the response does not carry the outcome — re-read the orders to check.updatedoes not change the state and replaces the lines entirely: send all of them. Adoneorcanceledorder cannot be edited (151002).
Reservation. With booking_product_in_order on in sale settings, an order in new, accepted or in_progress reserves goods; done, canceled and deletion release them.
From order to sale
Send order_id to POST /trade/create, and order_item_id on each line. Its value is the line's item_id from the sale-order/get-by-id response (not _id, which is the product id). The other required fields are as for an ordinary sale.
- Customer and organization are taken from the order; the currency must match the order's (
149015). - The order's whole reservation is released. After a partial sale the remainder is not reserved again automatically.
trade_status:zero→partial→fully. A fully sold order becomesdone, even when the sale isneworin_progress.- Selling more than was ordered is rejected unless overselling is allowed (
151005). - Canceling the sale lowers the sold quantity, but the order stays
done. - Do not record a sale against a canceled order.
- An advance paid on the order is not applied to the sale automatically — send it from the customer's balance in
by_balance(reference).
Tracking
Get state changes through webhooks (saleOrders.status_change, trades.*) and re-read the document with get-by-id. Terms: glossary.