feat(freight-rpa): 库存/收料改名在手/入站,报表归属RPA,类名统一FreightRpa
把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与 枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa 持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀, 上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ffc0d4a430
commit
39fe3c05f2
453 files changed
+17945
-8646
No files matched your search
@@ -17,11 +17,11 @@ import pytest
|
||||
|
||||
from app import db
|
||||
from app.models import (
|
||||
ShippingExcelTemplate, ShippingInventoryParsingProfile, ShippingInventorySource, ShippingOrderExtraction,
|
||||
ShippingExcelTemplate, FreightRpaOnhandReportConfig, FreightRpaParsingProfile, FreightRpaSource, ShippingOrderExtraction,
|
||||
ShippingOrderField, ShippingOrderFieldDecision, ShippingOrderFieldValue, ShippingOrderLine,
|
||||
ShippingCustomer, ShippingInventoryField, ShippingInventoryFile, ShippingOrderSchema, ShippingOrderSchemaVersion,
|
||||
ShippingOrderSnapshot, ShippingOrderSnapshotLine, ShippingRpaProfile, ShippingNotice, ShippingOrderTask,
|
||||
ShippingNoticeLineInventoryMatch, ShippingTaskInventoryLink,
|
||||
ShippingCustomer, FreightRpaOnhandField, FreightRpaOnhandReportFile, ShippingOrderSchema, ShippingOrderSchemaVersion,
|
||||
ShippingOrderSnapshot, ShippingOrderSnapshotLine, FreightRpaProfile, ShippingNotice, ShippingOrderTask,
|
||||
ShippingNoticeLineOnhandMatch, ShippingTaskOnhandLink,
|
||||
)
|
||||
from app.services.shipping_notice import excel_template
|
||||
from app.services.shipping_notice.export import (
|
||||
@@ -34,7 +34,7 @@ from app.services.shipping_notice.export import (
|
||||
)
|
||||
from app.services.shipping_notice.fulfillment_workflow import _commit_generated_export
|
||||
from app.services.shipping_notice.notice_line_service import replace_notice_lines_from_snapshot
|
||||
from app.services.shipping_notice.inventory_file_store import (
|
||||
from app.services.shipping_notice.onhand_file_store import (
|
||||
active_inventory_lines_for_task,
|
||||
replace_task_inventory_link,
|
||||
resolve_inventory_lines_for_execution,
|
||||
@@ -53,7 +53,7 @@ def _lookup_standard_fields(*codes: str) -> dict[str, ShippingOrderField]:
|
||||
|
||||
def _inventory_field_id(field_code: str) -> str:
|
||||
"""返回库存字段目录 ID,使模板测试覆盖当前发布契约。"""
|
||||
return str(ShippingInventoryField.query.filter_by(field_code=field_code).one().id)
|
||||
return str(FreightRpaOnhandField.query.filter_by(field_code=field_code).one().id)
|
||||
|
||||
|
||||
def test_only_templates_consuming_system_warehouse_id_require_task_warehouse_fact():
|
||||
@@ -141,7 +141,7 @@ def _freeze_export_snapshot(
|
||||
|
||||
|
||||
def _materialize_export_notice(
|
||||
*, ot: ShippingOrderTask, snapshot: ShippingOrderSnapshot, inventory_file: ShippingInventoryFile,
|
||||
*, ot: ShippingOrderTask, snapshot: ShippingOrderSnapshot, inventory_file: FreightRpaOnhandReportFile,
|
||||
source_code: str, notice_no: str,
|
||||
) -> ShippingNotice:
|
||||
"""从 OT 的冻结快照构造正式 Notice、NoticeLine、匹配事实与活动库存链接。
|
||||
@@ -166,10 +166,10 @@ def _materialize_export_notice(
|
||||
},
|
||||
)
|
||||
for line in snapshot.lines:
|
||||
db.session.add(ShippingNoticeLineInventoryMatch(
|
||||
db.session.add(ShippingNoticeLineOnhandMatch(
|
||||
task_id=ot.id, snapshot_line_id=line.id, line_no=line.line_no,
|
||||
match_result='matched', inventory_status='ready',
|
||||
inventory_snapshot_id=inventory_file.id, inventory_source_code=source_code,
|
||||
match_result='matched', onhand_status='ready',
|
||||
onhand_snapshot_id=inventory_file.id, source_code=source_code,
|
||||
is_current=True, detail_json={},
|
||||
))
|
||||
db.session.flush()
|
||||
@@ -231,9 +231,9 @@ def test_inventory_execution_prefers_active_link_and_does_not_overwrite_task_cac
|
||||
"""业务执行必须使用活动库存 Link,忽略请求库存。"""
|
||||
with app.app_context():
|
||||
task = ShippingOrderTask(task_no='OT-INVENTORY-SOURCE', user_id=1)
|
||||
inventory_file = ShippingInventoryFile(
|
||||
inventory_file_no='SIF-INVENTORY-SOURCE', storage_path=str(tmp_path / 'inventory.xlsx'),
|
||||
inventory_lines_json=[{'part_number': 'ACTIVE'}], line_count=1,
|
||||
inventory_file = FreightRpaOnhandReportFile(
|
||||
onhand_file_no='SIF-INVENTORY-SOURCE', storage_path=str(tmp_path / 'inventory.xlsx'),
|
||||
onhand_lines_json=[{'part_number': 'ACTIVE'}], line_count=1,
|
||||
share_mode='task_only', snapshot_status='ready',
|
||||
)
|
||||
db.session.add_all([task, inventory_file])
|
||||
@@ -268,9 +268,9 @@ def test_active_inventory_json_is_not_silently_reparsed_from_stale_file(app, tmp
|
||||
storage_path = tmp_path / 'stale.xlsx'
|
||||
storage_path.write_bytes(b'stale-source')
|
||||
task = ShippingOrderTask(task_no='OT-INVENTORY-NO-REPARSE', user_id=1)
|
||||
inventory_file = ShippingInventoryFile(
|
||||
inventory_file_no='SIF-INVENTORY-NO-REPARSE', storage_path=str(storage_path),
|
||||
inventory_lines_json=[{'1': 'PN-A', '2': 'RSV-A', '6': 'ODM-FIXED'}],
|
||||
inventory_file = FreightRpaOnhandReportFile(
|
||||
onhand_file_no='SIF-INVENTORY-NO-REPARSE', storage_path=str(storage_path),
|
||||
onhand_lines_json=[{'1': 'PN-A', '2': 'RSV-A', '6': 'ODM-FIXED'}],
|
||||
line_count=1, share_mode='task_only', snapshot_status='ready',
|
||||
)
|
||||
db.session.add_all([task, inventory_file])
|
||||
@@ -284,7 +284,7 @@ def test_active_inventory_json_is_not_silently_reparsed_from_stale_file(app, tmp
|
||||
return ([{'1': 'PN-A', '2': 'RSV-A', '6': 'ODM-STALE'}], {})
|
||||
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_file_store.parse_inventory_snapshot_file', stale_reparse,
|
||||
'app.services.shipping_notice.onhand_file_store.parse_inventory_snapshot_file', stale_reparse,
|
||||
)
|
||||
|
||||
assert active_inventory_lines_for_task(task) == [
|
||||
@@ -358,23 +358,28 @@ def test_published_template_generates_dynamic_artifact(app, tmp_path):
|
||||
}, actor_id=None)
|
||||
published = excel_template.publish(draft['id'], actor_id=None)
|
||||
|
||||
parsing = ShippingInventoryParsingProfile(
|
||||
parsing = FreightRpaParsingProfile(
|
||||
profile_code='COMMON_INV', display_name='Common Inventory', version=1, status='published',
|
||||
file_format='xlsx', definition_json={
|
||||
'field_mapping': {_inventory_field_id('part_number'): 'Part No.', _inventory_field_id('odm_id'): 'ODM ID'},
|
||||
'match_keys': [{'order_field_id': part.id, 'inventory_field_id': _inventory_field_id('part_number')}],
|
||||
}, checksum='p' * 64,
|
||||
)
|
||||
login = ShippingRpaProfile(
|
||||
login = FreightRpaProfile(
|
||||
profile_code='LOGIN', display_name='Login', connector_type='dbs', login_url='https://invalid',
|
||||
login_config_json={'auth_mode': 'password'},
|
||||
)
|
||||
db.session.add_all([parsing, login])
|
||||
db.session.flush()
|
||||
source = ShippingInventorySource(
|
||||
source = FreightRpaSource(
|
||||
source_code='DUB', display_name='Dublin', connector_type='dbs', rpa_profile_id=login.id,
|
||||
parsing_profile_id=parsing.id, excel_template_id=published['id'], warehouse_resolution_mode='fixed',
|
||||
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[],
|
||||
excel_template_id=published['id'], warehouse_resolution_mode='fixed',
|
||||
fixed_warehouse_id='DUB',
|
||||
)
|
||||
# s18 起解析绑定/报表路径/查询条件归 FreightRpaOnhandReportConfig 配置行,随站点级联入库。
|
||||
FreightRpaOnhandReportConfig(
|
||||
source=source, parsing_profile_id=parsing.id,
|
||||
report_path_json={}, query_parameters_json=[],
|
||||
)
|
||||
ot = ShippingOrderTask(task_no='OT-EXPORT-1', user_id=1, status='ready', current_step='customer_review')
|
||||
db.session.add(ot)
|
||||
@@ -403,10 +408,10 @@ def test_published_template_generates_dynamic_artifact(app, tmp_path):
|
||||
db.session.add(confirmed_customer)
|
||||
db.session.flush()
|
||||
confirm_test_customer_resolution(ot, customer=confirmed_customer, extraction=extraction)
|
||||
inventory_file = ShippingInventoryFile(
|
||||
inventory_file_no='SIF-EXPORT-1', user_id=None,
|
||||
inventory_file = FreightRpaOnhandReportFile(
|
||||
onhand_file_no='SIF-EXPORT-1', user_id=None,
|
||||
source_file_name='inventory.xlsx', storage_path=str(tmp_path / 'inventory.xlsx'),
|
||||
inventory_lines_json=[{
|
||||
onhand_lines_json=[{
|
||||
_inventory_field_id('part_number'): 'PN-1', _inventory_field_id('odm_id'): 'ODM-9',
|
||||
}],
|
||||
line_count=1, share_mode='task_only', warehouse_id='DUB', source_code='DUB', snapshot_status='ready',
|
||||
@@ -536,23 +541,28 @@ def test_two_sources_can_share_one_published_excel_template(app, tmp_path):
|
||||
]},
|
||||
}, actor_id=None)
|
||||
published = excel_template.publish(draft['id'], actor_id=None)
|
||||
parsing = ShippingInventoryParsingProfile(
|
||||
parsing = FreightRpaParsingProfile(
|
||||
profile_code='SHARED_INV', display_name='Shared Inventory', version=1, status='published',
|
||||
file_format='xlsx', definition_json={}, checksum='p' * 64,
|
||||
)
|
||||
login = ShippingRpaProfile(
|
||||
login = FreightRpaProfile(
|
||||
profile_code='SHARED_LOGIN', display_name='Shared Login', connector_type='dbs',
|
||||
login_url='https://invalid', login_config_json={'auth_mode': 'password'},
|
||||
)
|
||||
db.session.add_all([parsing, login])
|
||||
db.session.flush()
|
||||
for code in ('DUB', 'RTM'):
|
||||
db.session.add(ShippingInventorySource(
|
||||
shared_source = FreightRpaSource(
|
||||
source_code=code, display_name=code, connector_type='dbs', rpa_profile_id=login.id,
|
||||
parsing_profile_id=parsing.id, excel_template_id=published['id'],
|
||||
excel_template_id=published['id'],
|
||||
warehouse_resolution_mode='fixed', fixed_warehouse_id=code,
|
||||
)
|
||||
# s18 起解析绑定/报表路径/查询条件归配置行,随站点级联入库。
|
||||
FreightRpaOnhandReportConfig(
|
||||
source=shared_source, parsing_profile_id=parsing.id,
|
||||
report_path_json={}, query_parameters_json=[],
|
||||
))
|
||||
)
|
||||
db.session.add(shared_source)
|
||||
db.session.commit()
|
||||
|
||||
template = db.session.get(ShippingExcelTemplate, published['id'])
|
||||
@@ -571,17 +581,17 @@ def test_disabled_source_still_blocks_template_retirement(app):
|
||||
}]},
|
||||
}, actor_id=None)
|
||||
published = excel_template.publish(draft['id'], actor_id=None)
|
||||
login = ShippingRpaProfile(
|
||||
login = FreightRpaProfile(
|
||||
profile_code='DISABLED_REF', display_name='Disabled Ref', connector_type='dbs',
|
||||
login_url='https://invalid', login_config_json={'auth_mode': 'password'},
|
||||
)
|
||||
db.session.add(login)
|
||||
db.session.flush()
|
||||
db.session.add(ShippingInventorySource(
|
||||
# s18 起站点行不再承载报表路径/查询条件;停用站点退役守卫只读模板绑定。
|
||||
db.session.add(FreightRpaSource(
|
||||
source_code='DISABLED_REF', display_name='Disabled Ref', connector_type='dbs', enabled=False,
|
||||
rpa_profile_id=login.id, excel_template_id=published['id'],
|
||||
warehouse_resolution_mode='fixed', fixed_warehouse_id='DUB',
|
||||
report_path_json={}, query_parameters_json=[],
|
||||
))
|
||||
db.session.commit()
|
||||
|
||||
@@ -611,20 +621,26 @@ def test_export_matches_inventory_by_profile_keys_not_row_position(app, tmp_path
|
||||
]},
|
||||
}, actor_id=None)
|
||||
published = excel_template.publish(draft['id'], actor_id=None)
|
||||
parsing = ShippingInventoryParsingProfile(
|
||||
parsing = FreightRpaParsingProfile(
|
||||
profile_code='KEYED', display_name='Keyed', version=1, status='published', file_format='xlsx',
|
||||
definition_json={'field_mapping': {_inventory_field_id('part_number'): 'Part No.', _inventory_field_id('odm_id'): 'ODM ID'}, 'match_keys': [{'order_field_id': part.id, 'inventory_field_id': _inventory_field_id('part_number')}]},
|
||||
)
|
||||
login = ShippingRpaProfile(
|
||||
login = FreightRpaProfile(
|
||||
profile_code='KEYED', display_name='Keyed', connector_type='dbs', login_url='https://invalid',
|
||||
login_config_json={'auth_mode': 'password'},
|
||||
)
|
||||
db.session.add_all([parsing, login]); db.session.flush()
|
||||
db.session.add(ShippingInventorySource(
|
||||
keyed_source = FreightRpaSource(
|
||||
source_code='KEYED', display_name='Keyed', connector_type='dbs', rpa_profile_id=login.id,
|
||||
parsing_profile_id=parsing.id, excel_template_id=published['id'], warehouse_resolution_mode='fixed',
|
||||
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[],
|
||||
))
|
||||
excel_template_id=published['id'], warehouse_resolution_mode='fixed',
|
||||
fixed_warehouse_id='DUB',
|
||||
)
|
||||
# s18 起解析绑定/报表路径/查询条件归配置行,随站点级联入库。
|
||||
FreightRpaOnhandReportConfig(
|
||||
source=keyed_source, parsing_profile_id=parsing.id,
|
||||
report_path_json={}, query_parameters_json=[],
|
||||
)
|
||||
db.session.add(keyed_source)
|
||||
customer = ShippingCustomer(standard_name='键控匹配客户', short_code='KEY', status='active')
|
||||
db.session.add(customer); db.session.flush()
|
||||
ot = ShippingOrderTask(task_no='OT-KEYED', user_id=1, status='ready', current_step='customer_review')
|
||||
@@ -646,10 +662,10 @@ def test_export_matches_inventory_by_profile_keys_not_row_position(app, tmp_path
|
||||
value_text=value, decision_id=decision.id,
|
||||
))
|
||||
confirm_test_customer_resolution(ot, customer=customer, extraction=extraction)
|
||||
inventory_file = ShippingInventoryFile(
|
||||
inventory_file_no='SIF-KEYED', user_id=None, source_file_name='keyed.xlsx',
|
||||
inventory_file = FreightRpaOnhandReportFile(
|
||||
onhand_file_no='SIF-KEYED', user_id=None, source_file_name='keyed.xlsx',
|
||||
storage_path=str(tmp_path / 'keyed.xlsx'),
|
||||
inventory_lines_json=[
|
||||
onhand_lines_json=[
|
||||
{_inventory_field_id('part_number'): 'PN-B', _inventory_field_id('odm_id'): 'ODM-B'},
|
||||
{_inventory_field_id('part_number'): 'PN-A', _inventory_field_id('odm_id'): 'ODM-A'},
|
||||
],
|
||||
@@ -800,20 +816,26 @@ def test_export_uses_active_inventory_link_instead_of_stale_task_cache(app, tmp_
|
||||
]},
|
||||
}, actor_id=None)
|
||||
published = excel_template.publish(draft['id'], actor_id=None)
|
||||
parsing = ShippingInventoryParsingProfile(
|
||||
parsing = FreightRpaParsingProfile(
|
||||
profile_code='AMBIGUOUS', display_name='Ambiguous', version=1, status='published', file_format='xlsx',
|
||||
definition_json={'field_mapping': {_inventory_field_id('part_number'): 'Part No.', _inventory_field_id('odm_id'): 'ODM ID'}, 'match_keys': [{'order_field_id': part.id, 'inventory_field_id': _inventory_field_id('part_number')}]},
|
||||
)
|
||||
login = ShippingRpaProfile(
|
||||
login = FreightRpaProfile(
|
||||
profile_code='AMBIGUOUS', display_name='Ambiguous', connector_type='dbs', login_url='https://invalid',
|
||||
login_config_json={'auth_mode': 'password'},
|
||||
)
|
||||
db.session.add_all([parsing, login]); db.session.flush()
|
||||
db.session.add(ShippingInventorySource(
|
||||
ambiguous_source = FreightRpaSource(
|
||||
source_code='AMBIGUOUS', display_name='Ambiguous', connector_type='dbs', rpa_profile_id=login.id,
|
||||
parsing_profile_id=parsing.id, excel_template_id=published['id'], warehouse_resolution_mode='fixed',
|
||||
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[],
|
||||
))
|
||||
excel_template_id=published['id'], warehouse_resolution_mode='fixed',
|
||||
fixed_warehouse_id='DUB',
|
||||
)
|
||||
# s18 起解析绑定/报表路径/查询条件归配置行,随站点级联入库。
|
||||
FreightRpaOnhandReportConfig(
|
||||
source=ambiguous_source, parsing_profile_id=parsing.id,
|
||||
report_path_json={}, query_parameters_json=[],
|
||||
)
|
||||
db.session.add(ambiguous_source)
|
||||
customer = ShippingCustomer(standard_name='模糊匹配客户', short_code='AMB', status='active')
|
||||
db.session.add(customer); db.session.flush()
|
||||
ot = ShippingOrderTask(task_no='OT-AMBIGUOUS', user_id=1, status='ready', current_step='customer_review')
|
||||
@@ -834,10 +856,10 @@ def test_export_uses_active_inventory_link_instead_of_stale_task_cache(app, tmp_
|
||||
value_text='PN-A', decision_id=decision.id,
|
||||
))
|
||||
confirm_test_customer_resolution(ot, customer=customer, extraction=extraction)
|
||||
ambiguous_file = ShippingInventoryFile(
|
||||
inventory_file_no='SIF-AMBIGUOUS', user_id=None, source_file_name='ambiguous.xlsx',
|
||||
ambiguous_file = FreightRpaOnhandReportFile(
|
||||
onhand_file_no='SIF-AMBIGUOUS', user_id=None, source_file_name='ambiguous.xlsx',
|
||||
storage_path=str(tmp_path / 'ambiguous.xlsx'),
|
||||
inventory_lines_json=[
|
||||
onhand_lines_json=[
|
||||
{_inventory_field_id('part_number'): 'PN-A', _inventory_field_id('odm_id'): 'ODM-1'},
|
||||
{_inventory_field_id('part_number'): 'PN-A', _inventory_field_id('odm_id'): 'ODM-2'},
|
||||
],
|
||||
@@ -859,10 +881,10 @@ def test_export_uses_active_inventory_link_instead_of_stale_task_cache(app, tmp_
|
||||
export_root = tmp_path / 'shipping' / 'exports'
|
||||
assert not export_root.exists() or not list(export_root.rglob('*.xlsx'))
|
||||
|
||||
inventory_file = ShippingInventoryFile(
|
||||
inventory_file_no='SIF-ACTIVE-FIXED', user_id=None,
|
||||
inventory_file = FreightRpaOnhandReportFile(
|
||||
onhand_file_no='SIF-ACTIVE-FIXED', user_id=None,
|
||||
source_file_name='fixed.xlsx', storage_path=str(tmp_path / 'fixed.xlsx'),
|
||||
inventory_lines_json=[
|
||||
onhand_lines_json=[
|
||||
{_inventory_field_id('part_number'): 'PN-A', _inventory_field_id('odm_id'): 'ODM-FIXED'},
|
||||
{_inventory_field_id('part_number'): 'PN-A', _inventory_field_id('odm_id'): 'ODM-FIXED'},
|
||||
],
|
||||
@@ -873,8 +895,8 @@ def test_export_uses_active_inventory_link_instead_of_stale_task_cache(app, tmp_
|
||||
db.session.flush()
|
||||
replace_task_inventory_link(task, inventory_file, role='owner')
|
||||
# 切换活动库存后,行级匹配事实须指向新快照;导出只读取活动 Link。
|
||||
for match in ShippingNoticeLineInventoryMatch.query.filter_by(task_id=ot.id, is_current=True).all():
|
||||
match.inventory_snapshot_id = inventory_file.id
|
||||
for match in ShippingNoticeLineOnhandMatch.query.filter_by(task_id=ot.id, is_current=True).all():
|
||||
match.onhand_snapshot_id = inventory_file.id
|
||||
db.session.flush()
|
||||
|
||||
path, _filename_value, artifact = generate_shipment_excel(task)
|
||||
@@ -926,20 +948,26 @@ def _build_multi_odm_notice(
|
||||
]},
|
||||
}, actor_id=None)
|
||||
published = excel_template.publish(draft['id'], actor_id=None)
|
||||
parsing = ShippingInventoryParsingProfile(
|
||||
parsing = FreightRpaParsingProfile(
|
||||
profile_code='ODMSCOPE', display_name='OdmScope', version=1, status='published', file_format='xlsx',
|
||||
definition_json={'field_mapping': {_inventory_field_id('part_number'): 'Part No.', _inventory_field_id('odm_id'): 'ODM ID'}, 'match_keys': [{'order_field_id': part.id, 'inventory_field_id': _inventory_field_id('part_number')}]},
|
||||
)
|
||||
login = ShippingRpaProfile(
|
||||
login = FreightRpaProfile(
|
||||
profile_code='ODMSCOPE', display_name='OdmScope', connector_type='dbs', login_url='https://invalid',
|
||||
login_config_json={'auth_mode': 'password'},
|
||||
)
|
||||
db.session.add_all([parsing, login]); db.session.flush()
|
||||
db.session.add(ShippingInventorySource(
|
||||
odm_source = FreightRpaSource(
|
||||
source_code='ODMSCOPE', display_name='OdmScope', connector_type='dbs', rpa_profile_id=login.id,
|
||||
parsing_profile_id=parsing.id, excel_template_id=published['id'], warehouse_resolution_mode='fixed',
|
||||
fixed_warehouse_id='DUB', report_path_json={}, query_parameters_json=[],
|
||||
))
|
||||
excel_template_id=published['id'], warehouse_resolution_mode='fixed',
|
||||
fixed_warehouse_id='DUB',
|
||||
)
|
||||
# s18 起解析绑定/报表路径/查询条件归配置行,随站点级联入库。
|
||||
FreightRpaOnhandReportConfig(
|
||||
source=odm_source, parsing_profile_id=parsing.id,
|
||||
report_path_json={}, query_parameters_json=[],
|
||||
)
|
||||
db.session.add(odm_source)
|
||||
customer = ShippingCustomer(
|
||||
standard_name='ODM范围客户', short_code='ODMSC', status='active',
|
||||
odm_ids=list(customer_odm_ids) if customer_odm_ids is not None else None,
|
||||
@@ -971,10 +999,10 @@ def _build_multi_odm_notice(
|
||||
for spec in specs:
|
||||
for odm in spec['odm_values']:
|
||||
inventory_rows.append({_inventory_field_id('part_number'): spec['part'], _inventory_field_id('odm_id'): odm})
|
||||
inventory_file = ShippingInventoryFile(
|
||||
inventory_file_no='SIF-ODMSCOPE', user_id=None, source_file_name='odm-scope.xlsx',
|
||||
inventory_file = FreightRpaOnhandReportFile(
|
||||
onhand_file_no='SIF-ODMSCOPE', user_id=None, source_file_name='odm-scope.xlsx',
|
||||
storage_path=str(tmp_path / 'odm-scope.xlsx'),
|
||||
inventory_lines_json=inventory_rows,
|
||||
onhand_lines_json=inventory_rows,
|
||||
line_count=len(inventory_rows), share_mode='task_only', warehouse_id='DUB', source_code='ODMSCOPE',
|
||||
snapshot_status='ready',
|
||||
)
|
||||
@@ -988,7 +1016,7 @@ def _build_multi_odm_notice(
|
||||
ot=ot, snapshot=snapshot, inventory_file=inventory_file, source_code='ODMSCOPE', notice_no='TASK-ODMSCOPE',
|
||||
)
|
||||
if choice_odm is not None:
|
||||
for match in ShippingNoticeLineInventoryMatch.query.filter_by(task_id=int(ot.id), is_current=True).all():
|
||||
for match in ShippingNoticeLineOnhandMatch.query.filter_by(task_id=int(ot.id), is_current=True).all():
|
||||
match.chosen_odm_id = choice_odm
|
||||
db.session.flush()
|
||||
return notice, customer
|
||||
@@ -1095,7 +1123,7 @@ def test_notice_odm_options_and_choice_roundtrip(app, tmp_path):
|
||||
result = set_notice_odm_choice(task, snapshot_line_id=snapshot_line_id, odm_id='ODM-2')
|
||||
|
||||
assert result['odm_id'] == 'ODM-2'
|
||||
matches = ShippingNoticeLineInventoryMatch.query.filter_by(
|
||||
matches = ShippingNoticeLineOnhandMatch.query.filter_by(
|
||||
task_id=int(task.order_task_id), is_current=True,
|
||||
).all()
|
||||
assert matches and {m.chosen_odm_id for m in matches} == {'ODM-2'}
|
||||
@@ -1134,7 +1162,7 @@ def test_notice_odm_choice_syncs_same_snapshot_file_lines(app, tmp_path):
|
||||
|
||||
# [断言] 同步范围=同一快照文件:两行当前匹配行写同一选择。
|
||||
assert result['synced_line_count'] == 2
|
||||
matches = ShippingNoticeLineInventoryMatch.query.filter_by(
|
||||
matches = ShippingNoticeLineOnhandMatch.query.filter_by(
|
||||
task_id=int(task.order_task_id), is_current=True,
|
||||
).all()
|
||||
assert len(matches) == 2
|
||||
|
||||
Reference in new issue
Block a user