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
+349
-163
@@ -1,9 +1,14 @@
|
||||
"""
|
||||
services/admin/shipping_inventory_service.py
|
||||
services/admin/shipping_onhand_admin_service.py
|
||||
|
||||
用途:管理库存源、RPA Profile、路由规则和外部系统映射主数据。
|
||||
依赖:db、库存配置模型、凭据加密、Source/Profile 校验、统一 AppError。
|
||||
用途:管理库存源、RPA Profile、在手报表配置、路由规则和外部系统映射主数据。
|
||||
依赖:db、库存配置模型(含 s18 起的 FreightRpaOnhandReportConfig 配置行)、凭据加密、
|
||||
Source/Profile 校验、统一 AppError。
|
||||
逻辑:管理 API 委托本服务完成校验和事务;运行期库存匹配不从本服务读取明文凭据。
|
||||
s18 起在手报表路径/查询条件/解析方案绑定归 FreightRpaOnhandReportConfig 一对一配置行
|
||||
(save_source 载荷内嵌 onhand_report_config 时经 _apply_onhand_report_config 写行),
|
||||
站点行只保留连接、模板绑定、仓库模式与启停;启用门禁由
|
||||
assert_onhand_source_can_enable 在服务层执行(PostgreSQL CHECK 不能跨表)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -14,22 +19,22 @@ from typing import Any
|
||||
from app.extensions import db
|
||||
from app.core.errors import ConflictError, NotFoundError, ValidationError
|
||||
from app.models import (
|
||||
ShippingInventoryExternalMapping, ShippingInventoryFile, ShippingInventoryRoutingRule, ShippingInventoryRoutingRuleCondition,
|
||||
ShippingInventoryRoutingRuleVersion, ShippingInventorySource, ShippingRpaProfile, ScheduleRun, ScheduleTask, ShippingNotice,
|
||||
FreightRpaOnhandExternalMapping, FreightRpaOnhandReportFile, FreightRpaOnhandRoutingRule, FreightRpaOnhandRoutingRuleCondition,
|
||||
FreightRpaOnhandRoutingRuleVersion, FreightRpaSource, FreightRpaProfile, ScheduleRun, ScheduleTask, ShippingNotice,
|
||||
ShippingOrderField,
|
||||
ShippingInventoryParsingProfile,
|
||||
ShippingNoticeLine, ShippingNoticeLineInventoryMatch,
|
||||
FreightRpaParsingProfile,
|
||||
ShippingNoticeLine, ShippingNoticeLineOnhandMatch,
|
||||
ShippingExcelTemplate,
|
||||
ShippingInventorySourceParsingBindingAudit,
|
||||
ShippingReceiptReportConfig,
|
||||
FreightRpaSourceParsingBindingAudit,
|
||||
FreightRpaInboundReportConfig, FreightRpaOnhandReportConfig,
|
||||
)
|
||||
from app.services.shipping_notice.audit_service import append_shipping_audit_event
|
||||
from app.services.freight_rpa.common.credential_crypto import encrypt_credential
|
||||
from app.services.shipping_notice.inventory_source_repository import validate_source_profile
|
||||
from app.services.shipping_notice.onhand_source_repository import validate_source_profile
|
||||
from app.services.shipping_notice.upload_config_validation import validate_upload_config
|
||||
from app.services.shipping_notice.routing_operators import ALLOWED_OPERATORS
|
||||
from app.services.shipping_notice.inventory_routing_engine import ALLOWED_ACTIONS
|
||||
from app.services.shipping_notice import inventory_parsing_profile
|
||||
from app.services.shipping_notice.onhand_routing_engine import ALLOWED_ACTIONS
|
||||
from app.services.shipping_notice import onhand_parsing_profile
|
||||
from app.services.shipping_notice.order_schema import service as order_schema_service
|
||||
|
||||
|
||||
@@ -62,7 +67,7 @@ def _json_object(data: dict[str, Any], field: str) -> dict[str, Any]:
|
||||
"""
|
||||
value = data.get(field, {})
|
||||
if not isinstance(value, dict):
|
||||
raise ValidationError(f'{field} must be an object', code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID')
|
||||
raise ValidationError(f'{field} must be an object', code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID')
|
||||
return dict(value)
|
||||
|
||||
|
||||
@@ -84,19 +89,19 @@ def _validate_report_path(connector_type: str, report_path: dict[str, Any]) -> d
|
||||
"""校验 DBS 四级报表路径,防止技术选择器混入业务配置。"""
|
||||
allowed = {'program_group', 'program_label', 'report_group', 'report_name'}
|
||||
if set(report_path) - allowed:
|
||||
raise ValidationError('report_path_json contains unsupported fields', code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID')
|
||||
raise ValidationError('report_path_json contains unsupported fields', code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID')
|
||||
normalized = {key: str(value or '').strip() for key, value in report_path.items()}
|
||||
if connector_type == 'dbs':
|
||||
missing = [key for key in allowed if not normalized.get(key)]
|
||||
if missing:
|
||||
raise ValidationError(
|
||||
'DBS inventory source requires a complete report path',
|
||||
code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID', details={'missing': sorted(missing)},
|
||||
code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID', details={'missing': sorted(missing)},
|
||||
)
|
||||
elif normalized:
|
||||
raise ValidationError(
|
||||
'Only DBS inventory sources can define report_path_json',
|
||||
code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID',
|
||||
code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID',
|
||||
)
|
||||
return {key: normalized[key] for key in allowed if normalized.get(key)}
|
||||
|
||||
@@ -105,7 +110,7 @@ def _validate_query_parameters(data: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
"""校验 Source 的可视化查询参数列表,禁止保存 selector 等 Driver 实现细节。"""
|
||||
raw = data.get('query_parameters_json', [])
|
||||
if not isinstance(raw, list):
|
||||
raise ValidationError('query_parameters_json must be a list', code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID')
|
||||
raise ValidationError('query_parameters_json must be a list', code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID')
|
||||
result: list[dict[str, Any]] = []
|
||||
seen_names: set[str] = set()
|
||||
allowed = {'name', 'mode', 'values', 'required', 'select_all', 'joiner'}
|
||||
@@ -113,7 +118,7 @@ def _validate_query_parameters(data: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
if not isinstance(item, dict) or set(item) - allowed:
|
||||
raise ValidationError(
|
||||
'query parameter contains unsupported fields',
|
||||
code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID', details={'index': index},
|
||||
code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID', details={'index': index},
|
||||
)
|
||||
name = str(item.get('name') or '').strip()
|
||||
mode = str(item.get('mode') or 'single').strip().lower()
|
||||
@@ -121,16 +126,16 @@ def _validate_query_parameters(data: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
required = item.get('required', False)
|
||||
select_all = item.get('select_all', False)
|
||||
if not name or name.lower() in seen_names or mode not in {'single', 'multi_text', 'multi_select'}:
|
||||
raise ValidationError('query parameter name or mode is invalid', code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID')
|
||||
raise ValidationError('query parameter name or mode is invalid', code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID')
|
||||
if not isinstance(values, list) or any(not isinstance(value, str) for value in values):
|
||||
raise ValidationError('query parameter values must be a string list', code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID')
|
||||
raise ValidationError('query parameter values must be a string list', code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID')
|
||||
if not isinstance(required, bool) or not isinstance(select_all, bool):
|
||||
raise ValidationError('query parameter flags must be boolean', code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID')
|
||||
raise ValidationError('query parameter flags must be boolean', code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID')
|
||||
normalized_values = [value.strip() for value in values if value.strip()]
|
||||
if required and not normalized_values and not select_all:
|
||||
raise ValidationError('required query parameter needs values or select_all', code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID')
|
||||
raise ValidationError('required query parameter needs values or select_all', code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID')
|
||||
if select_all and mode != 'multi_select':
|
||||
raise ValidationError('select_all only applies to multi_select', code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID')
|
||||
raise ValidationError('select_all only applies to multi_select', code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID')
|
||||
parameter: dict[str, Any] = {
|
||||
'name': name, 'mode': mode, 'values': normalized_values,
|
||||
'required': required, 'select_all': select_all,
|
||||
@@ -138,14 +143,14 @@ def _validate_query_parameters(data: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
if mode == 'multi_text':
|
||||
joiner = str(item.get('joiner') or ',').strip()
|
||||
if not joiner:
|
||||
raise ValidationError('multi_text query parameter needs joiner', code='SHIPPING.INVENTORY_SOURCE_CONFIG_INVALID')
|
||||
raise ValidationError('multi_text query parameter needs joiner', code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID')
|
||||
parameter['joiner'] = joiner
|
||||
seen_names.add(name.lower())
|
||||
result.append(parameter)
|
||||
return result
|
||||
|
||||
|
||||
def _profile_payload(profile: ShippingRpaProfile) -> dict[str, Any]:
|
||||
def _profile_payload(profile: FreightRpaProfile) -> dict[str, Any]:
|
||||
return {
|
||||
'id': profile.id, 'profile_code': profile.profile_code, 'display_name': profile.display_name,
|
||||
'connector_type': profile.connector_type, 'login_url': profile.login_url,
|
||||
@@ -168,15 +173,15 @@ def _iso(value: datetime | None) -> str | None:
|
||||
|
||||
def list_profiles() -> list[dict[str, Any]]:
|
||||
"""列出 Profile 元数据,不返回可恢复的凭据。"""
|
||||
return [_profile_payload(item) for item in ShippingRpaProfile.query.order_by(ShippingRpaProfile.profile_code).all()]
|
||||
return [_profile_payload(item) for item in FreightRpaProfile.query.order_by(FreightRpaProfile.profile_code).all()]
|
||||
|
||||
|
||||
def delete_profile(profile_id: int) -> None:
|
||||
"""删除未绑定库存源的错误连接配置,保留已使用连接的可追溯性。"""
|
||||
profile = db.session.get(ShippingRpaProfile, profile_id)
|
||||
profile = db.session.get(FreightRpaProfile, profile_id)
|
||||
if profile is None:
|
||||
raise NotFoundError('RPA Profile not found', code='SHIPPING.RPA_PROFILE_NOT_FOUND')
|
||||
if ShippingInventorySource.query.filter_by(rpa_profile_id=profile.id).count():
|
||||
if FreightRpaSource.query.filter_by(rpa_profile_id=profile.id).count():
|
||||
raise ConflictError('RPA Profile is referenced by inventory sources', code='SHIPPING.RPA_PROFILE_DELETE_BLOCKED')
|
||||
db.session.delete(profile)
|
||||
db.session.commit()
|
||||
@@ -184,10 +189,10 @@ def delete_profile(profile_id: int) -> None:
|
||||
|
||||
def save_profile(data: dict[str, Any], *, actor_id: int | None, profile_id: int | None = None) -> dict[str, Any]:
|
||||
"""创建或更新货代登录连接;密码留空表示保留既有密文。"""
|
||||
profile = db.session.get(ShippingRpaProfile, profile_id) if profile_id else None
|
||||
profile = db.session.get(FreightRpaProfile, profile_id) if profile_id else None
|
||||
if profile_id and profile is None:
|
||||
raise NotFoundError('RPA Profile not found', code='SHIPPING.RPA_PROFILE_NOT_FOUND')
|
||||
profile = profile or ShippingRpaProfile(profile_code='', display_name='', connector_type='', login_url='', login_config_json={})
|
||||
profile = profile or FreightRpaProfile(profile_code='', display_name='', connector_type='', login_url='', login_config_json={})
|
||||
# 记录“非 upload_config”的既有运行时配置快照:仅当这些字段变化才递增 config_version,
|
||||
# upload_config_json 属于连接上传配置,变更不得误判库存 RPA 配置测试过期。
|
||||
prev_non_upload = (
|
||||
@@ -237,26 +242,42 @@ def save_profile(data: dict[str, Any], *, actor_id: int | None, profile_id: int
|
||||
return _profile_payload(profile)
|
||||
|
||||
|
||||
def _source_payload(source: ShippingInventorySource) -> dict[str, Any]:
|
||||
"""序列化库存站点及其是否满足正式启用前置条件。"""
|
||||
def _onhand_report_config_payload(config: FreightRpaOnhandReportConfig) -> dict[str, Any]:
|
||||
"""序列化站点一对一在手报表配置行,不透传解析方案定义。"""
|
||||
return {
|
||||
'id': config.id,
|
||||
'report_path_json': config.report_path_json or {},
|
||||
'query_parameters_json': config.query_parameters_json or [],
|
||||
'parsing_profile_id': config.parsing_profile_id,
|
||||
}
|
||||
|
||||
|
||||
def _source_payload(source: FreightRpaSource) -> dict[str, Any]:
|
||||
"""序列化库存站点及其是否满足正式启用前置条件。
|
||||
|
||||
s18 起报表路径/查询条件/解析方案绑定不再随站点 DTO 平铺,
|
||||
改挂在 ``onhand_report_config`` 嵌套对象(配置行不存在时为 null)。
|
||||
"""
|
||||
return {
|
||||
'id': source.id, 'source_code': source.source_code, 'display_name': source.display_name,
|
||||
'connector_type': source.connector_type, 'rpa_profile_id': source.rpa_profile_id,
|
||||
'parsing_profile_id': source.parsing_profile_id,
|
||||
'excel_template_id': source.excel_template_id,
|
||||
'warehouse_resolution_mode': source.warehouse_resolution_mode, 'fixed_warehouse_id': source.fixed_warehouse_id,
|
||||
'report_path_json': source.report_path_json or {}, 'query_parameters_json': source.query_parameters_json or [],
|
||||
'onhand_report_config': (
|
||||
_onhand_report_config_payload(source.onhand_report_config)
|
||||
if source.onhand_report_config is not None else None
|
||||
),
|
||||
'snapshot_ttl_seconds': source.snapshot_ttl_seconds, 'enabled': bool(source.enabled),
|
||||
'config_version': source.config_version, 'created_at': _iso(source.created_at), 'updated_at': _iso(source.updated_at),
|
||||
'activation': get_source_activation_status(source),
|
||||
}
|
||||
|
||||
|
||||
def _receipt_report_config_payload(config: ShippingReceiptReportConfig) -> dict[str, Any]:
|
||||
def _receipt_report_config_payload(config: FreightRpaInboundReportConfig) -> dict[str, Any]:
|
||||
"""序列化独立收料配置,禁止把库存路径或凭据透传至管理端。"""
|
||||
profile = config.parsing_profile
|
||||
return {
|
||||
'id': config.id, 'inventory_source_id': config.inventory_source_id,
|
||||
'id': config.id, 'source_id': config.source_id,
|
||||
'report_path_json': config.report_path_json or {},
|
||||
'query_parameters_json': config.query_parameters_json or [],
|
||||
# 入站解析绑定:供抽屉回显当前规则;摘要只取展示字段,不透传定义。
|
||||
@@ -282,7 +303,7 @@ def _validate_inbound_profile_binding(profile_id: Any) -> int | None:
|
||||
"""
|
||||
if profile_id is None or str(profile_id).strip() == '':
|
||||
return None
|
||||
profile = db.session.get(ShippingInventoryParsingProfile, int(profile_id))
|
||||
profile = db.session.get(FreightRpaParsingProfile, int(profile_id))
|
||||
if profile is None or profile.status != 'published' or profile.purpose != 'inbound':
|
||||
raise ValidationError(
|
||||
'Inbound parsing profile must be published with purpose inbound',
|
||||
@@ -292,7 +313,7 @@ def _validate_inbound_profile_binding(profile_id: Any) -> int | None:
|
||||
|
||||
|
||||
def _validate_receipt_report_config(
|
||||
source: ShippingInventorySource, data: dict[str, Any],
|
||||
source: FreightRpaSource, data: dict[str, Any],
|
||||
) -> tuple[dict[str, str], list[dict[str, Any]]]:
|
||||
"""规范收料配置,与库存同构:路径+查询条件;日期禁填。
|
||||
|
||||
@@ -328,24 +349,24 @@ def _validate_receipt_report_config(
|
||||
|
||||
def get_receipt_report_config(source_id: int) -> dict[str, Any] | None:
|
||||
"""读取站点的收料配置;不存在时返回空,供抽屉初始化而非创建库存配置。"""
|
||||
source = db.session.get(ShippingInventorySource, source_id)
|
||||
source = db.session.get(FreightRpaSource, source_id)
|
||||
if source is None:
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
config = ShippingReceiptReportConfig.query.filter_by(inventory_source_id=source.id).one_or_none()
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
config = FreightRpaInboundReportConfig.query.filter_by(source_id=source.id).one_or_none()
|
||||
return _receipt_report_config_payload(config) if config else None
|
||||
|
||||
|
||||
def save_receipt_report_config(source_id: int, data: dict[str, Any], *, actor_id: int | None) -> dict[str, Any]:
|
||||
"""保存站点内独立收料配置并追加配置前后快照审计,不写入库存 Source 字段。"""
|
||||
source = db.session.get(ShippingInventorySource, source_id)
|
||||
source = db.session.get(FreightRpaSource, source_id)
|
||||
if source is None:
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
path, parameters = _validate_receipt_report_config(source, data)
|
||||
config = ShippingReceiptReportConfig.query.filter_by(inventory_source_id=source.id).one_or_none()
|
||||
config = FreightRpaInboundReportConfig.query.filter_by(source_id=source.id).one_or_none()
|
||||
before = _receipt_report_config_payload(config) if config else None
|
||||
is_new = config is None
|
||||
if config is None:
|
||||
config = ShippingReceiptReportConfig(inventory_source_id=source.id)
|
||||
config = FreightRpaInboundReportConfig(source_id=source.id)
|
||||
config.created_by = actor_id
|
||||
db.session.add(config)
|
||||
else:
|
||||
@@ -357,37 +378,173 @@ def save_receipt_report_config(source_id: int, data: dict[str, Any], *, actor_id
|
||||
db.session.flush()
|
||||
after = _receipt_report_config_payload(config)
|
||||
append_shipping_audit_event(
|
||||
event_type='shipping_receipt_report_config_saved', aggregate_type='shipping_receipt_report_config',
|
||||
event_type='shipping_inbound_report_config_saved', aggregate_type='shipping_inbound_report_config',
|
||||
aggregate_id=str(source.id), actor_type='admin', actor_id=actor_id, action='create' if is_new else 'update',
|
||||
result='success', before=before, after=after,
|
||||
metadata={'inventory_source_id': source.id, 'connector_type': source.connector_type,
|
||||
metadata={'source_id': source.id, 'connector_type': source.connector_type,
|
||||
'parsing_profile_id': config.parsing_profile_id},
|
||||
)
|
||||
db.session.commit()
|
||||
return after
|
||||
|
||||
|
||||
def _binding_snapshot(source: ShippingInventorySource) -> dict[str, Any]:
|
||||
"""冻结解析绑定变更的最小站点上下文,避免审计依赖后续可变主数据。"""
|
||||
def _validate_onhand_profile_binding(profile_id: Any) -> int | None:
|
||||
"""校验在手配置绑定的解析方案:必须已发布且 purpose='onhand';空值/0 表示解绑。
|
||||
|
||||
Args:
|
||||
profile_id: 请求载荷中的 parsing_profile_id;None/空串/0 视为解绑(与旧站点保存语义一致)。
|
||||
|
||||
Returns:
|
||||
int | None: 规整后的方案 id 或 None。
|
||||
|
||||
Raises:
|
||||
ValidationError: 方案 id 非法、不存在、未发布或用途不是 onhand
|
||||
(fail-closed,防误绑入站/出站方案,统一 SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED)。
|
||||
"""
|
||||
raw = str(profile_id).strip() if profile_id is not None else ''
|
||||
if raw in {'', '0'}:
|
||||
return None
|
||||
if not raw.isdigit():
|
||||
raise ValidationError(
|
||||
'Onhand parsing profile must be published with purpose onhand',
|
||||
code='SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED',
|
||||
)
|
||||
profile = db.session.get(FreightRpaParsingProfile, int(raw))
|
||||
if profile is None or profile.status != 'published' or profile.purpose != 'onhand':
|
||||
raise ValidationError(
|
||||
'Onhand parsing profile must be published with purpose onhand',
|
||||
code='SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED',
|
||||
)
|
||||
return profile.id
|
||||
|
||||
|
||||
def _apply_onhand_report_config(
|
||||
source: FreightRpaSource, data: dict[str, Any], *, actor_id: int | None,
|
||||
) -> FreightRpaOnhandReportConfig:
|
||||
"""把手报表三字段写入手配置行(无则插入),不触碰站点行已删除的三列。
|
||||
|
||||
核心逻辑:先全量校验路径对象/查询条件/解析绑定,失败时不留脏会话;
|
||||
校验通过后无配置行则插入(created_by=actor),有则更新并递增 config_version。
|
||||
报表路径按原样 JSON object 存取(Driver selector 等实现细节归 Worker/模板域,
|
||||
管理端 DBS 四段路径由前端 normaliseInventoryReportPath 规整后提交)。
|
||||
|
||||
Args:
|
||||
source: 已存在的库存站点(新配置行经 inventory_source 关系级联挂载)。
|
||||
data: 含 report_path_json / query_parameters_json / parsing_profile_id 的载荷。
|
||||
actor_id: 当前管理员主键,仅写审计字段。
|
||||
|
||||
Returns:
|
||||
FreightRpaOnhandReportConfig: 已写入(尚未提交)的配置行。
|
||||
"""
|
||||
# [STEP 1] 全量校验先行,任何失败都不会留下半写的配置行。
|
||||
report_path = _json_object(data, 'report_path_json')
|
||||
# DBS 四段路径按原样 JSON object 存取(前端 normaliseInventoryReportPath 规整);
|
||||
# 非 DBS(Crane)站点不得误填 DBS 报表路径(fail-closed,与列搬迁前契约一致)。
|
||||
if source.connector_type != 'dbs' and report_path:
|
||||
raise ValidationError(
|
||||
'Only DBS inventory sources can define report_path_json',
|
||||
code='SHIPPING.ONHAND_SOURCE_CONFIG_INVALID',
|
||||
)
|
||||
parameters = _validate_query_parameters(data)
|
||||
parsing_profile_id = _validate_onhand_profile_binding(data.get('parsing_profile_id'))
|
||||
# [STEP 2] 校验通过后写配置行:无则插入,有则更新并递增 config_version。
|
||||
config = source.onhand_report_config
|
||||
if config is None:
|
||||
config = FreightRpaOnhandReportConfig(source=source)
|
||||
config.created_by = actor_id
|
||||
db.session.add(config)
|
||||
else:
|
||||
config.config_version += 1
|
||||
config.report_path_json = report_path
|
||||
config.query_parameters_json = parameters
|
||||
config.parsing_profile_id = parsing_profile_id
|
||||
config.updated_by = actor_id
|
||||
return config
|
||||
|
||||
|
||||
def save_onhand_report_config(source_id: int, data: dict[str, Any], *, actor_id: int | None) -> dict[str, Any]:
|
||||
"""保存站点一对一在手报表配置:没有配置行时插入,有则更新并递增该行 config_version。
|
||||
|
||||
核心逻辑:委托 _apply_onhand_report_config 校验并写行;启用中的站点借保存拆掉
|
||||
启用门禁(缺解析绑定/模板)时由 assert_onhand_source_can_enable fail-closed 拒绝。
|
||||
|
||||
Args:
|
||||
source_id: 库存站点主键,必须已存在。
|
||||
data: 含 report_path_json / query_parameters_json / parsing_profile_id 的载荷。
|
||||
actor_id: 当前管理员主键,仅写审计字段。
|
||||
|
||||
Returns:
|
||||
dict[str, Any]: 配置行 DTO(id / report_path_json / query_parameters_json / parsing_profile_id)。
|
||||
|
||||
Raises:
|
||||
NotFoundError: 站点不存在。
|
||||
ValidationError: 解析方案不存在/未发布/purpose 不是 onhand,或启用中站点门禁被拆。
|
||||
"""
|
||||
source = db.session.get(FreightRpaSource, source_id)
|
||||
if source is None:
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
config = _apply_onhand_report_config(source, data, actor_id=actor_id)
|
||||
# 启用中的站点不得借配置保存解绑解析方案(excel_template 缺失同样拒绝)。
|
||||
assert_onhand_source_can_enable(source)
|
||||
db.session.commit()
|
||||
return _onhand_report_config_payload(config)
|
||||
|
||||
|
||||
def assert_onhand_source_can_enable(source: FreightRpaSource) -> None:
|
||||
"""启用中的库存站点必须已有在手配置行(含解析方案绑定)与发货模板。
|
||||
|
||||
【AI 触发时机】:保存站点(save_source 载荷含 enabled=true 或保留启用态)、
|
||||
保存在手配置(save_onhand_report_config 拆绑定前)时调用;
|
||||
PostgreSQL CHECK 不能跨表,解析方案存在性只能由服务层执行。
|
||||
|
||||
Args:
|
||||
source: 站点对象(可为未提交的暂态行,配置行经 onhand_report_config 关系读取)。
|
||||
|
||||
Returns:
|
||||
None: 门禁通过(站点未启用时恒通过)。
|
||||
|
||||
Raises:
|
||||
ValidationError: enabled 为真但缺配置行、配置行未绑解析方案或站点未绑模板,
|
||||
统一 code='SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED'。
|
||||
"""
|
||||
if not source.enabled:
|
||||
return
|
||||
config = source.onhand_report_config
|
||||
if config is None or not config.parsing_profile_id or not source.excel_template_id:
|
||||
raise ValidationError(
|
||||
'Enabled inventory source requires onhand report config, parsing profile and excel template',
|
||||
code='SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED',
|
||||
)
|
||||
|
||||
|
||||
def _binding_snapshot(source: FreightRpaSource) -> dict[str, Any]:
|
||||
"""冻结解析绑定变更的最小站点上下文,避免审计依赖后续可变主数据。
|
||||
|
||||
s18 起解析绑定挂在 onhand_report_config 配置行上,快照同样取自配置行。
|
||||
"""
|
||||
config = source.onhand_report_config
|
||||
return {
|
||||
'source_id': source.id,
|
||||
'source_code': source.source_code,
|
||||
'enabled': bool(source.enabled),
|
||||
'parsing_profile_id': source.parsing_profile_id,
|
||||
'parsing_profile_checksum': source.parsing_profile.checksum if source.parsing_profile else None,
|
||||
'parsing_profile_id': config.parsing_profile_id if config is not None else None,
|
||||
'parsing_profile_checksum': (
|
||||
config.parsing_profile.checksum
|
||||
if config is not None and config.parsing_profile is not None else None
|
||||
),
|
||||
'excel_template_id': source.excel_template_id,
|
||||
'config_version': source.config_version,
|
||||
}
|
||||
|
||||
|
||||
def _validate_source_parsing_binding(source: ShippingInventorySource, profile: ShippingInventoryParsingProfile) -> None:
|
||||
def _validate_source_parsing_binding(source: FreightRpaSource, profile: FreightRpaParsingProfile) -> None:
|
||||
"""校验站点可直接采用的已发布方案与当前发货模板字段契约;启用中的站点同样允许更换解析绑定。"""
|
||||
if profile.status != 'published':
|
||||
raise ValidationError('Published parsing profile is required', code='SHIPPING.INVENTORY_PARSING_PROFILE_REQUIRED')
|
||||
raise ValidationError('Published parsing profile is required', code='SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED')
|
||||
definition = profile.definition_json if isinstance(profile.definition_json, dict) else {}
|
||||
mapping = definition.get('field_mapping') if isinstance(definition.get('field_mapping'), dict) else {}
|
||||
if not mapping:
|
||||
raise ValidationError('Published parsing profile is invalid', code='SHIPPING.INVENTORY_PARSING_PROFILE_REQUIRED')
|
||||
raise ValidationError('Published parsing profile is invalid', code='SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED')
|
||||
template = source.excel_template
|
||||
if template is None:
|
||||
return
|
||||
@@ -405,7 +562,7 @@ def _validate_source_parsing_binding(source: ShippingInventorySource, profile: S
|
||||
if missing_fields:
|
||||
raise ValidationError(
|
||||
'Parsing profile does not provide all inventory fields required by the excel template',
|
||||
code='SHIPPING.INVENTORY_SOURCE_BINDING_TEMPLATE_INVALID', details={'inventory_field_ids': missing_fields},
|
||||
code='SHIPPING.ONHAND_SOURCE_BINDING_TEMPLATE_INVALID', details={'inventory_field_ids': missing_fields},
|
||||
)
|
||||
|
||||
|
||||
@@ -446,26 +603,36 @@ def bind_source_parsing_profile(
|
||||
normalized_profile_id = int(profile_id)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValidationError('parsing_profile_id is required', code='VALIDATION.INVALID_PARAM') from exc
|
||||
profile = db.session.get(ShippingInventoryParsingProfile, normalized_profile_id)
|
||||
profile = db.session.get(FreightRpaParsingProfile, normalized_profile_id)
|
||||
if profile is None:
|
||||
raise NotFoundError('Parsing profile not found', code='SHIPPING.INVENTORY_PARSING_PROFILE_NOT_FOUND')
|
||||
sources = [db.session.get(ShippingInventorySource, source_id) for source_id in normalized_ids]
|
||||
raise NotFoundError('Parsing profile not found', code='SHIPPING.ONHAND_PARSING_PROFILE_NOT_FOUND')
|
||||
sources = [db.session.get(FreightRpaSource, source_id) for source_id in normalized_ids]
|
||||
if any(source is None for source in sources):
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
typed_sources = [source for source in sources if source is not None]
|
||||
# [STEP 1] 全量预检后才变更,避免多站点操作出现部分绑定。
|
||||
for source in typed_sources:
|
||||
_validate_source_parsing_binding(source, profile)
|
||||
for source in typed_sources:
|
||||
before = _binding_snapshot(source)
|
||||
previous_profile_id = source.parsing_profile_id
|
||||
source.parsing_profile = profile
|
||||
# s18 起解析绑定写 onhand_report_config 配置行(无则插入),站点行不再承载该外键。
|
||||
config = source.onhand_report_config
|
||||
previous_profile_id = config.parsing_profile_id if config is not None else None
|
||||
if config is None:
|
||||
config = FreightRpaOnhandReportConfig(source=source)
|
||||
config.created_by = actor_id
|
||||
db.session.add(config)
|
||||
else:
|
||||
config.config_version += 1
|
||||
config.parsing_profile_id = profile.id
|
||||
config.updated_by = actor_id
|
||||
source.updated_by = actor_id
|
||||
# 站点 config_version 仍随绑定递增:配置测试锁定版本与运行期失效判断依赖它。
|
||||
source.config_version += 1
|
||||
db.session.flush()
|
||||
db.session.add(ShippingInventorySourceParsingBindingAudit(
|
||||
inventory_source_id=source.id, previous_parsing_profile_id=previous_profile_id,
|
||||
parsing_profile_id=profile.id, operation=operation, reason=normalized_reason, actor_id=actor_id,
|
||||
db.session.add(FreightRpaSourceParsingBindingAudit(
|
||||
source_id=source.id, previous_parsing_profile_id=previous_profile_id,
|
||||
parsing_profile_id=config.parsing_profile_id, operation=operation, reason=normalized_reason, actor_id=actor_id,
|
||||
source_config_version_before=before['config_version'], source_config_version_after=source.config_version,
|
||||
before_snapshot_json=before, after_snapshot_json=_binding_snapshot(source),
|
||||
))
|
||||
@@ -475,11 +642,11 @@ def bind_source_parsing_profile(
|
||||
|
||||
def get_source_parsing_binding_audits(source_id: int) -> list[dict[str, Any]]:
|
||||
"""读取库存站点解析绑定审计,仅返回配置快照和操作者标识。"""
|
||||
if db.session.get(ShippingInventorySource, source_id) is None:
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
rows = ShippingInventorySourceParsingBindingAudit.query.filter_by(
|
||||
inventory_source_id=source_id,
|
||||
).order_by(ShippingInventorySourceParsingBindingAudit.id.desc()).all()
|
||||
if db.session.get(FreightRpaSource, source_id) is None:
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
rows = FreightRpaSourceParsingBindingAudit.query.filter_by(
|
||||
source_id=source_id,
|
||||
).order_by(FreightRpaSourceParsingBindingAudit.id.desc()).all()
|
||||
return [{
|
||||
'id': row.id, 'operation': row.operation, 'reason': row.reason, 'actor_id': row.actor_id,
|
||||
'previous_parsing_profile_id': row.previous_parsing_profile_id, 'parsing_profile_id': row.parsing_profile_id,
|
||||
@@ -492,27 +659,27 @@ def get_source_parsing_binding_audits(source_id: int) -> list[dict[str, Any]]:
|
||||
|
||||
def list_sources() -> list[dict[str, Any]]:
|
||||
"""列出库存源及其稳定业务配置。"""
|
||||
return [_source_payload(item) for item in ShippingInventorySource.query.order_by(ShippingInventorySource.source_code).all()]
|
||||
return [_source_payload(item) for item in FreightRpaSource.query.order_by(FreightRpaSource.source_code).all()]
|
||||
|
||||
|
||||
def delete_source(source_id: int) -> None:
|
||||
"""删除未参与映射、快照或规则的错误库存源,避免破坏历史路由身份。"""
|
||||
source = db.session.get(ShippingInventorySource, source_id)
|
||||
source = db.session.get(FreightRpaSource, source_id)
|
||||
if source is None:
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
source_code = str(source.source_code or '').strip().upper()
|
||||
has_mapping = ShippingInventoryExternalMapping.query.filter_by(inventory_source_id=source.id).count() > 0
|
||||
has_snapshot = ShippingInventoryFile.query.filter_by(source_code=source_code).count() > 0
|
||||
has_mapping = FreightRpaOnhandExternalMapping.query.filter_by(source_id=source.id).count() > 0
|
||||
has_snapshot = FreightRpaOnhandReportFile.query.filter_by(source_code=source_code).count() > 0
|
||||
has_rule = any(
|
||||
source_code in {str(code).strip().upper() for code in candidates}
|
||||
for rule in ShippingInventoryRoutingRule.query.all()
|
||||
for rule in FreightRpaOnhandRoutingRule.query.all()
|
||||
for candidates in [(rule.action_payload_json or {}).get('source_codes', [])]
|
||||
if isinstance(candidates, list)
|
||||
)
|
||||
has_task = db.session.query(ShippingNoticeLine.id).filter(
|
||||
ShippingNoticeLine.inventory_source_code == source_code,
|
||||
).first() is not None or db.session.query(ShippingNoticeLineInventoryMatch.id).filter(
|
||||
ShippingNoticeLineInventoryMatch.inventory_source_code == source_code,
|
||||
).first() is not None or db.session.query(ShippingNoticeLineOnhandMatch.id).filter(
|
||||
ShippingNoticeLineOnhandMatch.source_code == source_code,
|
||||
).first() is not None
|
||||
has_export_run = any(
|
||||
source_code in {str(code).strip().upper() for code in source_codes}
|
||||
@@ -521,15 +688,15 @@ def delete_source(source_id: int) -> None:
|
||||
if isinstance(source_codes, list)
|
||||
)
|
||||
if has_mapping or has_snapshot or has_rule or has_task or has_export_run:
|
||||
raise ConflictError('Inventory Source has operational references', code='SHIPPING.INVENTORY_SOURCE_DELETE_BLOCKED')
|
||||
raise ConflictError('Inventory Source has operational references', code='SHIPPING.ONHAND_SOURCE_DELETE_BLOCKED')
|
||||
db.session.delete(source)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def _snapshot_payload(snapshot: ShippingInventoryFile) -> dict[str, Any]:
|
||||
def _snapshot_payload(snapshot: FreightRpaOnhandReportFile) -> dict[str, Any]:
|
||||
"""投影库存快照的管理端只读行,不暴露存储路径或库存明细。"""
|
||||
return {
|
||||
'id': snapshot.id, 'inventory_file_no': snapshot.inventory_file_no,
|
||||
'id': snapshot.id, 'inventory_file_no': snapshot.onhand_file_no,
|
||||
'source_code': snapshot.source_code, 'warehouse_id': snapshot.warehouse_id,
|
||||
'snapshot_status': snapshot.snapshot_status, 'identity_status': snapshot.identity_status,
|
||||
'line_count': snapshot.line_count, 'share_mode': snapshot.share_mode,
|
||||
@@ -543,8 +710,8 @@ def _snapshot_payload(snapshot: ShippingInventoryFile) -> dict[str, Any]:
|
||||
|
||||
def list_snapshots(*, limit: int = 100) -> list[dict[str, Any]]:
|
||||
"""列出最新库存快照,供管理员确认当前可用的库存文件。"""
|
||||
rows = ShippingInventoryFile.query.order_by(
|
||||
ShippingInventoryFile.exported_at.desc(), ShippingInventoryFile.id.desc(),
|
||||
rows = FreightRpaOnhandReportFile.query.order_by(
|
||||
FreightRpaOnhandReportFile.exported_at.desc(), FreightRpaOnhandReportFile.id.desc(),
|
||||
).limit(max(1, min(limit, 200))).all()
|
||||
return [_snapshot_payload(row) for row in rows]
|
||||
|
||||
@@ -563,22 +730,22 @@ def get_snapshot_download(snapshot_id: int) -> tuple[str, str]:
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
snapshot = db.session.get(ShippingInventoryFile, snapshot_id)
|
||||
snapshot = db.session.get(FreightRpaOnhandReportFile, snapshot_id)
|
||||
if snapshot is None:
|
||||
raise NotFoundError('Inventory snapshot not found', code='SHIPPING.INVENTORY_SNAPSHOT_NOT_FOUND')
|
||||
raise NotFoundError('Inventory snapshot not found', code='SHIPPING.ONHAND_SNAPSHOT_NOT_FOUND')
|
||||
path = Path(str(snapshot.storage_path or '')).resolve()
|
||||
if not str(snapshot.storage_path or '') or str(snapshot.storage_path).startswith('failed://') or not path.is_file():
|
||||
raise NotFoundError('Inventory snapshot file not found', code='SHIPPING.INVENTORY_SNAPSHOT_FILE_NOT_FOUND')
|
||||
filename = str(snapshot.source_file_name or f'{snapshot.inventory_file_no}{path.suffix or ".xlsx"}')
|
||||
raise NotFoundError('Inventory snapshot file not found', code='SHIPPING.ONHAND_SNAPSHOT_FILE_NOT_FOUND')
|
||||
filename = str(snapshot.source_file_name or f'{snapshot.onhand_file_no}{path.suffix or ".xlsx"}')
|
||||
return str(path), filename
|
||||
|
||||
|
||||
def list_export_records(*, limit: int = 100) -> list[dict[str, Any]]:
|
||||
"""列出 RPA 导出记录,合并已归档文件与排程失败/跳过结果。"""
|
||||
file_rows = ShippingInventoryFile.query.filter(
|
||||
ShippingInventoryFile.rpa_run_no.is_not(None),
|
||||
file_rows = FreightRpaOnhandReportFile.query.filter(
|
||||
FreightRpaOnhandReportFile.rpa_run_no.is_not(None),
|
||||
).order_by(
|
||||
ShippingInventoryFile.exported_at.desc(), ShippingInventoryFile.id.desc(),
|
||||
FreightRpaOnhandReportFile.exported_at.desc(), FreightRpaOnhandReportFile.id.desc(),
|
||||
).limit(max(1, min(limit, 200))).all()
|
||||
records = [_snapshot_payload(row) for row in file_rows]
|
||||
known_identities = {
|
||||
@@ -636,10 +803,12 @@ def list_export_records(*, limit: int = 100) -> list[dict[str, Any]]:
|
||||
return records[:max(1, min(limit, 200))]
|
||||
|
||||
|
||||
def _template_validation_missing(source: ShippingInventorySource) -> list[str]:
|
||||
def _template_validation_missing(source: FreightRpaSource) -> list[str]:
|
||||
"""确认发货模板引用的库存字段均由当前解析方案提供,避免启用后才发现字段断链。"""
|
||||
template = source.excel_template
|
||||
profile = source.parsing_profile
|
||||
# s18 起解析方案绑定取自 onhand_report_config 配置行。
|
||||
config = source.onhand_report_config
|
||||
profile = config.parsing_profile if config is not None else None
|
||||
if template is None or profile is None:
|
||||
return []
|
||||
definition = template.definition_json if isinstance(template.definition_json, dict) else {}
|
||||
@@ -669,13 +838,16 @@ def _activation_check(
|
||||
}
|
||||
|
||||
|
||||
def _source_activation_checks(source: ShippingInventorySource) -> list[dict[str, Any]]:
|
||||
def _source_activation_checks(source: FreightRpaSource) -> list[dict[str, Any]]:
|
||||
"""构建库存站点启用硬门槛:可用连接、已发布解析方案、已绑定已发布发货模板及字段契约。
|
||||
|
||||
测试导出不再参与启用门禁;启停由管理员显式开关完成。
|
||||
"""
|
||||
profile_ready = source.rpa_profile is not None and bool(source.rpa_profile.enabled)
|
||||
parsing_ready = source.parsing_profile is not None and source.parsing_profile.status == 'published'
|
||||
# s18 起解析方案绑定取自 onhand_report_config 配置行;配置行缺失即解析门禁未就绪。
|
||||
config = source.onhand_report_config
|
||||
parsing_profile = config.parsing_profile if config is not None else None
|
||||
parsing_ready = parsing_profile is not None and parsing_profile.status == 'published'
|
||||
template_ready = source.excel_template is not None and source.excel_template.status == 'published'
|
||||
template_invalid = bool(_template_validation_missing(source)) if template_ready and parsing_ready else False
|
||||
return [
|
||||
@@ -685,7 +857,7 @@ def _source_activation_checks(source: ShippingInventorySource) -> list[dict[str,
|
||||
),
|
||||
_activation_check(
|
||||
'parsing_profile', passed=parsing_ready, action='configure_parsing_profile',
|
||||
evidence={'profile_id': source.parsing_profile_id, 'published': parsing_ready},
|
||||
evidence={'profile_id': parsing_profile.id if parsing_profile is not None else None, 'published': parsing_ready},
|
||||
),
|
||||
_activation_check(
|
||||
'excel_template', passed=template_ready, action='configure_excel_template',
|
||||
@@ -698,7 +870,7 @@ def _source_activation_checks(source: ShippingInventorySource) -> list[dict[str,
|
||||
]
|
||||
|
||||
|
||||
def get_source_activation_status(source: ShippingInventorySource) -> dict[str, Any]:
|
||||
def get_source_activation_status(source: FreightRpaSource) -> dict[str, Any]:
|
||||
"""返回库存站点启用硬门槛的结构化结果。
|
||||
|
||||
Args:
|
||||
@@ -719,14 +891,14 @@ def get_source_activation_status(source: ShippingInventorySource) -> dict[str, A
|
||||
|
||||
def activate_source(source_id: int, *, actor_id: int | None) -> dict[str, Any]:
|
||||
"""启用已满足硬门槛的库存站点;未通过任一前置条件时保持停用。"""
|
||||
source = db.session.get(ShippingInventorySource, source_id)
|
||||
source = db.session.get(FreightRpaSource, source_id)
|
||||
if source is None:
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
status = get_source_activation_status(source)
|
||||
if not status['ready']:
|
||||
raise ConflictError(
|
||||
'Inventory Source is not ready for activation',
|
||||
code='SHIPPING.INVENTORY_SOURCE_ACTIVATION_BLOCKED',
|
||||
code='SHIPPING.ONHAND_SOURCE_ACTIVATION_BLOCKED',
|
||||
details=status,
|
||||
)
|
||||
source.enabled = True
|
||||
@@ -737,9 +909,9 @@ def activate_source(source_id: int, *, actor_id: int | None) -> dict[str, Any]:
|
||||
|
||||
def deactivate_source(source_id: int, *, actor_id: int | None) -> dict[str, Any]:
|
||||
"""停用库存站点,保留其解析方案和历史运行审计。"""
|
||||
source = db.session.get(ShippingInventorySource, source_id)
|
||||
source = db.session.get(FreightRpaSource, source_id)
|
||||
if source is None:
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
source.enabled = False
|
||||
source.updated_by = actor_id
|
||||
db.session.commit()
|
||||
@@ -750,15 +922,20 @@ def save_source(
|
||||
data: dict[str, Any], *, actor_id: int | None, source_id: int | None = None,
|
||||
allow_enable_transition: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
"""保存库存站点基础配置;管理 API 不允许通过普通保存直接启用站点。"""
|
||||
source = db.session.get(ShippingInventorySource, source_id) if source_id else None
|
||||
"""保存库存站点基础配置;管理 API 不允许通过普通保存直接启用站点。
|
||||
|
||||
s18 起站点头部仅编辑 source_code / display_name / connector_type / rpa_profile_id /
|
||||
excel_template_id / 仓库模式 / snapshot_ttl_seconds;报表路径、查询条件与解析方案
|
||||
绑定经载荷内嵌的 ``onhand_report_config`` 对象写入配置行(与独立保存同一校验路径)。
|
||||
"""
|
||||
source = db.session.get(FreightRpaSource, source_id) if source_id else None
|
||||
if source_id and source is None:
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
try:
|
||||
profile_id = int(data.get('rpa_profile_id'))
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValidationError('rpa_profile_id is required') from exc
|
||||
profile = db.session.get(ShippingRpaProfile, profile_id)
|
||||
profile = db.session.get(FreightRpaProfile, profile_id)
|
||||
if profile is None:
|
||||
raise ValidationError('RPA Profile not found', code='SHIPPING.RPA_PROFILE_NOT_FOUND')
|
||||
requested_enabled = _bool(data, 'enabled', bool(source.enabled) if source_id else False)
|
||||
@@ -772,32 +949,21 @@ def save_source(
|
||||
'Enabled Inventory Source requires an enabled RPA Profile',
|
||||
code='SHIPPING.RPA_PROFILE_DISABLED',
|
||||
)
|
||||
parsing_profile_id = data.get('parsing_profile_id')
|
||||
parsing_profile = db.session.get(ShippingInventoryParsingProfile, int(parsing_profile_id)) if str(parsing_profile_id or '').isdigit() else None
|
||||
if parsing_profile_id not in (None, '', 0, '0') and (parsing_profile is None or parsing_profile.status != 'published'):
|
||||
raise ValidationError('parsing_profile_id must reference a published profile', code='SHIPPING.INVENTORY_PARSING_PROFILE_REQUIRED')
|
||||
if enabled and parsing_profile is None:
|
||||
raise ValidationError('published parsing_profile_id is required', code='SHIPPING.INVENTORY_PARSING_PROFILE_REQUIRED')
|
||||
excel_template_id = data.get('excel_template_id')
|
||||
excel_template = db.session.get(ShippingExcelTemplate, int(excel_template_id)) if str(excel_template_id or '').isdigit() else None
|
||||
if excel_template_id not in (None, '', 0, '0') and (excel_template is None or excel_template.status != 'published'):
|
||||
raise ValidationError('excel_template_id must reference a published template', code='SHIPPING.EXCEL_TEMPLATE_REQUIRED')
|
||||
if enabled and excel_template is None:
|
||||
raise ValidationError('published excel_template_id is required', code='SHIPPING.EXCEL_TEMPLATE_REQUIRED')
|
||||
is_new = source is None
|
||||
source = source or ShippingInventorySource(
|
||||
source = source or FreightRpaSource(
|
||||
source_code='', display_name='', connector_type='', warehouse_resolution_mode='fixed',
|
||||
)
|
||||
source.source_code = str(_text(data, 'source_code', required=True)).upper()
|
||||
source.display_name = str(_text(data, 'display_name', required=True))
|
||||
source.connector_type = str(_text(data, 'connector_type', required=True)).lower()
|
||||
source.rpa_profile = profile
|
||||
source.parsing_profile = parsing_profile
|
||||
source.excel_template = excel_template
|
||||
source.warehouse_resolution_mode = str(_text(data, 'warehouse_resolution_mode', required=True)).lower()
|
||||
source.fixed_warehouse_id = _text(data, 'fixed_warehouse_id')
|
||||
source.report_path_json = _validate_report_path(source.connector_type, _json_object(data, 'report_path_json'))
|
||||
source.query_parameters_json = _validate_query_parameters(data)
|
||||
source.snapshot_ttl_seconds = int(data.get('snapshot_ttl_seconds') or 86400)
|
||||
source.enabled = enabled
|
||||
source.updated_by = actor_id
|
||||
@@ -806,16 +972,36 @@ def save_source(
|
||||
if is_new:
|
||||
source.created_by = actor_id
|
||||
db.session.add(source)
|
||||
# [STEP 1] 启用门禁先行:缺模板在写库前给出可解释错误,避免撞站点行 CHECK 的 IntegrityError
|
||||
# (模板缺失复用 SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED,不新造码)。
|
||||
if enabled and excel_template is None:
|
||||
raise ValidationError(
|
||||
'published excel_template_id is required',
|
||||
code='SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED',
|
||||
)
|
||||
try:
|
||||
# flush 让 excel_template_id / 新行主键先行落位,后续门禁读取规整后的外键。
|
||||
db.session.flush()
|
||||
except Exception as exc:
|
||||
db.session.rollback()
|
||||
raise ValidationError('Invalid Inventory Source configuration', code='SHIPPING.ONHAND_SOURCE_INVALID') from exc
|
||||
# [STEP 2] 载荷内嵌 onhand_report_config 时与独立保存走同一校验/写行路径(无则插入配置行)。
|
||||
config_data = data.get('onhand_report_config')
|
||||
if isinstance(config_data, dict):
|
||||
_apply_onhand_report_config(source, config_data, actor_id=actor_id)
|
||||
# [STEP 3] 启用门禁复核(缺配置行/解析绑定/模板统一 SHIPPING.ONHAND_PARSING_PROFILE_REQUIRED)。
|
||||
if enabled:
|
||||
assert_onhand_source_can_enable(source)
|
||||
validate_source_profile(source, profile)
|
||||
try:
|
||||
db.session.commit()
|
||||
except Exception as exc:
|
||||
db.session.rollback()
|
||||
raise ValidationError('Invalid Inventory Source configuration', code='SHIPPING.INVENTORY_SOURCE_INVALID') from exc
|
||||
raise ValidationError('Invalid Inventory Source configuration', code='SHIPPING.ONHAND_SOURCE_INVALID') from exc
|
||||
return _source_payload(source)
|
||||
|
||||
|
||||
def _rule_payload(rule: ShippingInventoryRoutingRule) -> dict[str, Any]:
|
||||
def _rule_payload(rule: FreightRpaOnhandRoutingRule) -> dict[str, Any]:
|
||||
return {
|
||||
'id': rule.id, 'rule_code': rule.rule_code, 'rule_name': rule.rule_name, 'scope': rule.scope,
|
||||
'priority': rule.priority, 'match_mode': rule.match_mode, 'status': rule.status,
|
||||
@@ -832,47 +1018,47 @@ def _validate_rule_condition_expected(operator: str, value: Any) -> Any:
|
||||
return None
|
||||
if operator in {'in', 'not_in'}:
|
||||
if not isinstance(value, list):
|
||||
raise ValidationError('List operator requires a string list', code='SHIPPING.INVENTORY_RULE_CONDITION_INVALID')
|
||||
raise ValidationError('List operator requires a string list', code='SHIPPING.ONHAND_RULE_CONDITION_INVALID')
|
||||
normalized = [str(item).strip() for item in value if str(item).strip()]
|
||||
if not normalized:
|
||||
raise ValidationError('List operator requires at least one value', code='SHIPPING.INVENTORY_RULE_CONDITION_INVALID')
|
||||
raise ValidationError('List operator requires at least one value', code='SHIPPING.ONHAND_RULE_CONDITION_INVALID')
|
||||
return normalized
|
||||
if operator in {'numeric_length', 'string_length'}:
|
||||
try:
|
||||
length = int(value)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValidationError('Length operator requires an integer', code='SHIPPING.INVENTORY_RULE_CONDITION_INVALID') from exc
|
||||
raise ValidationError('Length operator requires an integer', code='SHIPPING.ONHAND_RULE_CONDITION_INVALID') from exc
|
||||
if length < 0:
|
||||
raise ValidationError('Length must not be negative', code='SHIPPING.INVENTORY_RULE_CONDITION_INVALID')
|
||||
raise ValidationError('Length must not be negative', code='SHIPPING.ONHAND_RULE_CONDITION_INVALID')
|
||||
return length
|
||||
if not isinstance(value, str) or not value.strip():
|
||||
raise ValidationError('Routing condition requires an expected value', code='SHIPPING.INVENTORY_RULE_CONDITION_INVALID')
|
||||
raise ValidationError('Routing condition requires an expected value', code='SHIPPING.ONHAND_RULE_CONDITION_INVALID')
|
||||
return value.strip()
|
||||
|
||||
|
||||
def list_rules() -> list[dict[str, Any]]:
|
||||
"""列出规则及条件,用于草稿编辑和已发布规则查看。"""
|
||||
return [_rule_payload(item) for item in ShippingInventoryRoutingRule.query.order_by(ShippingInventoryRoutingRule.priority.desc()).all()]
|
||||
return [_rule_payload(item) for item in FreightRpaOnhandRoutingRule.query.order_by(FreightRpaOnhandRoutingRule.priority.desc()).all()]
|
||||
|
||||
|
||||
def delete_draft_rule(rule_id: int) -> None:
|
||||
"""删除从未发布的草稿规则;发布过的规则必须归档以保留审计定义。"""
|
||||
rule = db.session.get(ShippingInventoryRoutingRule, rule_id)
|
||||
rule = db.session.get(FreightRpaOnhandRoutingRule, rule_id)
|
||||
if rule is None:
|
||||
raise NotFoundError('Routing rule not found', code='SHIPPING.INVENTORY_RULE_NOT_FOUND')
|
||||
raise NotFoundError('Routing rule not found', code='SHIPPING.ONHAND_RULE_NOT_FOUND')
|
||||
if rule.status != 'draft':
|
||||
raise ConflictError('Only draft routing rules can be deleted', code='SHIPPING.INVENTORY_RULE_DELETE_BLOCKED')
|
||||
raise ConflictError('Only draft routing rules can be deleted', code='SHIPPING.ONHAND_RULE_DELETE_BLOCKED')
|
||||
db.session.delete(rule)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def retire_rule(rule_id: int, *, actor_id: int | None) -> dict[str, Any]:
|
||||
"""归档已发布规则,使其不再参与新路由,同时保留已发布版本。"""
|
||||
rule = db.session.get(ShippingInventoryRoutingRule, rule_id)
|
||||
rule = db.session.get(FreightRpaOnhandRoutingRule, rule_id)
|
||||
if rule is None:
|
||||
raise NotFoundError('Routing rule not found', code='SHIPPING.INVENTORY_RULE_NOT_FOUND')
|
||||
raise NotFoundError('Routing rule not found', code='SHIPPING.ONHAND_RULE_NOT_FOUND')
|
||||
if rule.status != 'published':
|
||||
raise ConflictError('Only published routing rules can be retired', code='SHIPPING.INVENTORY_RULE_RETIRE_INVALID')
|
||||
raise ConflictError('Only published routing rules can be retired', code='SHIPPING.ONHAND_RULE_RETIRE_INVALID')
|
||||
rule.status = 'retired'
|
||||
rule.updated_by = actor_id
|
||||
db.session.commit()
|
||||
@@ -882,12 +1068,12 @@ def retire_rule(rule_id: int, *, actor_id: int | None) -> dict[str, Any]:
|
||||
def save_rule(data: dict[str, Any], *, actor_id: int | None, rule_id: int | None = None) -> dict[str, Any]:
|
||||
"""保存草稿规则;发布规则必须以新版本创建,避免篡改历史定义。"""
|
||||
if rule_id:
|
||||
current = db.session.get(ShippingInventoryRoutingRule, rule_id)
|
||||
current = db.session.get(FreightRpaOnhandRoutingRule, rule_id)
|
||||
if current is None:
|
||||
raise NotFoundError('Routing rule not found', code='SHIPPING.INVENTORY_RULE_NOT_FOUND')
|
||||
raise NotFoundError('Routing rule not found', code='SHIPPING.ONHAND_RULE_NOT_FOUND')
|
||||
if current.status != 'draft':
|
||||
raise ConflictError('Only draft routing rules can be updated', code='SHIPPING.INVENTORY_RULE_IMMUTABLE')
|
||||
rule = current if rule_id else ShippingInventoryRoutingRule(
|
||||
raise ConflictError('Only draft routing rules can be updated', code='SHIPPING.ONHAND_RULE_IMMUTABLE')
|
||||
rule = current if rule_id else FreightRpaOnhandRoutingRule(
|
||||
rule_code='', rule_name='', scope='', action_type='', action_payload_json={}
|
||||
)
|
||||
rule.rule_code = str(_text(data, 'rule_code', required=True)).upper()
|
||||
@@ -903,37 +1089,37 @@ def save_rule(data: dict[str, Any], *, actor_id: int | None, rule_id: int | None
|
||||
rule.created_by = actor_id
|
||||
rule.updated_by = actor_id
|
||||
if rule.action_type not in ALLOWED_ACTIONS or rule.scope not in {'task', 'line'} or rule.match_mode not in {'all', 'any'}:
|
||||
raise ValidationError('Invalid routing rule metadata', code='SHIPPING.INVENTORY_RULE_INVALID')
|
||||
raise ValidationError('Invalid routing rule metadata', code='SHIPPING.ONHAND_RULE_INVALID')
|
||||
conditions = data.get('conditions')
|
||||
if not isinstance(conditions, list) or not conditions:
|
||||
raise ValidationError('Routing rule requires conditions', code='SHIPPING.INVENTORY_RULE_CONDITIONS_REQUIRED')
|
||||
raise ValidationError('Routing rule requires conditions', code='SHIPPING.ONHAND_RULE_CONDITIONS_REQUIRED')
|
||||
# 草稿更新在同一版本内替换条件;发布后不可原地修改。
|
||||
if rule_id:
|
||||
db.session.query(ShippingInventoryRoutingRuleCondition).filter_by(rule_id=rule.id).delete(
|
||||
db.session.query(FreightRpaOnhandRoutingRuleCondition).filter_by(rule_id=rule.id).delete(
|
||||
synchronize_session=False
|
||||
)
|
||||
db.session.flush()
|
||||
db.session.expire(rule, ['conditions'])
|
||||
for index, item in enumerate(conditions, start=1):
|
||||
if not isinstance(item, dict) or item.get('operator') not in ALLOWED_OPERATORS:
|
||||
raise ValidationError('Routing rule condition is not allowed', code='SHIPPING.INVENTORY_RULE_CONDITION_INVALID')
|
||||
raise ValidationError('Routing rule condition is not allowed', code='SHIPPING.ONHAND_RULE_CONDITION_INVALID')
|
||||
source_kind = str(item.get('source_kind') or 'order_field')
|
||||
order_field_id = str(item.get('order_field_id') or '') or None
|
||||
field = db.session.get(ShippingOrderField, order_field_id) if order_field_id else None
|
||||
if source_kind == 'order_field':
|
||||
if field is None or field.status != 'active' or field.scope != rule.scope.replace('task', 'header'):
|
||||
raise ValidationError('Routing order field is invalid for rule scope', code='SHIPPING.INVENTORY_RULE_CONDITION_INVALID')
|
||||
raise ValidationError('Routing order field is invalid for rule scope', code='SHIPPING.ONHAND_RULE_CONDITION_INVALID')
|
||||
published_fields = {
|
||||
str(config.get('field_id'))
|
||||
for config in order_schema_service.get_published_contract()['fields']
|
||||
if config.get('scope') == field.scope
|
||||
}
|
||||
if field.id not in published_fields:
|
||||
raise ValidationError('Routing order field is not published', code='SHIPPING.INVENTORY_RULE_CONDITION_INVALID')
|
||||
raise ValidationError('Routing order field is not published', code='SHIPPING.ONHAND_RULE_CONDITION_INVALID')
|
||||
else:
|
||||
raise ValidationError('Routing conditions must use a published order field', code='SHIPPING.INVENTORY_RULE_CONDITION_INVALID')
|
||||
raise ValidationError('Routing conditions must use a published order field', code='SHIPPING.ONHAND_RULE_CONDITION_INVALID')
|
||||
operator = str(item['operator'])
|
||||
rule.conditions.append(ShippingInventoryRoutingRuleCondition(
|
||||
rule.conditions.append(FreightRpaOnhandRoutingRuleCondition(
|
||||
condition_group=int(item.get('condition_group') or 1), source_kind=source_kind,
|
||||
order_field_id=order_field_id,
|
||||
operator=operator, expected_value_json=_validate_rule_condition_expected(
|
||||
@@ -946,7 +1132,7 @@ def save_rule(data: dict[str, Any], *, actor_id: int | None, rule_id: int | None
|
||||
db.session.commit()
|
||||
except Exception as exc:
|
||||
db.session.rollback()
|
||||
raise ConflictError('Routing rule code and version already exist', code='SHIPPING.INVENTORY_RULE_CONFLICT') from exc
|
||||
raise ConflictError('Routing rule code and version already exist', code='SHIPPING.ONHAND_RULE_CONFLICT') from exc
|
||||
return _rule_payload(rule)
|
||||
|
||||
|
||||
@@ -956,11 +1142,11 @@ def publish_rule(rule_id: int, *, actor_id: int | None) -> dict[str, Any]:
|
||||
路由规则只声明库存源候选,允许引用已配置但暂时停用的 Source;实际
|
||||
库存 RPA 运行时仍由库存源门禁拒绝停用 Source,避免发布配置误触发 RPA。
|
||||
"""
|
||||
rule = db.session.get(ShippingInventoryRoutingRule, rule_id)
|
||||
rule = db.session.get(FreightRpaOnhandRoutingRule, rule_id)
|
||||
if rule is None:
|
||||
raise NotFoundError('Routing rule not found', code='SHIPPING.INVENTORY_RULE_NOT_FOUND')
|
||||
raise NotFoundError('Routing rule not found', code='SHIPPING.ONHAND_RULE_NOT_FOUND')
|
||||
if rule.status != 'draft':
|
||||
raise ConflictError('Only draft routing rules can be published', code='SHIPPING.INVENTORY_RULE_PUBLISH_INVALID')
|
||||
raise ConflictError('Only draft routing rules can be published', code='SHIPPING.ONHAND_RULE_PUBLISH_INVALID')
|
||||
if rule.action_type in {'add_source_candidates', 'exclude_source_candidates'}:
|
||||
payload = rule.action_payload_json if isinstance(rule.action_payload_json, dict) else {}
|
||||
source_codes = {
|
||||
@@ -970,27 +1156,27 @@ def publish_rule(rule_id: int, *, actor_id: int | None) -> dict[str, Any]:
|
||||
}
|
||||
existing_codes = {
|
||||
str(code).strip().upper()
|
||||
for (code,) in db.session.query(ShippingInventorySource.source_code).all()
|
||||
for (code,) in db.session.query(FreightRpaSource.source_code).all()
|
||||
}
|
||||
missing_codes = sorted(source_codes - existing_codes)
|
||||
if missing_codes:
|
||||
raise ValidationError(
|
||||
'Routing rule references unavailable inventory sources',
|
||||
code='SHIPPING.INVENTORY_RULE_SOURCE_INVALID',
|
||||
code='SHIPPING.ONHAND_RULE_SOURCE_INVALID',
|
||||
details={'source_codes': missing_codes},
|
||||
)
|
||||
rule.status = 'published'
|
||||
rule.updated_by = actor_id
|
||||
db.session.add(ShippingInventoryRoutingRuleVersion(
|
||||
db.session.add(FreightRpaOnhandRoutingRuleVersion(
|
||||
rule_id=rule.id, version=rule.version, definition_json=_rule_payload(rule), published_by=actor_id,
|
||||
))
|
||||
db.session.commit()
|
||||
return _rule_payload(rule)
|
||||
|
||||
|
||||
def _external_payload(mapping: ShippingInventoryExternalMapping) -> dict[str, Any]:
|
||||
def _external_payload(mapping: FreightRpaOnhandExternalMapping) -> dict[str, Any]:
|
||||
return {
|
||||
'id': mapping.id, 'inventory_source_id': mapping.inventory_source_id,
|
||||
'id': mapping.id, 'source_id': mapping.source_id,
|
||||
'freight_warehouse_id': mapping.freight_warehouse_id, 'external_system_code': mapping.external_system_code,
|
||||
'external_organization_code': mapping.external_organization_code, 'external_site_code': mapping.external_site_code,
|
||||
'external_warehouse_code': mapping.external_warehouse_code, 'external_warehouse_name': mapping.external_warehouse_name,
|
||||
@@ -1001,31 +1187,31 @@ def _external_payload(mapping: ShippingInventoryExternalMapping) -> dict[str, An
|
||||
|
||||
def list_external_mappings() -> list[dict[str, Any]]:
|
||||
"""列出库存源到外部系统仓库的映射,不执行调拨判断。"""
|
||||
return [_external_payload(item) for item in ShippingInventoryExternalMapping.query.order_by(ShippingInventoryExternalMapping.id).all()]
|
||||
return [_external_payload(item) for item in FreightRpaOnhandExternalMapping.query.order_by(FreightRpaOnhandExternalMapping.id).all()]
|
||||
|
||||
|
||||
def delete_external_mapping(mapping_id: int) -> None:
|
||||
"""删除错误的外部仓库映射;历史文件和任务不回写此实时配置。"""
|
||||
record = db.session.get(ShippingInventoryExternalMapping, mapping_id)
|
||||
record = db.session.get(FreightRpaOnhandExternalMapping, mapping_id)
|
||||
if record is None:
|
||||
raise NotFoundError('External mapping not found', code='SHIPPING.INVENTORY_EXTERNAL_MAPPING_NOT_FOUND')
|
||||
raise NotFoundError('External mapping not found', code='SHIPPING.ONHAND_EXTERNAL_MAPPING_NOT_FOUND')
|
||||
db.session.delete(record)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def save_external_mapping(data: dict[str, Any], *, actor_id: int | None, mapping_id: int | None = None) -> dict[str, Any]:
|
||||
"""创建或更新精确/默认外部系统映射。"""
|
||||
record = db.session.get(ShippingInventoryExternalMapping, mapping_id) if mapping_id else None
|
||||
record = db.session.get(FreightRpaOnhandExternalMapping, mapping_id) if mapping_id else None
|
||||
if mapping_id and record is None:
|
||||
raise NotFoundError('External mapping not found', code='SHIPPING.INVENTORY_EXTERNAL_MAPPING_NOT_FOUND')
|
||||
raise NotFoundError('External mapping not found', code='SHIPPING.ONHAND_EXTERNAL_MAPPING_NOT_FOUND')
|
||||
try:
|
||||
source_id = int(data.get('inventory_source_id'))
|
||||
source_id = int(data.get('source_id'))
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValidationError('inventory_source_id is required') from exc
|
||||
if db.session.get(ShippingInventorySource, source_id) is None:
|
||||
raise ValidationError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
record = record or ShippingInventoryExternalMapping(inventory_source_id=source_id, external_system_code='', external_warehouse_code='', external_warehouse_name='')
|
||||
record.inventory_source_id = source_id
|
||||
raise ValidationError('source_id is required') from exc
|
||||
if db.session.get(FreightRpaSource, source_id) is None:
|
||||
raise ValidationError('Inventory Source not found', code='SHIPPING.ONHAND_SOURCE_NOT_FOUND')
|
||||
record = record or FreightRpaOnhandExternalMapping(source_id=source_id, external_system_code='', external_warehouse_code='', external_warehouse_name='')
|
||||
record.source_id = source_id
|
||||
# 货代仓库改为可选维度:inventory_match 源按「收料文件仓库 == 货代仓库」匹配映射行,
|
||||
# 空值即「空库位」默认映射行;归一化为大写以与收料仓库值精确比对。
|
||||
record.freight_warehouse_id = str(_text(data, 'freight_warehouse_id') or '').upper() or None
|
||||
@@ -1045,5 +1231,5 @@ def save_external_mapping(data: dict[str, Any], *, actor_id: int | None, mapping
|
||||
db.session.commit()
|
||||
except Exception as exc:
|
||||
db.session.rollback()
|
||||
raise ConflictError('Active external mapping already exists for this freight identity', code='SHIPPING.INVENTORY_EXTERNAL_MAPPING_CONFLICT') from exc
|
||||
raise ConflictError('Active external mapping already exists for this freight identity', code='SHIPPING.ONHAND_EXTERNAL_MAPPING_CONFLICT') from exc
|
||||
return _external_payload(record)
|
||||
Reference in new issue
Block a user