194 lines
5.4 KiB
Python
194 lines
5.4 KiB
Python
# 合同系统页面步骤:登录、起草、填表、提交、读合同号。
|
||
#
|
||
# 对外入口:job.py / run_batch.py / 单测继续从本模块 import。
|
||
# 实现按 S0x 拆在 contract_common / contract_login / contract_form /
|
||
# contract_goods / contract_upload / contract_submit / contract_number。
|
||
|
||
from __future__ import annotations
|
||
|
||
from contract_common import (
|
||
BrowserAdapter,
|
||
ContractGoodsLine,
|
||
ContractFlowContext,
|
||
_ACCEPT,
|
||
_expected_title,
|
||
DRAFT_PAGE_URL,
|
||
TEMPLATE_ID,
|
||
FORM_PAGE_URL,
|
||
VIEW_PAGE_URL,
|
||
EDIT_PAGE_URL,
|
||
F,
|
||
X,
|
||
_YES_NO,
|
||
_CATEGORY_ALIASES,
|
||
_PAYMENT_ALIASES,
|
||
_yes_no,
|
||
_category_option,
|
||
_payment_option,
|
||
GOODS_FIELD_SUFFIXES,
|
||
ADD_ROW_SELECTORS,
|
||
GOODS_PICKER,
|
||
CUSTOMER_PICKER,
|
||
_PORTAL_MARKERS,
|
||
_is_logged_in,
|
||
sign_date_for,
|
||
begin_date_for,
|
||
_close_blocking_dialogs,
|
||
_current_url,
|
||
_read_document_id,
|
||
_open_submitted_view,
|
||
_lui_btn_xpath,
|
||
_click_toolbar_button,
|
||
_LUI_TOOLBAR_FIND_JS,
|
||
_LUI_TOOLBAR_CLICK_JS,
|
||
_lui_toolbar_button_exists,
|
||
_wait_lui_toolbar_button,
|
||
_click_top_submit,
|
||
_usable_contract_no,
|
||
_try_read,
|
||
contract_version_label,
|
||
)
|
||
|
||
from contract_login import (
|
||
open_contract_system,
|
||
login_contract_system,
|
||
enter_contract_create,
|
||
select_contract_template,
|
||
)
|
||
|
||
from contract_form import (
|
||
fill_contract_signatory_info,
|
||
_wait_customer_name,
|
||
_pick_customer_from_dialog,
|
||
fill_contract_basic_info,
|
||
_fill_contract_title,
|
||
_select_cover_template_if_needed,
|
||
_read_xform_label,
|
||
_select_settlement_type,
|
||
check_customer_diligence,
|
||
fill_contract_amount_and_dates,
|
||
fill_contract_payment_info,
|
||
_fill_concession_defaults,
|
||
)
|
||
|
||
from contract_goods import (
|
||
fill_contract_goods_lines,
|
||
_goods_search_keyword,
|
||
_looks_like_goods_opcode,
|
||
_picker_rows_dump,
|
||
_pick_goods_from_dialog,
|
||
_select_goods_in_picker,
|
||
_search_goods_in_dialog,
|
||
_dialog_row_has_keyword,
|
||
_select_dialog_row_by_keyword,
|
||
_scroll_to_goods_table,
|
||
_click_dialog_ok,
|
||
_as_index_list,
|
||
_next_unused_goods_row,
|
||
_find_goods_row,
|
||
_goods_table_dump,
|
||
_wait_unused_goods_row,
|
||
_empty_goods_row_indexes,
|
||
_occupied_goods_row_indexes,
|
||
_add_goods_row,
|
||
_existing_used_match,
|
||
_append_same_goods_row,
|
||
_clone_goods_identity,
|
||
_fill_goods_required_qty_price,
|
||
_delete_empty_goods_rows,
|
||
_goods_selector,
|
||
)
|
||
|
||
from contract_upload import (
|
||
_resolve_contract_body_path,
|
||
upload_contract_document_if_needed,
|
||
_upload_contract_body,
|
||
_reveal_contract_body_section,
|
||
_click_add_contract_body,
|
||
_contract_body_attached,
|
||
_on_body_editor_tab,
|
||
)
|
||
|
||
from contract_submit import (
|
||
_ERROR_MARKS,
|
||
_SUCCESS_MARKS,
|
||
_CONFIRM_MARKS,
|
||
submit_contract_for_approval,
|
||
_submit_error_from_body,
|
||
_classify_dialog_text,
|
||
_wait_submit_outcome,
|
||
_read_submit_signal,
|
||
_finish_submit_signal,
|
||
_accept_native_alert,
|
||
_submit_view_page,
|
||
_submit_success_text,
|
||
_submit_succeeded,
|
||
_submit_validation_error,
|
||
_handle_submit_dialogs,
|
||
_wait_lui_dialog_gone,
|
||
)
|
||
|
||
from contract_number import (
|
||
read_contract_number,
|
||
_read_contract_number_routed,
|
||
_read_contract_number_on_page,
|
||
_reload_contract_home,
|
||
_reopen_contract_home,
|
||
_open_my_contracts,
|
||
_click_my_contracts_sidebar,
|
||
_wait_text_in_frames,
|
||
_page_has_text,
|
||
_click_by_exact_text,
|
||
_sort_my_contracts_by_apply_time,
|
||
_scrape_latest_my_contract_number,
|
||
_pick_contract_row,
|
||
_search_my_contracts,
|
||
_scrape_my_contract_rows,
|
||
_row_has_fd_id,
|
||
_read_number_by_fd_id,
|
||
_read_contract_number_from_my_list,
|
||
)
|
||
|
||
|
||
# 按 S02–S13 串合同起草页,成功返回正式合同号。
|
||
#
|
||
# dry_run 在提交前停,返回空字符串。提交失败也返回空字符串,不抛。
|
||
# 合同号必须来自本单 fdId 对应详情。
|
||
def run_contract_create_flow(browser: BrowserAdapter, ctx: ContractFlowContext) -> str:
|
||
_ACCEPT.reset()
|
||
try:
|
||
open_contract_system(browser, ctx)
|
||
login_contract_system(browser, ctx)
|
||
enter_contract_create(browser)
|
||
select_contract_template(browser, ctx)
|
||
fill_contract_signatory_info(browser, ctx)
|
||
check_customer_diligence(browser, ctx)
|
||
fill_contract_basic_info(browser, ctx)
|
||
fill_contract_amount_and_dates(browser, ctx)
|
||
fill_contract_goods_lines(browser, ctx)
|
||
fill_contract_payment_info(browser, ctx)
|
||
upload_contract_document_if_needed(browser, ctx)
|
||
fd_id = _read_document_id(browser)
|
||
if not submit_contract_for_approval(browser, ctx, fd_id=fd_id):
|
||
if ctx.submit_mode == "dry_run":
|
||
_ACCEPT.note("S13", "读合同号", {"contractNo": "(dry_run)", "mode": "dry_run"}, ok=True)
|
||
return ""
|
||
_ACCEPT.note("S13", "读合同号", {"contractNo": "(none)", "mode": ctx.submit_mode}, ok=False)
|
||
return ""
|
||
fd_id = fd_id or _read_document_id(browser)
|
||
contract_no, via = _read_contract_number_routed(browser, ctx, fd_id=fd_id)
|
||
_ACCEPT.note(
|
||
"S13",
|
||
"读合同号",
|
||
{
|
||
"contractNo": contract_no or "(none)",
|
||
"via": via,
|
||
"fdId": fd_id or "(none)",
|
||
},
|
||
ok=_usable_contract_no(contract_no),
|
||
)
|
||
return contract_no
|
||
finally:
|
||
print(_ACCEPT.summary_text(), end="", flush=True)
|
||
_ACCEPT.dump()
|