Skip to content
View as Markdown

Sale and order states ​

DocumentWhat it isIn the admin panel
sale-orderA customer's order: an intention, not yet a saleCRM › Orders
tradeThe sale itself: it affects stock, money and the customer balanceSale › Sales

On both, state is the status and state_id is the pipeline (kanban) column. To list the columns:

json
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) ​

stateStockCan move to
newGoods reserved: amount is down, booked is upin_progress, done, canceled
in_progressReserved the same waydone, canceled
doneGoods sold, reservation releasedcanceled
canceledGoods returnednowhere

payments are posted to the cashbox when the sale is created, whatever the state.

ActionCall
CreatePOST /trade/create, state: new, in_progress or done
Change statePUT /trade/set-state: { "_id", "state" }
Move to a pipeline columnPUT /trade/set-state-id: { "_id", "state_id" }. A default column sets its own state, any other sets in_progress
RefundPOST /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 ​

json
PUT /trade/set-state

{
    "_id": "6712f0a9c4d1e87b3a0f9988",
    "state": "canceled",
    "with_transactions": true,
    "with_cashbacks": true
}
  • The goods return to the warehouse.
  • with_transactions: true cancels 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: true reverses cashback as well.
  • A sale that has a refund cannot be canceled (149009).

Order (sale-order) ​

stateMeaning
in_progressBeing worked on. An order created by an integration lands in the first regular column with this state
newNew (a default column)
accepted, draftMay appear in API responses
doneSold
canceledCanceled
ActionCall
CreatePOST /sale-order/create
Take into workPUT /sale-order/accept/{id} — in_progress, first regular column
Change column, cancelPOST /sale-order/update-status-many: { "ids": [], "state_id" }
Edit contentsPUT /sale-order/update
SellPOST /trade/create with order_id
DeleteDELETE /sale-order/delete/{id} — soft delete

Details that matter:

  • create: an order cannot be created as canceled. 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 a done or canceled order.
  • update-status-many: to cancel, send the column with default_key: "canceled". An order cannot be moved into the new column; a canceled order does not change; from done only to canceled; only an order that has a sale can enter the done column. The work runs in the background and the response does not carry the outcome — re-read the orders to check.
  • update does not change the state and replaces the lines entirely: send all of them. A done or canceled order 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 becomes done, even when the sale is new or in_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.

Bito 2.0 Integration API