fix(contract-plan): 采购合同请款支持根据公司查不同账套
This commit is contained in:
1 parent
6867aeb90c
commit
89c8da2990
20 files changed
+381
-116
No files matched your search
@@ -676,7 +676,8 @@ class ContractOaClient:
|
||||
"""
|
||||
解析合同申请单表格与附件区域。
|
||||
|
||||
截图确认的字段名为“流程编号、采购单号、合同单位、合同金额、合同书币别、合同生效日期、约定到货日期”;
|
||||
截图确认的字段名为“流程编号、公司、采购单号、合同单位、合同金额、合同书币别、合同生效日期、约定到货日期”;
|
||||
「公司」决定 ERP 账套,「合同单位」是供应商,两者不能混用。
|
||||
解析保留原始 labels,便于首次联调快速发现同义字段变化。
|
||||
"""
|
||||
tree = _html_tree(page)
|
||||
@@ -708,6 +709,7 @@ class ContractOaClient:
|
||||
"contract_no": contract_no,
|
||||
"workflow_no": workflow_no,
|
||||
"purchase_order_no": _field_value(labels, "采购单号") or _purchase_order_no_from_title(_field_value(labels, "标题")),
|
||||
"company_name": _field_value(labels, "公司"),
|
||||
"supplier_name": _field_value(labels, "合同单位", "供应商"),
|
||||
"applicant_name": _field_value(labels, "申请人", "申请人员", "申请人姓名"),
|
||||
"total_amount": total_amount,
|
||||
@@ -807,6 +809,7 @@ class ContractOaClient:
|
||||
"contract_no": detail.get("contract_no") or None,
|
||||
"workflow_no": detail.get("workflow_no") or process_id,
|
||||
"purchase_order_no": detail.get("purchase_order_no"),
|
||||
"company_name": detail.get("company_name"),
|
||||
"supplier_name": detail.get("supplier_name"),
|
||||
"applicant_name": detail.get("applicant_name"),
|
||||
"total_amount": detail.get("total_amount"),
|
||||
@@ -907,12 +910,43 @@ def _pick(row: dict[str, Any], *keys: str) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def _cell_text(cell: Any) -> str:
|
||||
"""
|
||||
读取表单单元格的展示值。
|
||||
|
||||
核心逻辑:下拉框的 HTML 会带上全部选项。只取 `option selected`;没有 selected 时,
|
||||
用同格隐藏 input 的 value 对上 option 的 value。普通文本格仍拼接可见文字。
|
||||
有下拉框但无法确定选中项时返回空,避免把候选项拼成公司名。
|
||||
"""
|
||||
selects = cell.xpath(".//select")
|
||||
if not selects:
|
||||
return _clean_text(" ".join(cell.xpath(".//text()")))
|
||||
select = selects[0]
|
||||
for option in select.xpath("./option[@selected]"):
|
||||
text = _clean_text("".join(option.xpath(".//text()")))
|
||||
if text:
|
||||
return text
|
||||
current = ""
|
||||
for node in cell.xpath(".//input[@value]"):
|
||||
current = str(node.get("value") or "").strip()
|
||||
if current:
|
||||
break
|
||||
if current:
|
||||
for option in select.xpath("./option"):
|
||||
if str(option.get("value") or "").strip() != current:
|
||||
continue
|
||||
text = _clean_text("".join(option.xpath(".//text()")))
|
||||
if text:
|
||||
return text
|
||||
return ""
|
||||
|
||||
|
||||
def _table_fields(tree: Any) -> dict[str, str]:
|
||||
"""解析表格中“标签单元格 + 值单元格”对;同一行可包含多组字段。"""
|
||||
"""解析表格中“标签单元格 + 值单元格”对;同一行可包含多组字段。下拉框只取选中项。"""
|
||||
fields: dict[str, str] = {}
|
||||
for row in tree.xpath("//tr"):
|
||||
cells = row.xpath("./th|./td")
|
||||
texts = [_clean_text(" ".join(cell.xpath(".//text()"))) for cell in cells]
|
||||
texts = [_cell_text(cell) for cell in cells]
|
||||
for index in range(0, len(texts) - 1, 2):
|
||||
label, value = texts[index], texts[index + 1]
|
||||
if label and value and len(label) <= 32:
|
||||
|
||||
Reference in new issue
Block a user