feat(schedule): 增加库存源选项描述字段与站点ID支持

This commit is contained in:
hugo committed 2026-07-10 00:48:27 +08:00
1 parent f4e74f7b07
commit 8b1efbedb9
37 files changed
+8488 -4126

No files matched your search

+81 -12
View File
@@ -195,20 +195,28 @@ def _fill_input_via_script(root: Any, selector: str, value: str) -> bool:
return False
def _fill_multi_value_parameter(page: Any, label: str, values: list[str], *, timeout_ms: int) -> bool:
def _fill_multi_value_parameter(
page: Any,
label: str,
values: list[str],
*,
timeout_ms: int,
config_override: dict[str, str] | None = None,
select_all: bool = False,
) -> bool:
"""
填充 SSRS MultiValueParameterInputControl(Owner / PutawayZone)。
核心逻辑:展开 dropdown → 按 label 勾选/取消 checkbox → 关闭 dropdown。
"""
config = _DSV_REPORT_PARAM_DEFAULTS.get(label, {})
config = {**_DSV_REPORT_PARAM_DEFAULTS.get(label, {}), **(config_override or {})}
if config.get("control") != "multi_value":
return False
cleaned = [str(item).strip() for item in values if str(item).strip()]
if not cleaned:
if not cleaned and not select_all:
return False
_, text_locator = _find_locator(page, config["text"])
if text_locator is not None:
if text_locator is not None and not select_all:
try:
current = str(text_locator.input_value(timeout=2_000) or "").strip()
if current and all(item in current for item in cleaned):
@@ -233,15 +241,17 @@ def _fill_multi_value_parameter(page: Any, label: str, values: list[str], *, tim
try:
adjusted = root.evaluate(
"""
({ dropdownSelector, desiredValues, restrictToDesired }) => {
({ dropdownSelector, desiredValues, restrictToDesired, selectAll }) => {
const dropdown = document.querySelector(dropdownSelector);
if (!dropdown) return false;
const normalize = (text) => (text || '').replace(/\\s+/g, ' ').trim();
const labels = Array.from(dropdown.querySelectorAll('label'));
let changed = false;
let selectAllClicked = false;
const entries = [];
for (const labelNode of labels) {
const text = normalize(labelNode.textContent);
if (!text || text === '(Select All)') continue;
if (!text) continue;
let checkbox = null;
const htmlFor = labelNode.getAttribute('for');
if (htmlFor) {
@@ -251,14 +261,37 @@ def _fill_multi_value_parameter(page: Any, label: str, values: list[str], *, tim
checkbox = labelNode.previousElementSibling;
}
if (!checkbox || checkbox.type !== 'checkbox') continue;
const shouldCheck = desiredValues.includes(text.toLowerCase());
if (restrictToDesired) {
if (checkbox.checked !== shouldCheck) {
const isSelectAll = text === '(Select All)' || text.toLowerCase().includes('select all');
entries.push({ text, checkbox, isSelectAll });
if (selectAll && isSelectAll) {
if (!checkbox.checked) {
checkbox.click();
changed = true;
}
} else if (shouldCheck && !checkbox.checked) {
checkbox.click();
selectAllClicked = true;
}
}
if (selectAll && !selectAllClicked) {
for (const entry of entries) {
if (!entry.isSelectAll && !entry.checkbox.checked) {
entry.checkbox.click();
changed = true;
}
}
}
if (selectAll) {
return changed || entries.length > 0;
}
for (const entry of entries) {
if (entry.isSelectAll) continue;
const shouldCheck = desiredValues.includes(text.toLowerCase());
if (restrictToDesired) {
if (entry.checkbox.checked !== shouldCheck) {
entry.checkbox.click();
changed = true;
}
} else if (shouldCheck && !entry.checkbox.checked) {
entry.checkbox.click();
changed = true;
}
}
@@ -269,10 +302,14 @@ def _fill_multi_value_parameter(page: Any, label: str, values: list[str], *, tim
"dropdownSelector": config["dropdown"],
"desiredValues": list(desired),
"restrictToDesired": label == "PutawayZone",
"selectAll": select_all,
},
)
if adjusted:
print(f"[dsv-filter] {label} multi_value checkboxes={cleaned!r}")
if select_all:
print(f"[dsv-filter] {label} multi_value select_all")
else:
print(f"[dsv-filter] {label} multi_value checkboxes={cleaned!r}")
if toggle is not None:
try:
toggle.click(timeout=2_000, force=True)
@@ -405,3 +442,35 @@ def fill_dsv_filter_if_needed(
print(f"[dsv] failed to fill {label} filter text={text!r}", file=sys.stderr)
_debug(f"filter-failed-{label.lower()}", text)
def fill_dsv_multi_select_parameter(
page: Any,
label: str,
values: list[str],
*,
selectors: dict[str, str] | None = None,
select_all: bool = False,
browser_timeout_ms: Callable[[], int],
) -> bool:
"""
填充由 YAML `mode: multi_select` 显式声明的 SSRS checkbox 下拉参数。
【AI 触发时机】:当 DSV 报表参数不是原生 select,而是 `txtValue + divDropDown + checkbox`
组合控件时调用;例如 AWSAMS 的 Warehouse 下拉需要全选。
"""
config_override = {"control": "multi_value"}
if selectors:
for key in ("text", "toggle", "dropdown"):
value = str(selectors.get(key) or "").strip()
if value:
config_override[key] = value
if not all(config_override.get(key) for key in ("text", "toggle", "dropdown")):
return False
return _fill_multi_value_parameter(
page,
label,
values,
timeout_ms=browser_timeout_ms(),
config_override=config_override,
select_all=select_all,
)