1
0
forked from erp-dev/erp

feat: allocation record for pre sales order

This commit is contained in:
2026-02-01 22:57:16 +08:00
parent a633a617d5
commit ac065e115e
14 changed files with 1955 additions and 44 deletions

View File

@@ -0,0 +1,273 @@
# API v1预销售单 / 预采购单(前端对接)
本文档面向前端描述预销售单PreSalesOrder与预采购单PrePurchaseOrder的 API、字段与参数。
- API 前缀:`/api/v1/`
- 认证:接口均要求登录(`IsAuthenticated`)。
- 权限:要求当前用户绑定员工(`request.user.employee`),否则返回 `403`
## 分页Limit/Offset
预销售单列表、预采购单列表均使用 DRF `LimitOffsetPagination`
- `limit`:返回条数,默认 `20`,最大 `100`
- `offset`:偏移量,默认 `0`
分页响应结构:
```json
{
"count": 123,
"next": "http://.../api/v1/pre-sales-orders/?limit=20&offset=20",
"previous": null,
"results": [
{ "id": 1, "human_id": "YS...", "items": [] }
]
}
```
## 列表查询参数(已支持)
预销售单列表 `GET /pre-sales-orders/`
- `limit` / `offset`
- `customer` / `customer_id`int
- `warehouse` / `warehouse_id`int
- `kind`int
- `human_id__icontains`string
- `created_at_from`datetime 或 date
- `created_at_to`datetime 或 date
预采购单列表 `GET /pre-purchase-orders/`
- `limit` / `offset`
- `supplier` / `supplier_id`int
- `warehouse` / `warehouse_id`int
- `kind`int
- `human_id__icontains`string
- `created_at_from`datetime 或 date
- `created_at_to`datetime 或 date
---
# 预销售单 PreSalesOrder
## 1) 列表
- `GET /api/v1/pre-sales-orders/?limit=20&offset=0`
- 查询参数:
- `limit`可选int默认 20最大 100
- `offset`可选int默认 0
- 响应:`200 OK`,分页结构,`results` 为预销售单数组
## 2) 创建
- `POST /api/v1/pre-sales-orders/`
请求体参数JSON
- `customer` / `customer_id`必填int客户 ID
- `warehouse` / `warehouse_id`必填int仓库 ID
- `kind`可选int预销售单类型
- `1`:大货
- `2`:样板
- 默认 `1`
- `remarks`可选string
- `items`必填array非空明细列表
`items[]` 字段:
- `product_id` / `product`必填int产品 ID
- `quantity`必填string 或 number数量会被转换为 Decimal
- `unit`可选string单位为空时会尝试使用产品默认单位
- `product_name`可选string产品名称弱关联承载
- `color`可选string
- `spec`可选string
- `quantity_of_rolls`可选string各条数数量原样保存
- `num_of_rolls`可选int条数必须 > 0默认 `1`
- `order_quantity`可选int下单数量必须为非负整数
- `remarks`可选string明细备注
响应:`201 CREATED`,返回预销售单详情(含 `items`)。
示例请求:
```json
{
"customer": 1,
"warehouse": 2,
"kind": 1,
"remarks": "预销售单备注",
"items": [
{
"product_id": 10,
"quantity": "12.5",
"unit": "米",
"order_quantity": 7,
"remarks": "明细备注"
}
]
}
```
## 3) 详情
- `GET /api/v1/pre-sales-orders/{id}/`
- 响应:`200 OK`,返回预销售单详情
## 4) 更新(全量/部分)
- `PUT /api/v1/pre-sales-orders/{id}/`
- `PATCH /api/v1/pre-sales-orders/{id}/`
请求体参数:
- `customer` / `customer_id`可选int
- `warehouse` / `warehouse_id`可选int
- `kind`可选int
- `remarks`可选string
- `items`必填array非空更新时必须提供否则会返回 `400`
响应:`200 OK`,返回更新后的详情。
## 5) 删除
- `DELETE /api/v1/pre-sales-orders/{id}/`
- 响应:`204 NO CONTENT`
## 预销售单字段说明(响应)
预销售单对象字段(`results[]` 与详情一致):
- `id`int主键
- `human_id`string人类可读编号`YSYYYYMMDD000001`
- `merchant`int所属商户 ID
- `merchant`int商户 ID调试字段
- `customer`int客户 ID
- `customer_name`string只读
- `warehouse`int仓库 ID
- `warehouse_name`string只读
- `operator`int|null经办人员工ID创建时由后端从登录用户推导
- `operator_name`string只读
- `kind`int类型1/2
- `remarks`string|null
- `created_at`datetime string
- `items`array明细只读
`items[]` 字段(响应):
- `id`int
- `product_id`int|null
- `product_name`string
- `color`string|null
- `quantity`string|null通常为两位小数`"20.00"`
- `unit`string
- `spec`string|null
- `remarks`string|null
---
# 预采购单 PrePurchaseOrder
## 1) 列表
- `GET /api/v1/pre-purchase-orders/?limit=20&offset=0`
- 查询参数:
- `limit`可选int默认 20最大 100
- `offset`可选int默认 0
- 响应:`200 OK`,分页结构
## 2) 创建
- `POST /api/v1/pre-purchase-orders/`
请求体参数JSON
- `supplier` / `supplier_id`必填int供应商 ID
- `warehouse` / `warehouse_id`必填int仓库 ID
- `kind`可选int预采购单类型
- `1`:大货
- `2`:样板
- 默认 `1`
- `remarks`可选string
- `items`必填array非空明细列表字段同预销售明细
响应:`201 CREATED`,返回预采购单详情(含 `items`)。
示例请求:
```json
{
"supplier": 1,
"warehouse": 2,
"kind": 1,
"remarks": "预采购单备注",
"items": [
{
"product_id": 10,
"quantity": "12.5",
"unit": "米",
"order_quantity": 7,
"remarks": "明细备注"
}
]
}
```
## 3) 详情
- `GET /api/v1/pre-purchase-orders/{id}/`
- 响应:`200 OK`
## 4) 更新(全量/部分)
- `PUT /api/v1/pre-purchase-orders/{id}/`
- `PATCH /api/v1/pre-purchase-orders/{id}/`
请求体参数:
- `supplier` / `supplier_id`可选int
- `warehouse` / `warehouse_id`可选int
- `kind`可选int
- `remarks`可选string
- `items`必填array非空更新时必须提供否则会返回 `400`
响应:`200 OK`
## 5) 删除
- `DELETE /api/v1/pre-purchase-orders/{id}/`
- 响应:`204 NO CONTENT`
## 预采购单字段说明(响应)
预采购单对象字段(`results[]` 与详情一致):
- `id`int
- `human_id`string人类可读编号`YCYYYYMMDD000001`
- `merchant`int
- `merchant`int商户 ID调试字段
- `supplier`int
- `supplier_name`string只读
- `warehouse`int
- `warehouse_name`string只读
- `operator`int|null
- `operator_name`string只读
- `kind`int1/2
- `remarks`string|null
- `created_at`
- `items`array只读
`items[]` 字段同预销售明细响应。
---
# 错误响应约定(两类接口通用)
- `400 BAD REQUEST`:参数校验失败
- 示例:`{"error": "items 需要为非空数组"}`
- `401 UNAUTHORIZED`:未登录
- `403 FORBIDDEN`:无员工信息/无权限
- 示例:`{"error": "无权限访问"}`
- `404 NOT FOUND`:订单不存在
- 示例:`{"error": "预销售单不存在"}` / `{"error": "预采购单不存在"}`