# Deducting stock after a sale Deducting warehouse stock after a sale in Ritevo: a button on the order or an automatic action, missing stock, stock below zero and the result per line. When you sell something, Ritevo does not lower the product's warehouse stock by itself. You do it with one click in the order or leave it to an automatic action, for example after the order is paid. Below we explain how to do it, what happens when there is not enough goods and where to check the result. > **Required integration:** You need a warehouse integration from the **Warehouses and wholesalers** category, for example the [Own warehouse](https://ritevo.com/en/docs/integrations/own-warehouse). The order lines must be linked to products - how to do it is described in [Linking offers to products](https://ritevo.com/en/docs/products/offer-links). ## How to deduct stock 1. Open the order you want to deduct stock for. 2. Above the order lines, click the **Deduct warehouse stock** button. A list with four options opens. 3. Pick what to do if a product is short in the warehouse. Hover over the info icon next to an option for a short explanation; the full description is below. 4. Clicking an option deducts the stock right away - there is no extra confirmation. After a few seconds the result appears next to each line, in the **Stock deduction** column. To deduct stock automatically, add the **Deduct warehouse stock** step to an [order action](https://ritevo.com/en/docs/automations/order-actions#steps) and pick one of the same options in it. The step works exactly like the button. ## How the deduction works - **Linked lines only** - we deduct stock only for lines linked to a product. A line without a link stays unchanged and gets the **Not linked** status. If you link it later and deduct again, all lines of the order are deducted again - also the ones already deducted. - **Deleted or inactive product** - such a line is not deducted. It gets the **Skipped - product deleted** or **Skipped - product inactive** status. - **Every click deducts again** - earlier deductions show in the line history, but they do not block the next one. If you click twice or two actions do the same, the stock goes down twice. - **Each line separately** - in one order one line can be deducted and another not, for example when it is not linked or short of goods. The only exception is the **Deduct nothing in the order** option. - **Several stocks of one product** - a product can have several stocks, for example one per warehouse. We deduct from the largest first, then from the next. Example: a product has two stocks of 5 pieces and the order is for 10 - both stocks drop to 0. Stocks marked as deleted are skipped entirely: they do not count towards the available quantity and we never change them. - **Stock below zero** - stock can drop below zero if you pick **Deduct anyway (stock goes below zero)**. Such a product is easy to find: on the **Products** list, in the **Stock** column, a number below zero, for example **-1**, is shown in red. Do not confuse it with the **No stock** badge - that marks a product with no stock at all. ## When stock is not enough - **Deduct anyway (stock goes below zero)** (API: "Deduct anyway (stock goes below zero)" = `DEDUCT_ANYWAY`; value in `shortagePolicy`) - we deduct the whole ordered quantity, even if there is not enough goods. The missing part is recorded as a minus on the largest stock. Example: two stocks of 5 pieces, an order for 11 - one stock has 0, the other -1. If the product has no stock at all, there is nothing to deduct from - we only record how much was missing. - **Deduct what is there (stock stops at zero)** (API: "Deduct what is there (stock stops at zero)" = `STOP_AT_ZERO`; value in `shortagePolicy`) - we deduct only as much as is in the warehouse and the stock stops at 0. How much was missing shows in the line history. - **Skip line** (API: "Skip line" = `SKIP_LINE_ITEM`; value in `shortagePolicy`) - a line that is short of goods stays unchanged and gets the **Skipped - not enough stock** status. The other lines are deducted as usual. - **Deduct nothing in the order** (API: "Deduct nothing in the order" = `CANCEL_DEDUCTION`; value in `shortagePolicy`) - if even one line is short of goods, nothing is deducted in the whole order. That line gets **Skipped - not enough stock** and the others **Cancelled - another line stopped the deduction**. Useful when the order should be deducted in full or not at all. > **Good to know:** A new automatic action step has **Deduct anyway (stock goes below zero)** selected from the start. In the order this option is first on the list. ## Result on the line After a deduction, each line shows the result of the latest deduction in the **Stock deduction** column. The icon next to it opens the **Stock deduction history**: every deduction of this line with its date, how much was deducted, how much was missing and any error. The result is also in the orders audit. What the statuses mean: - **Deducted** (API: "Deducted" = `DEDUCTED`; value in `lineItems[].stockDeductions[].status`) - we deducted the whole ordered quantity. - **Deducted, short** (API: "Deducted, short" = `SHORTAGE`; value in `lineItems[].stockDeductions[].status`) - we deducted, but there was not enough goods. Depending on the option, the missing part went into the minus or the stock stopped at 0. - **Skipped - not enough stock** (API: "Skipped - not enough stock" = `SKIPPED_SHORTAGE`; value in `lineItems[].stockDeductions[].status`) - there was not enough goods, so this line was not deducted. - **Not linked** (API: "Not linked" = `NOT_LINKED`; value in `lineItems[].stockDeductions[].status`) - the line is not linked to a product. - **Skipped - product deleted** (API: "Skipped - product deleted" = `PRODUCT_DELETED`; value in `lineItems[].stockDeductions[].status`) - the linked product is deleted. - **Skipped - product inactive** (API: "Skipped - product inactive" = `PRODUCT_INACTIVE`; value in `lineItems[].stockDeductions[].status`) - the linked product is inactive. - **Cancelled - another line stopped the deduction** (API: "Cancelled - another line stopped the deduction" = `CANCELLED`; value in `lineItems[].stockDeductions[].status`) - this line could be deducted, but another one was short with the **Deduct nothing in the order** option, so nothing was deducted in the whole order. - **Error** (API: "Error" = `FAILED`; value in `lineItems[].stockDeductions[].status`) - the deduction failed and nothing was deducted. You will see the reason in the line history. ## When stock changes A product's stock changes only for lines with the **Deducted** or **Deducted, short** status. For Ritevo it is a regular stock change - the same as after a fetch from the wholesaler - even if the number comes out the same (for example the stock was already 0). Whether a line linked to an active product changes stock depends on the chosen option: - **Deduct anyway (stock goes below zero)** (API: "Deduct anyway (stock goes below zero)" = `DEDUCT_ANYWAY`; value in `shortagePolicy`) - always changes stock. - **Deduct what is there (stock stops at zero)** (API: "Deduct what is there (stock stops at zero)" = `STOP_AT_ZERO`; value in `shortagePolicy`) - always changes stock, down to 0 at most. - **Skip line** (API: "Skip line" = `SKIP_LINE_ITEM`; value in `shortagePolicy`) - changes stock only when there is enough goods for this line. - **Deduct nothing in the order** (API: "Deduct nothing in the order" = `CANCEL_DEDUCTION`; value in `shortagePolicy`) - changes stock only when there is enough goods for every line of the order. Stock certainly stays unchanged when: - the line is not linked to a product, - the product is deleted or inactive, - goods are short and you picked **Skip line**, - even one line is short and you picked **Deduct nothing in the order** - then nothing changes in the whole order, - the deduction ended with an error, - the product has no stock at all, - the stock is marked as deleted. > **Good to know:** Automatic actions for products are in preparation. With them you will catch the stock change after a deduction with an action and, for example, update the offer in a shop or on a marketplace. ## What is not there yet - It does not reserve goods - it deducts stock right away. - It does not deduct a single line - every use covers the whole order. - It does not give stock back after an order is cancelled or returned - correct the stock by hand in the product. - It does not send changed stock to shops or marketplaces yet. ## Stock deduction through the API By hand: `POST /orders/{orderId}/warehouse-stock-deduction` with the body `{shortagePolicy}` (required), response 202 - the result arrives asynchronously. In an action: the `DEDUCT_WAREHOUSE_STOCK` step with the same `shortagePolicy` value in `enumValue`, and the result fires the `DEDUCTED_WAREHOUSE_STOCK` trigger. Values: **When stock is not enough** (`shortagePolicy`) - **Deduct anyway** = `DEDUCT_ANYWAY` (the whole quantity always leaves stock; what is missing goes below zero on the largest stock; result `DEDUCTED` or `SHORTAGE`), **Deduct what is there** = `STOP_AT_ZERO` (only what is there leaves, stocks stop at 0, the shortage is only recorded in `shortageQuantity`; result `DEDUCTED` or `SHORTAGE`), **Skip line** = `SKIP_LINE_ITEM` (a line without enough stock changes nothing and gets `SKIPPED_SHORTAGE`, the rest is deducted as usual), **Deduct nothing in the order** = `CANCEL_DEDUCTION` (if even one line lacks stock, nothing in the order is deducted: it gets `SKIPPED_SHORTAGE`, the others `CANCELLED`). With enough stock all four behave the same (`DEDUCTED`). A deleted (`deleted`) or inactive (`active` = `false`) product is always skipped - the line gets `PRODUCT_DELETED` or `PRODUCT_INACTIVE` and stops nothing. Every call deducts again, without checking earlier ones. Stocks with `deleted` = `true` are skipped entirely, as if they did not exist: they do not count towards the available quantity, are not locked or written and never go below zero. A line is linked to a product by its `externalOfferId` within the order's integration (links: `/integrations/warehouses/external-offer-assignments`). Result: in `GET /orders/{id}` every line has `stockDeductions` - the history of all runs, newest last, and the line's current result is the last entry. Entry fields: `createdAt`, `status`, `warehouseProductId`, `requestedQuantity` (the line quantity), `deductedQuantity` (taken from positive stocks), `shortageQuantity` (how much was missing - with `DEDUCT_ANYWAY` it went below zero on the largest stock, with `STOP_AT_ZERO` it was only recorded, with `SKIPPED_SHORTAGE` it is the shortage the line was skipped for), `errorType` and `errorMessage` (only with `FAILED`). A line with quantity 0 gets `DEDUCTED` with zeros. A product without any stock gets `SHORTAGE` with `DEDUCT_ANYWAY` and its stock is not changed. With `CANCEL_DEDUCTION` nothing is saved: lines without stock get `SKIPPED_SHORTAGE`, lines that could be deducted get `CANCELLED`, and `NOT_LINKED`, `PRODUCT_DELETED` and `PRODUCT_INACTIVE` stop nothing. Only `DEDUCTED` and `SHORTAGE` lines write stock: all stocks of their products are written (also without a quantity change, e.g. `STOP_AT_ZERO` at stock 0) and it counts as a product stock change, just like a fetch from the wholesaler. The result is per line, so in one order one line can change stock and another not (except `CANCEL_DEDUCTION`). If the whole deduction fails, every line gets `FAILED` with the same `errorType` and nothing is deducted. What exactly happens in typical cases (one result per line, appended to `lineItems[].stockDeductions[]`): - A line without a link (no `externalOfferId`, e.g. a line added by hand, or an offer not linked to a product within the order's integration): `NOT_LINKED`, `warehouseProductId` = `null`, quantities 0, no stock changes. It is not an error and does not stop the other lines - also with `CANCEL_DEDUCTION`. - No line is linked (or the order has no integration): the deduction still runs - every line gets `NOT_LINKED`, nothing changes, the `DEDUCTED_WAREHOUSE_STOCK` trigger still fires and the action step moves on as after a success. - Fixing a missing link: create the link (`POST /integrations/warehouses/external-offer-assignments` or `POST /orders/{orderId}/line-items/{lineItemId}/warehouse-link`) and run the deduction again. Note: running it again deducts again the lines that already got `DEDUCTED`/`SHORTAGE` - there is no single-line deduction. - A deleted or inactive product: `PRODUCT_DELETED` / `PRODUCT_INACTIVE` with `warehouseProductId`, nothing changes, nothing stops, whatever the `shortagePolicy`. - A linked product without any stock (or with deleted stocks only): with `DEDUCT_ANYWAY` and `STOP_AT_ZERO` the result is `SHORTAGE` with `deductedQuantity` 0 and `shortageQuantity` = the whole quantity, stock unchanged; with `SKIP_LINE_ITEM` `SKIPPED_SHORTAGE`; with `CANCEL_DEDUCTION` `SKIPPED_SHORTAGE` and the whole order `CANCELLED`. - A deleted stock (`deleted` = `true`): it is not read, locked or written - the deduction works as if it did not exist. A product with deleted stocks only behaves like a product without stock. - The same product on two lines: the lines are worked out one after another on the same stocks, so the second sees the stock already reduced by the first. - A line with quantity 0 or below: `DEDUCTED` with zeros, stock unchanged. - A technical failure of the whole deduction: every line `FAILED` with `errorType`/`errorMessage`, nothing is deducted; the order shows the error in the audit, the `DEDUCTED_WAREHOUSE_STOCK` trigger fires and the action step moves on (as after a shipment error). - A line removed from the order before the result arrived gets no entry; a line added meanwhile does not either. - Every run (manual or from an action) appends exactly one entry to each line the order had when it started. --- All help in one file: https://ritevo.com/llms-full.txt. Help map with links to every page: https://ritevo.com/llms.txt.