AutoRpa/rpa_rebate/rebate_find.py

72 lines
2.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 返利查号节点:run_find_flow。登录/查号在 rebate_common。
from __future__ import annotations
from accept import AcceptanceReport, evidence_shot
from rebate_common import (
FLOW,
BrowserAdapter,
RebateFlowContext,
open_rebate_center,
login_rebate_center,
enter_purchase_agreement,
search_contract,
)
_ACCEPT = AcceptanceReport(flow=FLOW)
# 打开返利中心、登录、进采购协议、按合同号查号。
#
# 表里出现该号才返回 True。输入框回显不算。写 ACCEPT SUMMARY REBATE_FIND。
def run_find_flow(
browser: BrowserAdapter,
ctx: RebateFlowContext,
contract_no: str,
*,
expect_found: bool | None = None,
) -> bool:
_ACCEPT.reset()
try:
open_rebate_center(browser, ctx)
_ACCEPT.note("S02", "打开返利中心", {"url": ctx.rebate_url}, ok=True)
try:
login_rebate_center(browser, ctx)
_ACCEPT.note("S03", "登录", {"user": ctx.username}, ok=True)
except Exception as exc:
evidence_shot(browser, "rebate-login-failed", failed=True)
_ACCEPT.note(
"S03",
"登录",
{"user": ctx.username, "error": exc},
ok=False,
raise_error=False,
)
raise
enter_purchase_agreement(browser)
_ACCEPT.note("S04", "进入采购协议", {"menu": "采购协议管理"}, ok=True)
found = search_contract(browser, contract_no)
found_text = "yes" if found else "no"
if expect_found is None:
_ACCEPT.note(
"S05",
"查号",
{"contractNo": contract_no, "found": found_text},
ok=True,
)
else:
_ACCEPT.check(
"S05",
"查号",
[
("contractNo", contract_no, contract_no),
("found", found_text, "yes" if expect_found else "no"),
],
browser=browser,
screenshot_on_fail="rebate-find-mismatch",
)
return found
finally:
print(_ACCEPT.summary_text(), end="", flush=True)
_ACCEPT.dump()