feat(shipping_notice): 支持客户 ODM 白名单与整单 ODM 选择收敛导出
- 客户主数据新增 odm_ids 白名单字段(含 Alembic 迁移),表单与管理端支持维护 - 导出库存命中行按客户白名单与整单 ODM 裁决收敛,新增 notice_odm_choice_service - 工作台新增 odm-options / odm-choice 接口,投影行级候选并持久化用户选择 - 修复复核工作台跨 Run 切换时接收解析上下文残留 - 同步四语言 i18n、测试用例、funclist 与 shipping-notice 技术文档
This commit is contained in:
1 parent
a032354cb9
commit
d396371020
51 files changed
+2717
-109
No files matched your search
@@ -37,6 +37,47 @@ from app.services.shipping_notice.customer_normalization import (
|
||||
|
||||
CUSTOMER_STATUSES = frozenset({'active', 'inactive', 'merged'})
|
||||
IDENTIFIER_STATUSES = frozenset({'pending', 'approved', 'disabled'})
|
||||
_ODM_ID_MAX_ITEMS = 100
|
||||
_ODM_ID_MAX_LENGTH = 64
|
||||
|
||||
|
||||
def _normalize_odm_ids(value: Any) -> list[str] | None:
|
||||
"""
|
||||
规范化客户 ODM ID 清单:逐项 trim、去空、去重(保持原顺序)。
|
||||
|
||||
Args:
|
||||
value: 前端提交的清单(字符串列表);None 表示未提交,空列表表示清空。
|
||||
Returns:
|
||||
规范化后的清单;None 仅当输入为 None。
|
||||
Raises:
|
||||
ValidationError: 条目超长或清单超量。
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
if not isinstance(value, list):
|
||||
raise ValidationError(
|
||||
'ODM ID list must be an array of strings',
|
||||
code='SHIPPING.CUSTOMER_ODM_IDS_INVALID',
|
||||
)
|
||||
normalized: list[str] = []
|
||||
for item in value:
|
||||
text = str(item or '').strip()
|
||||
if not text:
|
||||
continue
|
||||
if len(text) > _ODM_ID_MAX_LENGTH:
|
||||
raise ValidationError(
|
||||
'ODM ID is too long',
|
||||
code='SHIPPING.CUSTOMER_ODM_IDS_INVALID',
|
||||
details={'odm_id': text},
|
||||
)
|
||||
if text not in normalized:
|
||||
normalized.append(text)
|
||||
if len(normalized) > _ODM_ID_MAX_ITEMS:
|
||||
raise ValidationError(
|
||||
'Too many ODM IDs',
|
||||
code='SHIPPING.CUSTOMER_ODM_IDS_INVALID',
|
||||
)
|
||||
return normalized
|
||||
|
||||
|
||||
def _record_lifecycle_event(
|
||||
@@ -142,6 +183,7 @@ def serialize_customer(
|
||||
'status': record.status,
|
||||
'merged_into_customer_id': record.merged_into_customer_id,
|
||||
'remark': record.remark,
|
||||
'odm_ids': list(record.odm_ids or []) if record.odm_ids is not None else None,
|
||||
'created_by_id': record.created_by_id,
|
||||
'updated_by_id': record.updated_by_id,
|
||||
'created_at': record.created_at.isoformat() if record.created_at else None,
|
||||
@@ -318,6 +360,7 @@ def create_customer(data: dict[str, Any], *, actor_id: int | None) -> dict[str,
|
||||
short_code=short_code,
|
||||
status=status,
|
||||
remark=clean_text(data.get('remark')) or None,
|
||||
odm_ids=_normalize_odm_ids(data.get('odm_ids')) if 'odm_ids' in data else None,
|
||||
created_by_id=actor_id,
|
||||
updated_by_id=actor_id,
|
||||
)
|
||||
@@ -385,11 +428,13 @@ def update_customer(customer_id: int, data: dict[str, Any], *, actor_id: int | N
|
||||
'short_code': record.short_code,
|
||||
'status': record.status,
|
||||
'remark': record.remark,
|
||||
'odm_ids': list(record.odm_ids or []) if record.odm_ids is not None else None,
|
||||
}
|
||||
next_name = before['standard_name']
|
||||
next_short_code = before['short_code']
|
||||
next_status = before['status']
|
||||
next_remark = before['remark']
|
||||
next_odm_ids = before['odm_ids']
|
||||
if 'standard_name' in data:
|
||||
name = clean_text(data.get('standard_name'))
|
||||
if not name:
|
||||
@@ -404,11 +449,14 @@ def update_customer(customer_id: int, data: dict[str, Any], *, actor_id: int | N
|
||||
raise ValidationError('Invalid customer status', code='SHIPPING.CUSTOMER_STATUS_INVALID')
|
||||
if 'remark' in data:
|
||||
next_remark = clean_text(data.get('remark')) or None
|
||||
if 'odm_ids' in data:
|
||||
next_odm_ids = _normalize_odm_ids(data.get('odm_ids'))
|
||||
after = {
|
||||
'standard_name': next_name,
|
||||
'short_code': next_short_code,
|
||||
'status': next_status,
|
||||
'remark': next_remark,
|
||||
'odm_ids': next_odm_ids,
|
||||
}
|
||||
changes = {key: {'before': before[key], 'after': after[key]} for key in before if before[key] != after[key]}
|
||||
if changes:
|
||||
@@ -418,6 +466,7 @@ def update_customer(customer_id: int, data: dict[str, Any], *, actor_id: int | N
|
||||
record.short_code = next_short_code
|
||||
record.status = next_status
|
||||
record.remark = next_remark
|
||||
record.odm_ids = next_odm_ids
|
||||
record.updated_by_id = actor_id
|
||||
_record_lifecycle_event(
|
||||
record,
|
||||
|
||||
Reference in new issue
Block a user