1
0
forked from erp-dev/erp
Files
erpnew/docs/2026-01-14_summary.md

78 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 2026-01-14 工作日志
## 已完成
### 1. 通过生产订单查询销售品 API
创建了独立的 Shipment API 模块,提供出货管理相关接口。
- **接口路径**: `GET /api/v1/shipment/sales-items/by-printing-order/<printing_order_id>/`
- **查询参数**: `include_already_has_shipment`(默认 false不包含已出货的销售品
#### 新建文件
- `api_v1/views/shipment/__init__.py`: 模块入口
- `api_v1/views/shipment/views.py`: API 视图 `SalesItemByPrintingOrderView`
- `api_v1/views/shipment/serializers.py`: 序列化器 `SalesItemSerializer`
- `api_v1/views/shipment/test_api.py`: API 测试用例8 个测试场景)
- `shipment/services.py`: 业务逻辑层 `get_sales_items_by_printing_order()`
- `docs/shipment_api.md`: API 文档
#### 修改文件
- `api_v1/urls.py`: 注册新路由
#### 业务逻辑
1. 根据 PrintingOrder ID 获取所有 PrintingJob 的 ID
2. 查询 SalesItem过滤 printing_job_id 在这些 job_ids 中
3. 根据参数决定是否过滤已关联出货单的销售品
---
### 2. Printing 模块添加 merchant 字段
为多租户支持,为 printing 模块的核心模型添加 `merchant` 外键字段:
- `PlateOrder.merchant` - 开版订单所属商户
- `PrintingOrder.merchant` - 印染订单所属商户
- `PrintingJob.merchant` - 印染任务所属商户
所有字段设置为可空(`null=True, blank=True`),以兼容现有数据。
**迁移文件**: `printing/migrations/0029_add_merchant_to_models.py`
---
### 3. 确保 API 创建时自动绑定 merchant
修复了创建 API确保新建记录时自动从当前用户获取 merchant
- `PrintingOrderService.create_printing_order()` - 自动绑定 merchant
- `PrintingJobService.create_printing_job()` - 自动绑定 merchant
- `PlateOrderViewSet.perform_create()` - 自动绑定 merchant
---
### 4. 数据补录命令
创建了 management command 用于补录历史数据的 merchant_id
```bash
# 预览(不执行)
python manage.py backfill_merchant <merchant_id> --dry-run
# 执行补录
python manage.py backfill_merchant <merchant_id>
```
**文件**: `printing/management/commands/backfill_merchant.py`
---
## 待办
---
## 备注
- API 独立于 printing 模块,避免影响现有功能
- 完整的测试覆盖正常查询、包含已出货、数据格式、404 错误、空结果、未认证
- printing 和 shipment 模块全部测试通过31个测试用例