forked from erp-dev/erp
fix: added permission for plate_order and printing_order api
This commit is contained in:
@@ -67,6 +67,71 @@ python manage.py backfill_merchant <merchant_id>
|
||||
|
||||
---
|
||||
|
||||
### 5. 创建出货单 API
|
||||
|
||||
实现了创建出货单的 API,支持同时关联多个销售品。
|
||||
|
||||
- **接口路径**: `POST /api/v1/shipment/shipments/`
|
||||
- **请求参数**: `customer`(客户ID)、`shipment_date`(出货日期)、`remark`(备注)、`sales_items`(销售品ID列表)
|
||||
|
||||
#### 业务逻辑
|
||||
1. 验证客户存在
|
||||
2. 验证销售品存在且未被关联到其他出货单
|
||||
3. 创建出货单并将销售品关联到该出货单(事务保护)
|
||||
|
||||
#### 修改文件
|
||||
- `shipment/services.py`: 添加 `create_shipment()` 函数
|
||||
- `api_v1/views/shipment/views.py`: 添加 `ShipmentCreateView`
|
||||
- `api_v1/views/shipment/serializers.py`: 添加 `ShipmentSerializer`、`ShipmentCreateSerializer`
|
||||
- `api_v1/views/shipment/test_api.py`: 添加 6 个测试用例
|
||||
- `api_v1/urls.py`: 注册新路由
|
||||
- `docs/shipment_api.md`: 更新 API 文档
|
||||
|
||||
---
|
||||
|
||||
### 6. 添加销售品自动创建开关
|
||||
|
||||
在 `settings.py` 中添加 `AUTO_CREATE_SALESITEM_FROM_PRINT_ORDER` 配置项:
|
||||
|
||||
- **默认值**: `True`(保持现有行为)
|
||||
- **环境变量**: `AUTO_CREATE_SALESITEM_FROM_PRINT_ORDER`
|
||||
- **作用**: 当设为 `False` 时,`printing/handlers.py` 中的流程完成信号处理器将不再自动创建销售品
|
||||
|
||||
#### 修改文件
|
||||
- `flower/settings.py`: 添加配置项
|
||||
- `printing/handlers.py`: 检查开关状态,为 False 时提前返回
|
||||
|
||||
---
|
||||
|
||||
### 7. Printing 模块客户可见性过滤
|
||||
|
||||
实现了基于客户可见性的订单查询过滤功能,确保员工只能看到自己负责的客户的订单。
|
||||
|
||||
#### 新增权限
|
||||
- `printing.view_all_plateorders`: 查看所有开版订单(突破客户可见性限制)
|
||||
- `printing.view_all_printingorders`: 查看所有印染订单(突破客户可见性限制)
|
||||
|
||||
#### 可见性规则
|
||||
- 超级用户:无限制
|
||||
- 有 `view_all_xxx` 权限:可见本商户所有订单
|
||||
- 普通员工:
|
||||
- 可见自己创建的客户的订单
|
||||
- 可见被加入 `visible_employees` 的客户的订单
|
||||
- 所有用户:受 merchant 隔离限制
|
||||
|
||||
#### 新建文件
|
||||
- `api_v1/views/printing/mixins.py`: `CustomerVisibilityFilterMixin`
|
||||
|
||||
#### 修改文件
|
||||
- `printing/models.py`: 添加新权限定义
|
||||
- `api_v1/views/printing/views.py`: 三个 ViewSet 继承 Mixin
|
||||
- `api_v1/views/printing/test_api.py`: 修复测试数据 + 新增 7 个权限过滤测试
|
||||
|
||||
#### Migration
|
||||
- `printing/migrations/0030_add_view_all_permissions.py`
|
||||
|
||||
---
|
||||
|
||||
## 待办
|
||||
|
||||
---
|
||||
@@ -75,4 +140,4 @@ python manage.py backfill_merchant <merchant_id>
|
||||
|
||||
- API 独立于 printing 模块,避免影响现有功能
|
||||
- 完整的测试覆盖:正常查询、包含已出货、数据格式、404 错误、空结果、未认证
|
||||
- printing 和 shipment 模块全部测试通过(31个测试用例)
|
||||
- printing 和 shipment 模块全部测试通过(共 13 个测试用例)
|
||||
@@ -4,10 +4,101 @@
|
||||
|
||||
## 目录
|
||||
|
||||
- [创建出货单](#创建出货单)
|
||||
- [通过生产订单查询销售品](#通过生产订单查询销售品)
|
||||
|
||||
---
|
||||
|
||||
## 创建出货单
|
||||
|
||||
创建出货单并关联销售品。
|
||||
|
||||
### 接口信息
|
||||
|
||||
- **URL**: `/api/v1/shipment/shipments/`
|
||||
- **Method**: `POST`
|
||||
- **认证**: 需要登录(JWT Token)
|
||||
|
||||
### 请求参数
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| customer | int | 是 | 客户ID |
|
||||
| shipment_date | string | 是 | 出货日期(YYYY-MM-DD) |
|
||||
| remark | string | 否 | 备注 |
|
||||
| sales_items | array[int] | 否 | 要关联的销售品ID列表 |
|
||||
|
||||
### 请求示例
|
||||
|
||||
```json
|
||||
{
|
||||
"customer": 1,
|
||||
"shipment_date": "2026-01-14",
|
||||
"remark": "备注信息",
|
||||
"sales_items": [1, 2, 3]
|
||||
}
|
||||
```
|
||||
|
||||
### 响应格式
|
||||
|
||||
```json
|
||||
{
|
||||
"id": 1,
|
||||
"customer": 1,
|
||||
"customer_name": "客户A",
|
||||
"shipment_date": "2026-01-14",
|
||||
"remark": "备注信息",
|
||||
"items_count": 3,
|
||||
"created_by_id": 1,
|
||||
"created_by_name": "张三",
|
||||
"created_at": "2026-01-14T10:00:00Z",
|
||||
"updated_at": "2026-01-14T10:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
### 响应字段说明
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | int | 出货单ID |
|
||||
| customer | int | 客户ID |
|
||||
| customer_name | string | 客户名称 |
|
||||
| shipment_date | string | 出货日期 |
|
||||
| remark | string | 备注 |
|
||||
| items_count | int | 关联的销售品数量 |
|
||||
| created_by_id | int | 创建人ID |
|
||||
| created_by_name | string | 创建人名称 |
|
||||
| created_at | string | 创建时间 |
|
||||
| updated_at | string | 更新时间 |
|
||||
|
||||
### 错误响应
|
||||
|
||||
#### 400 Bad Request - 客户不存在
|
||||
|
||||
```json
|
||||
{
|
||||
"detail": "客户 999 不存在"
|
||||
}
|
||||
```
|
||||
|
||||
#### 400 Bad Request - 销售品不存在
|
||||
|
||||
```json
|
||||
{
|
||||
"detail": "以下销售品不存在: [999]"
|
||||
}
|
||||
```
|
||||
|
||||
#### 400 Bad Request - 销售品已关联其他出货单
|
||||
|
||||
```json
|
||||
{
|
||||
"detail": "以下销售品已关联到其他出货单: [1, 2]"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 通过生产订单查询销售品
|
||||
|
||||
查询与指定生产订单(PrintingOrder)关联的所有销售品(SalesItem)。
|
||||
|
||||
Reference in New Issue
Block a user