refactor(shipping-review): 统一复核投影与正式订单事实来源
复核投影统一读取 ShippingOrderTask、ShippingOrderSnapshot,清理 line_key 血缘投影
This commit is contained in:
1 parent
cd2967748b
commit
761a06e21a
5 files changed
+132
-58
No files matched your search
@@ -25,9 +25,11 @@ from app.models import (
|
||||
ShippingOrderLine,
|
||||
ShippingOrderSchema,
|
||||
ShippingOrderSchemaVersion,
|
||||
ShippingOrderCustomerMatch,
|
||||
ShippingCustomerShadowResolution,
|
||||
ShippingOrderCandidate,
|
||||
ShippingOrderIntake,
|
||||
ShippingCustomer,
|
||||
ShippingNotice,
|
||||
ShippingOrderTask,
|
||||
User,
|
||||
)
|
||||
from app.services.shipping_notice.freeze_readiness_service import assert_freeze_readiness
|
||||
@@ -43,7 +45,7 @@ from app.services.shipping_notice.order_freeze_service import (
|
||||
def _build_accepted_order(*, with_unverified_llm: bool = False, with_extension: bool = False, suffix: str = '001'):
|
||||
"""创建一份含预置核心字段的已接受解析;可加入扩展字段验证配置化履约。"""
|
||||
user = User(username=f'snapshot-user-{suffix}', email=f'snapshot-user-{suffix}@example.test', password_hash='x')
|
||||
task = ShippingNotice(task_no=f'SN-SNAPSHOT-{suffix}', source_type='test', order_data_version=7)
|
||||
task = ShippingOrderTask(task_no=f'OT-SNAPSHOT-{suffix}', source_type='direct_pdf', user_id=1, order_data_version=7)
|
||||
schema = ShippingOrderSchema(schema_code='SHIPPING_ORDER', display_name='Frozen order')
|
||||
db.session.add_all([user, task, schema])
|
||||
db.session.flush()
|
||||
@@ -82,7 +84,7 @@ def _build_accepted_order(*, with_unverified_llm: bool = False, with_extension:
|
||||
)
|
||||
db.session.add(extraction)
|
||||
db.session.flush()
|
||||
line = ShippingOrderLine(extraction_id=extraction.id, position=0)
|
||||
line = ShippingOrderLine(extraction_id=extraction.id, position=0, line_no=1)
|
||||
db.session.add(line)
|
||||
db.session.flush()
|
||||
values = {
|
||||
@@ -119,13 +121,26 @@ def _build_accepted_order(*, with_unverified_llm: bool = False, with_extension:
|
||||
customer = ShippingCustomer(standard_name='Snapshot Customer', short_code='CUS')
|
||||
db.session.add(customer)
|
||||
db.session.flush()
|
||||
db.session.add(ShippingOrderCustomerMatch(
|
||||
extraction_id=extraction.id, role='bill_to', raw_name='Snapshot Customer',
|
||||
normalized_name='SNAPSHOT CUSTOMER', status='confirmed', customer_id=customer.id,
|
||||
customer_name_snapshot=customer.standard_name, customer_short_code_snapshot=customer.short_code,
|
||||
identity_fingerprint='f' * 64, identity_rule_version='order-customer-fingerprint.v1',
|
||||
identity_components_json={'role': 'bill_to'}, resolution_method='manual',
|
||||
confirmation_reason='测试确认', confirmed_by_id=user.id, confirmed_at=datetime.utcnow(),
|
||||
intake = ShippingOrderIntake(
|
||||
intake_no=f'INT-SNAPSHOT-{suffix}', asset_id=1, user_id=user.id, parser_version='test',
|
||||
)
|
||||
db.session.add(intake)
|
||||
db.session.flush()
|
||||
candidate = ShippingOrderCandidate(
|
||||
candidate_no=f'CAND-SNAPSHOT-{suffix}', intake_id=intake.id, primary_document_id=1,
|
||||
candidate_key=f'snapshot-{suffix}', order_extraction_id=extraction.id, candidate_status='accepted',
|
||||
)
|
||||
db.session.add(candidate)
|
||||
db.session.flush()
|
||||
task.candidate_id = candidate.id
|
||||
db.session.add(ShippingCustomerShadowResolution(
|
||||
candidate_id=candidate.id, intake_id=intake.id, resolution_version='test.v1', status='confirmed',
|
||||
evidence_json=[{'definition_code': 'test_customer', 'normalized_value': customer.short_code}],
|
||||
candidate_matches_json=[{'customer_id': customer.id, 'score': 100}],
|
||||
resolution_context_json={'rule_set': {'checksum': 'f' * 64}},
|
||||
identity_rule_set_checksum='f' * 64, top_customer_id=customer.id, top_score=100,
|
||||
confirmed_customer_id=customer.id, confirmation_method='manual', confirmed_by_id=user.id,
|
||||
confirmed_at=datetime.utcnow(),
|
||||
))
|
||||
db.session.commit()
|
||||
return task, user
|
||||
@@ -141,7 +156,7 @@ def test_freeze_creates_strong_snapshot_and_preserves_identifiers(app):
|
||||
assert task.order_snapshot_id == snapshot.id
|
||||
assert snapshot.customer_short_code_snapshot == 'CUS'
|
||||
assert snapshot.customer_id is not None
|
||||
assert snapshot.rule_versions_json['ordering_customer']['identity_rule_version'] == 'order-customer-fingerprint.v1'
|
||||
assert snapshot.rule_versions_json['ordering_customer']['identity_rule_set_checksum'] == 'f' * 64
|
||||
assert snapshot.lines[0].part_number == '000123'
|
||||
assert snapshot.lines[0].reservation_id == '0012345678'
|
||||
assert snapshot.lines[0].qty == Decimal('12.50000000')
|
||||
@@ -225,10 +240,9 @@ def test_freeze_rejects_unconfirmed_or_caller_supplied_customer(app):
|
||||
"""冻结只能采纳已确认订购客户,调用者传 customer_id 不能绕过该链路。"""
|
||||
with app.app_context():
|
||||
task, user = _build_accepted_order()
|
||||
match = ShippingOrderCustomerMatch.query.filter_by(
|
||||
extraction_id=task.current_order_extraction_id, role='bill_to',
|
||||
).one()
|
||||
match.status = 'unique_candidate'
|
||||
resolution = ShippingCustomerShadowResolution.query.filter_by(candidate_id=task.candidate_id).one()
|
||||
resolution.status = 'unique_candidate'
|
||||
resolution.confirmed_customer_id = None
|
||||
with pytest.raises(ValidationError) as error:
|
||||
freeze_order_snapshot(task, actor_id=user.id, expected_order_data_version=7)
|
||||
assert error.value.code == 'SHIPPING.ORDER_CUSTOMER_CONFIRMATION_REQUIRED'
|
||||
|
||||
Reference in new issue
Block a user