guzhi/.trae/documents/修复添加发票抬头必填项校验.md
邹方成 c15f3e9925 fix(invoice): 移除发票创建模型中不必要的必填限制
refactor(valuations): 添加估值计算前的用户配额检查逻辑

docs: 添加发票抬头必填字段的修改方案文档
2025-11-26 18:17:47 +08:00

35 lines
1.3 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.

## 目标
* 添加抬头时将 `公司名称``公司税号``电子邮箱`设为必填,其他字段可为空。
* 现状确认(代码引用)
- 后端必填:`app/schemas/invoice.py:612``InvoiceHeaderCreate` 已要求 `company_name``tax_number` 为必填,`email: EmailStr` 为必填。
- API 入口:`app/api/v1/app_invoices/app_invoices.py:5558` 新增抬头接口使用 `InvoiceHeaderCreate`,后端将严格校验三项必填。
## 修改方案
1. 统一前端校验文案
* 统一三项必填的错误提示为简洁中文,如:“请输入公司名称 / 公司税号 / 电子邮箱”。
* 邮箱格式提示统一为:“请输入有效的电子邮箱”。
2. 后端校验与返回确认
* 保持 `InvoiceHeaderCreate` 的必填与格式限制不变(`app/schemas/invoice.py:612`)。
* 确认更新接口 `InvoiceHeaderUpdate``app/schemas/invoice.py:3239`)允许局部更新、但不影响创建必填逻辑。
3. 验证与测试
* 后端接口验证:对 `POST /app-invoices/headers``app/api/v1/app_invoices/app_invoices.py:5558`)进行用例:缺失任一必填字段应返回 422全部正确应 200/201。
* 可补充最小化单元测试Pydantic 校验用例覆盖必填与格式。
## 交付内容。
* 完成基本交互与接口验证,确保行为符合预期。