# Recipe: write-off

Your system knows that goods were damaged or lost — it has to show up in Bito under **Warehouse ›
Actions › Write-offs** and leave stock. That is a `write-off` document. It is created **directly** as
`done`: there is no draft.

**Permissions needed:** `write_off_create`, `write_off`, `warehouse`,
`employee`.

## 1. Find the organization and warehouse

```http
GET /organization/get-all
```

```json
POST /warehouse/get-all

{ "organization_id": "6712f0a9c4d1e87b3a0f9911", "status": "active" }
```

Keep the organization's `_id` and `currency_id` and the warehouse's `_id`.

## 2. Pick a reason

```json
POST /reason/get-paging

{ "page": 1, "limit": 200, "type": "write_off" }
```

::: warning Reasons and permissions
`reason/*` methods have no permission key. If your app declares even one permission in
`required_permissions`, they are **closed** to it ([Creating an integration](https://docs.bito.uz/en/guide/create.md)). In such an
app, keep the reason id in your settings, or take it from existing documents: `write-off/get-paging`
rows carry `reason._id`.
:::

## 3. Pick the responsible employee

```json
POST /employee/get-paging

{ "page": 1, "limit": 200 }
```

## 4. Create the document

```json
POST /write-off/create

{
    "organization_id": "6712f0a9c4d1e87b3a0f9911",
    "source_warehouse_id": "6712f0a9c4d1e87b3a0f9955",
    "currency_id": "6712f0a9c4d1e87b3a0f9988",
    "write_date": "2026-11-05T10:00:00Z",
    "responsible_id": "6712f0a9c4d1e87b3a0f99aa",
    "reason_id": "6712f0a9c4d1e87b3a0f99bb",
    "action": "remove",
    "products": [
        { "product_id": "6712f0a9c4d1e87b3a0f9933", "amount": 2 }
    ],
    "code": "WMS-10482",
    "note": "Damaged packaging"
}
```

| Field | Required | Description |
|---|---|---|
| `organization_id` | Yes | Organization |
| `source_warehouse_id` | Yes | Warehouse the goods leave |
| `currency_id` | Yes | The document's cost is calculated in it — usually the organization's currency |
| `write_date` | Yes | ISO 8601 |
| `responsible_id` | Yes | Responsible employee |
| `reason_id` | Yes | Reason |
| `action` | Yes | `remove` — write off for good, `defect` — move to defective goods |
| `destination_warehouse_id` | For `defect` | Warehouse that accounts for the defective goods |
| `products[].product_id` | Yes | Product |
| `products[].amount` | Yes | A positive number in the product's unit of measure |
| `products[].marks` | For marked goods | Codes; their count must equal `amount` |
| `products[].expiration_date` | No | Take only from batches with this expiry date |
| `code` | No | The document number in your system |
| `note` | No | Comment |

The reference lists `organization_id`, `source_warehouse_id` and `currency_id` as optional, but the
call fails without them. Send an existing warehouse of the same
organization as `destination_warehouse_id`.

The response carries `_id`, `number`, `state: "done"`, `total_cost` and the `products` lines.

::: warning Retries
`create` is not idempotent: a repeated call writes the goods off **a second time**. If no response came
back, first read `write-off/get-paging` with `warehouse_id`, `date_from`, `date_to` and look for your
`code` in the rows (`search` matches the Bito number only).
:::

## 5. What changes

- `amount` goes down in the source warehouse. Reserved goods are not written off.
- With `action: "defect"`, the same quantity is added to the `in_trash` counter of
  `destination_warehouse_id`.
- Cost is calculated from the batches (`total_cost`), and Bito issues an expense-type invoice for it —
  it shows up in
  [`invoice/get-paging`](https://docs.bito.uz/en/api/invoice.md#post-invoice-get-paging) rows, where `write_off_id` is
  the write-off's id. No money leaves a cashbox.
- There is no webhook event for write-offs.

What the counters mean: [stock and prices](https://docs.bito.uz/en/guide/recipes/stock-prices.md).

## 6. Cancel

```json
PUT /write-off/set-status/6712f0a9c4d1e87b3a0f99cc

{ "status": "canceled" }
```

The only transition is `done` → `canceled`. The goods return to the source warehouse (for `defect`,
`in_trash` also goes down) and the invoice is cancelled. There is no method to edit or delete the
document: if it is wrong, cancel it and create a new one.

## Errors

| `code` | Cause |
|---|---|
| `10001` | Validation: a required field is missing or a value is wrong — read `message` |
| `10003` (HTTP `403`) | A permission was not approved; `data` names it |
| `26000`, `26022` | Product not found, or not available in this organization |
| `26008`, `26014` | A compound product or a service cannot be written off |
| `124000`, `124009` | No stock, or not enough of it |
| `124003` | Wrong marking codes |
| `125000` | Reason not found |
| `132000` | Document not found |
| `132002` | Cannot cancel: already cancelled, or the goods were used afterwards |

On an error no document is created at all — lines are never partly written off.

## Methods

| Step | Method |
|---|---|
| Organization | [`GET /organization/get-all`](https://docs.bito.uz/en/api/organization.md) |
| Warehouse | [`POST /warehouse/get-all`](https://docs.bito.uz/en/api/warehouse.md#post-warehouse-get-all) |
| Reason | [`POST /reason/get-paging`](https://docs.bito.uz/en/api/reason.md#post-reason-get-paging) |
| Employee | [`POST /employee/get-paging`](https://docs.bito.uz/en/api/employee.md#post-employee-get-paging) |
| Create | [`POST /write-off/create`](https://docs.bito.uz/en/api/write-off.md#post-write-off-create) |
| Check | [`POST /write-off/get-paging`](https://docs.bito.uz/en/api/write-off.md#post-write-off-get-paging), [`GET /write-off/get-by-id/{id}`](https://docs.bito.uz/en/api/write-off.md#get-write-off-get-by-id-id) |
| Cancel | [`PUT /write-off/set-status/{id}`](https://docs.bito.uz/en/api/write-off.md#put-write-off-set-status-id) |
