fix(shipping-notice): 修复订单解析签名与库存 RPA 导出流程
- 修正订单提取运行与模板签名处理 - 优化库存 RPA 归档及报表导出逻辑 - 补充库存参数、归档、运行与签名测试 - 更新 Shipping Notice 技术文档
This commit is contained in:
1 parent
dabf140e41
commit
2bb7822247
10 files changed
+300
-43
No files matched your search
@@ -697,6 +697,60 @@ def _validate_inventory_excel(path: Path) -> None:
|
||||
)
|
||||
|
||||
|
||||
def _dsv_inventory_excel_has_detail_rows(path: Path) -> bool | None:
|
||||
"""
|
||||
判断 DSV 风格库存 Excel 表头之后是否有明细行。
|
||||
|
||||
核心逻辑:仅当识别到 Supplier ID + AWS Sku 表头时判空;其他格式返回 None(不拦截)。
|
||||
DOM 假空兜底后,Excel 才是 skip/no_inventory_data 的真相源。
|
||||
|
||||
Returns:
|
||||
True: 有明细;False: DSV 表头存在但无明细;None: 非 DSV 表头形态,跳过本门禁。
|
||||
"""
|
||||
try:
|
||||
from openpyxl import load_workbook
|
||||
except ImportError:
|
||||
return None
|
||||
|
||||
try:
|
||||
workbook = load_workbook(path, read_only=True, data_only=True)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
try:
|
||||
worksheet = workbook.active
|
||||
if worksheet is None:
|
||||
return None
|
||||
header_idx: int | None = None
|
||||
for idx, row in enumerate(worksheet.iter_rows(max_row=120, values_only=True), start=1):
|
||||
cells = [str(cell).strip() for cell in row if cell is not None and str(cell).strip()]
|
||||
if not cells:
|
||||
continue
|
||||
joined = " | ".join(cells).lower()
|
||||
if header_idx is None:
|
||||
if "supplier id" in joined and "aws sku" in joined:
|
||||
header_idx = idx
|
||||
continue
|
||||
if idx > header_idx:
|
||||
return True
|
||||
if header_idx is None:
|
||||
return None
|
||||
return False
|
||||
finally:
|
||||
workbook.close()
|
||||
|
||||
|
||||
def _enforce_inventory_excel_not_empty(path: Path) -> None:
|
||||
"""
|
||||
DSV Excel 有表头无明细时记为无库存(NoInventoryDataError → skipped)。
|
||||
|
||||
核心逻辑:配合导出路径「DOM 无行仍导出」;真真空才 skip,避免 DOM 慢渲染假空。
|
||||
"""
|
||||
detail = _dsv_inventory_excel_has_detail_rows(path)
|
||||
if detail is False:
|
||||
raise NoInventoryDataError("DSV report has no inventory data")
|
||||
|
||||
|
||||
def _download_dir_baseline_names(drop_dir: Path) -> set[str]:
|
||||
"""
|
||||
导出前拍摄下载目录已有文件名,供目录兜底识别“本次新文件”。
|
||||
@@ -775,6 +829,7 @@ def _save_download(
|
||||
)
|
||||
if suffix.lower() in {".xlsx", ".xlsm", ".xltx", ".xltm"}:
|
||||
_validate_inventory_excel(dest)
|
||||
_enforce_inventory_excel_not_empty(dest)
|
||||
return dest
|
||||
|
||||
|
||||
@@ -817,6 +872,7 @@ def _save_batch_download(
|
||||
)
|
||||
if suffix.lower() in {".xlsx", ".xlsm", ".xltx", ".xltm"}:
|
||||
_validate_inventory_excel(dest)
|
||||
_enforce_inventory_excel_not_empty(dest)
|
||||
return dest
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user