Write off
Stock write-offs
INFO
Har bir javob umumiy konvertda qaytadi — code, message, messages, status_code, time — foydali yuk esa data ichida. Quyidagi jadvallar faqat data ichini tavsiflaydi.
POST /write-off/create
Create a new write-off (stock loss). The document is immediately persisted in DONE state; stock is decremented and a linked invoice is created inside the same transaction.
So‘rov tanasi
| Maydon | Tur | Majburiy | Tavsif |
|---|---|---|---|
organization_id | string | Yo‘q | Organization ObjectId. Required when the tenant has multiple organizations. |
code | string | Yo‘q | Optional external reference code for the write-off |
write_date | string (date-time) | Ha | Date the write-off occurred |
source_warehouse_id | string | Yo‘q | Source warehouse ObjectId — the warehouse stock is deducted from |
responsible_id | string | Ha | Employee ObjectId responsible for this write-off |
reason_id | string | Ha | Reason ObjectId explaining why the stock is being written off |
currency_id | string | Yo‘q | Currency ObjectId used for cost values. Defaults to the organization's base currency. |
action | string | Ha | Write-off action type. remove — permanent stock removal; defect — defective goods moved to a destination warehouse.. Mumkin qiymatlar: remove, defect |
destination_warehouse_id | string | Yo‘q | Destination warehouse ObjectId. Required when action is defect. |
note | string | Yo‘q | Optional free-text note |
products | object[] | Ha | List of products to write off. At least one item is required. |
products[].product_id | string | Ha | Product ObjectId |
products[].amount | number | Ha | Quantity to write off (must be positive) |
products[].box_count | number | Yo‘q | Number of boxes (integer; defaults to 0) |
products[].marks | string[] | Yo‘q | Mark/serial codes for marked goods. Each mark must be unique within the request. |
products[].expiration_date | string (date-time) | Yo‘q | Expiration date — required for perishable products that have has_expiration: true |
{
"organization_id": "string",
"code": "string",
"write_date": "2025-05-01T12:00:00Z",
"source_warehouse_id": "string",
"responsible_id": "string",
"reason_id": "string",
"currency_id": "string",
"action": "remove",
"destination_warehouse_id": "string",
"note": "string",
"products": [
{
"product_id": "string",
"amount": 0,
"box_count": 0,
"marks": [],
"expiration_date": "2025-05-01T12:00:00Z"
}
]
}Javob
| Maydon | Tur | Tavsif |
|---|---|---|
_id | string | |
number | string | Auto-generated write-off document number |
code | string | Optional external reference code |
write_date | string (date-time) | |
action | string | Mumkin qiymatlar: remove, defect |
state | string | Mumkin qiymatlar: done, canceled |
note | string | |
total_cost | number | |
organization | object | |
organization._id | string | |
organization.name | string | |
responsible_employee | object | |
responsible_employee._id | string | |
responsible_employee.full_name | string | |
reason | object | |
reason._id | string | |
reason.name | string | |
currency | object | |
currency._id | string | |
currency.name | string | |
source_warehouse | object | |
source_warehouse._id | string | |
source_warehouse.name | string | |
destination_warehouse | object | Populated only when action is defect |
destination_warehouse._id | string | |
destination_warehouse.name | string | |
products | object[] | |
products[]._id | string | |
products[].product_id | string | |
products[].name | string | |
products[].barcode | string | |
products[].amount | number | |
products[].box_count | number | |
products[].cost | number | |
products[].total_cost | number | |
products[].marks | string[] | |
products[].expiration_date | string (date-time) | |
created_at | string (date-time) | |
updated_at | string (date-time) |
{
"code": 0,
"message": "Success",
"status_code": 200,
"data": {
"_id": "string",
"number": "string",
"code": "string",
"write_date": "2025-05-01T12:00:00Z",
"action": "remove",
"state": "done",
"note": "string",
"total_cost": 0,
"organization": {
"_id": "string",
"name": "string"
},
"responsible_employee": {
"_id": "string",
"full_name": "string"
},
"reason": {
"_id": "string",
"name": "string"
},
"currency": {
"_id": "string",
"name": "string"
},
"source_warehouse": {
"_id": "string",
"name": "string"
},
"destination_warehouse": {
"_id": "string",
"name": "string"
},
"products": [
{
"_id": "string",
"product_id": "string",
"name": "string",
"barcode": "string",
"amount": 0,
"box_count": 0,
"cost": 0,
"total_cost": 0,
"marks": [],
"expiration_date": "2025-05-01T12:00:00Z"
}
],
"created_at": "2025-05-01T12:00:00Z",
"updated_at": "2025-05-01T12:00:00Z"
},
"time": "2025-05-01T12:00:00Z"
}PUT /write-off/set-status/{id}
Transition a write-off to CANCELED state. This is the only valid state transition — it reverses stock, cancels the linked invoice, and posts a CREDIT reconciliation act. Only status: "canceled" is accepted; write-offs are created directly in DONE state.
Yo‘l parametrlari
| Parametr | Tur | Majburiy | Tavsif |
|---|---|---|---|
id | string | Ha | Write-off ObjectId |
So‘rov tanasi
| Maydon | Tur | Majburiy | Tavsif |
|---|---|---|---|
status | string | Ha | Target status. Only canceled is accepted — write-offs are created directly in DONE state and the only permitted transition is DONE → canceled.. Mumkin qiymatlar: canceled |
reason | string | Yo‘q | Optional free-text reason for the cancellation |
{
"status": "canceled",
"reason": "string"
}Javob
Javob tuzilishi quyidagi bilan bir xil: POST /write-off/create.
GET /write-off/get-by-id/{id}
Fetch a single write-off by ObjectId with full detail (products, organization, responsible employee, reason, currency, warehouses, attachments).
Yo‘l parametrlari
| Parametr | Tur | Majburiy | Tavsif |
|---|---|---|---|
id | string | Ha | Write-off ObjectId |
So‘rov tanasi
So‘rov tanasi talab qilinmaydi.
Javob
Javob tuzilishi quyidagi bilan bir xil: POST /write-off/create.
POST /write-off/get-paging
Paginated list of write-offs. Filterable by organization, warehouse, responsible employee, action type, and date range.
So‘rov tanasi
| Maydon | Tur | Majburiy | Tavsif |
|---|---|---|---|
page | number | Ha | Standart: 1 |
limit | number | Ha | Standart: 20 |
organization_id | string | Yo‘q | Filter by organization ObjectId |
warehouse_id | string | Yo‘q | Filter by source warehouse ObjectId |
responsible_id | string | Yo‘q | Filter by responsible employee ObjectId |
action | string | Yo‘q | Filter by write-off action type. Mumkin qiymatlar: remove, defect |
{
"page": 1,
"limit": 20,
"organization_id": "string",
"warehouse_id": "string",
"responsible_id": "string",
"action": "remove"
}Javob
| Maydon | Tur | Tavsif |
|---|---|---|
total | number | |
list | object[] | |
list[]._id | string | |
list[].number | string | |
list[].code | string | |
list[].write_date | string (date-time) | |
list[].action | string | Mumkin qiymatlar: remove, defect |
list[].state | string | Mumkin qiymatlar: done, canceled |
list[].total_cost | number | |
list[].organization | object | |
list[].organization._id | string | |
list[].organization.name | string | |
list[].responsible_employee | object | |
list[].responsible_employee._id | string | |
list[].responsible_employee.full_name | string | |
list[].reason | object | |
list[].reason._id | string | |
list[].reason.name | string | |
list[].source_warehouse | object | |
list[].source_warehouse._id | string | |
list[].source_warehouse.name | string | |
list[].created_at | string (date-time) |
{
"code": 0,
"message": "Success",
"status_code": 200,
"data": {
"total": 0,
"list": [
{
"_id": "string",
"number": "string",
"code": "string",
"write_date": "2025-05-01T12:00:00Z",
"action": "remove",
"state": "done",
"total_cost": 0,
"organization": {
"_id": null,
"name": null
},
"responsible_employee": {
"_id": null,
"full_name": null
},
"reason": {
"_id": null,
"name": null
},
"source_warehouse": {
"_id": null,
"name": null
},
"created_at": "2025-05-01T12:00:00Z"
}
]
},
"time": "2025-05-01T12:00:00Z"
}Bu sahifa OpenAPI spetsifikatsiyasidan yaratilgan.