按 common/connectors/inventory/receipt 分层并重命名
- common/: rpa_common, rpa_heartbeat, download_artifact_fallback,
new_rpa_worker_secret
- connectors/dsv|crane/: 登录网站连接器,库存与收料共用
- inventory/: inventory_rpa_worker, run_inventory_batch_trigger,
start_inventory_worker, register_inventory_worker_tasks
- receipt/: receipt_rpa_worker, receipt_crane/dbs_export,
start_receipt_worker
保留裸 import + sys.path 引导;修正懒加载路径;
按范围命名 register_rpa_background_tasks -> register_inventory_worker_tasks;
同步 backend 测试、start_local.ps1、.env 注释、docs 与 README 路径。
(cherry picked from commit f3050164d0)
58 lines
2.6 KiB
Python
58 lines
2.6 KiB
Python
"""Crane 收料报表导出适配器。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys as _sys
|
|
from pathlib import Path as _Path
|
|
|
|
_RPA_ROOT = next(
|
|
(_c for _c in _Path(__file__).resolve().parents
|
|
if (_c / "connectors").is_dir() and (_c / "common").is_dir()
|
|
and (_c / "inventory").is_dir() and (_c / "receipt").is_dir()),
|
|
None,
|
|
)
|
|
if _RPA_ROOT is not None:
|
|
for _rel in ("", "common", "connectors", "connectors/dsv", "connectors/crane", "inventory", "receipt"):
|
|
_dir = str(_RPA_ROOT) if not _rel else str(_RPA_ROOT / _rel)
|
|
if _dir not in _sys.path:
|
|
_sys.path.insert(0, _dir)
|
|
|
|
from typing import Any, Callable
|
|
from urllib.parse import urlsplit, urlunsplit
|
|
|
|
import crane_report_export
|
|
import crane_session
|
|
|
|
|
|
def _inbound_details_entry_url(login_url: str) -> str:
|
|
"""将复用的 Crane Profile 登录地址固定到收料 Inbound Details 路由。"""
|
|
parsed = urlsplit(str(login_url or '').strip())
|
|
if not parsed.scheme or not parsed.netloc:
|
|
raise RuntimeError('Crane receipt unit requires an absolute login_url')
|
|
return urlunsplit((parsed.scheme, parsed.netloc, parsed.path or '/', parsed.query, '/inbound-details-query'))
|
|
|
|
|
|
def export_receipt_report(
|
|
page: Any, unit: dict[str, Any], *, env: Callable[[str, str], str], browser_timeout_ms: int,
|
|
select_or_fill: Callable[..., None], click_text: Callable[..., None], first_in_profile: bool,
|
|
) -> Any:
|
|
"""创建并下载唯一 Description 对应的 Crane Inbound Details 文件,禁止按最新历史文件选择。"""
|
|
report_path = dict(unit.get('report_path_json') or {})
|
|
if str(report_path.get('report_name') or '').strip() != 'Inbound Details':
|
|
raise RuntimeError('Crane receipt report must be Inbound Details')
|
|
entry_url = _inbound_details_entry_url(str(unit.get('login_url') or '').strip())
|
|
if first_in_profile:
|
|
page.goto(entry_url, wait_until='domcontentloaded', timeout=browser_timeout_ms)
|
|
crane_session.maybe_auto_login_crane(page, env=env, browser_timeout_ms=browser_timeout_ms)
|
|
crane_session.wait_for_crane_app_ready(page, entry_url, env=env, browser_timeout_ms=browser_timeout_ms)
|
|
# 旧 Crane driver 的 Scheduled Reports 匹配名来自 source;收料固定为
|
|
# Inbound Details,不能沿用库存的 OnHandDetails.xlsx 默认值。
|
|
source = {
|
|
'entry_url': entry_url,
|
|
'scheduled_report_name': 'Inbound Details',
|
|
}
|
|
return crane_report_export.export_crane_inventory_report(
|
|
page, source, trigger={'callback_id': unit.get('callback_id')}, env=env,
|
|
browser_timeout_ms=browser_timeout_ms, select_or_fill=select_or_fill, click_text=click_text,
|
|
)
|