fix(shipping-notice): 客户简码允许重复解除全局唯一约束
- short_code 去除 unique,新增迁移 sd9e8f7a6b5c 删除唯一约束 - 服务层移除简码唯一校验,导入预检移除撞码 warning - 清理四语言失效错误码,同步 demand/tec/technical 文档描述
This commit is contained in:
1 parent
20835dcfc0
commit
34fe0c4d78
13 files changed
+67
-55
No files matched your search
@@ -16,7 +16,7 @@ from openpyxl import Workbook
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
from app import db
|
||||
from app.core.errors import ConflictError, ValidationError
|
||||
from app.core.errors import ValidationError
|
||||
from app.models import (
|
||||
ShippingCustomer,
|
||||
ShippingCustomerExternalRef,
|
||||
@@ -177,8 +177,8 @@ def test_publish_uses_row_source_system_for_customer_and_identifier(app):
|
||||
assert b'identifier_created' in csv_content
|
||||
|
||||
|
||||
def test_publish_conflict_rolls_back_entire_batch(app):
|
||||
"""发布中出现简码唯一冲突时,客户、来源映射和逐行结果全部回滚。"""
|
||||
def test_publish_allows_duplicate_short_codes(app):
|
||||
"""简码允许重复:同批两行共用简码须整批发布成功,创建两个同简码客户。"""
|
||||
with app.app_context():
|
||||
batch = create_import_batch(
|
||||
_make_upload([
|
||||
@@ -188,12 +188,12 @@ def test_publish_conflict_rolls_back_entire_batch(app):
|
||||
source_system='ERP',
|
||||
actor_id=None,
|
||||
)
|
||||
published = publish_import_batch(batch['id'], actor_id=None)
|
||||
|
||||
with pytest.raises(ConflictError) as exc_info:
|
||||
publish_import_batch(batch['id'], actor_id=None)
|
||||
assert exc_info.value.code == 'SHIPPING.CUSTOMER_IMPORT_PUBLISH_CONFLICT'
|
||||
assert db.session.query(ShippingCustomer).count() == 0
|
||||
assert db.session.query(ShippingCustomerExternalRef).count() == 0
|
||||
persisted = db.session.get(ShippingCustomerImportBatch, batch['id'])
|
||||
assert persisted.status == 'validated'
|
||||
assert all(row.result_status is None for row in persisted.rows)
|
||||
# 断言整批发布成功且两个客户共用简码 DUP,各自持有独立来源映射
|
||||
assert published['status'] == 'published'
|
||||
customers = db.session.query(ShippingCustomer).filter_by(short_code='DUP').all()
|
||||
assert len(customers) == 2
|
||||
assert {ref.legacy_customer_key for ref in db.session.query(ShippingCustomerExternalRef).all()} == {
|
||||
'ERP-101', 'ERP-102',
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import pytest
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from app import db
|
||||
from app.core.errors import ConflictError, ValidationError
|
||||
from app.core.errors import ValidationError
|
||||
from app.models import (
|
||||
ShippingCustomer, ShippingCustomerIdentifier, ShippingCustomerLifecycleEvent, ShippingNotice,
|
||||
ShippingOrderExtraction, ShippingOrderSchema, ShippingOrderSchemaVersion,
|
||||
@@ -56,15 +56,16 @@ def _notice_for_customer(customer_id: int) -> ShippingNotice:
|
||||
return notice
|
||||
|
||||
|
||||
def test_customer_short_code_is_normalized_and_unique(app):
|
||||
"""简码统一转大写,且标准化后重复必须返回冲突。"""
|
||||
def test_customer_short_code_is_normalized_and_duplicate_allowed(app):
|
||||
"""简码统一转大写;业务允许不同标准客户共用同一简码,仅格式非法才拒绝。"""
|
||||
with app.app_context():
|
||||
created = _create_customer(short_code='wyc')
|
||||
assert created['short_code'] == 'WYC'
|
||||
|
||||
with pytest.raises(ConflictError) as exc_info:
|
||||
_create_customer(name='另一客户', short_code='WYC')
|
||||
assert exc_info.value.code == 'SHIPPING.CUSTOMER_SHORT_CODE_EXISTS'
|
||||
# 重复简码(含小写归一后撞码)必须创建成功,不再返回冲突
|
||||
duplicated = _create_customer(name='另一客户', short_code='wyc')
|
||||
assert duplicated['short_code'] == 'WYC'
|
||||
assert db.session.query(ShippingCustomer).filter_by(short_code='WYC').count() == 2
|
||||
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
_create_customer(name='格式错误客户', short_code='W1')
|
||||
|
||||
Reference in new issue
Block a user