From cf88800444f6a39ef82ae4da248ad9a2d272a4f2 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Fri, 23 Jan 2026 11:11:22 +0800 Subject: [PATCH] feat: Check preparation status before cleaning data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added logic to extract and validate the "Material Preparation Status" (备料状态) before modifying discrete material plans. The cleanup process now only proceeds if the status is "审批通过" (Approval Passed). Orders with other statuses are skipped to prevent errors during modification. This change also includes code cleanup by removing commented-out debug statements. --- utils/离散备料计划维护数据清理.py | 34 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/utils/离散备料计划维护数据清理.py b/utils/离散备料计划维护数据清理.py index 8b52047..460940a 100644 --- a/utils/离散备料计划维护数据清理.py +++ b/utils/离散备料计划维护数据清理.py @@ -124,14 +124,25 @@ class DiscreteMaterialPlanCleaner: detail_count = int(match.group(1)) self._print(f"详细信息数量: {detail_count}") - - if detail_count > 0: + # 提取"备料状态"信息 + detail_element = inner_frame.get_by_text(re.compile(r"^备料状态:.+$")) + detail_text = detail_element.inner_text().replace("\n", "") + # 使用正则表达式提取括号中的数字 + match = re.search(r"^备料状态:(.+)$", detail_text) + if match: + detail_status = match.group(1) + self._print(f"备料状态: {detail_status}") + + + + #page2.pause() + if detail_count > 0 and detail_status == "审批通过": inner_frame.get_by_role("button", name="修改").click() save_button_locator = inner_frame.get_by_role("button", name="保存") save_button_locator.wait_for(state="visible", timeout=10000) inner_frame.get_by_text("展开").first.click() - page2.pause() + #page2.pause() for id in range(detail_count): id_lable_locator= inner_frame.get_by_text("序号 " + str(id + 1)).wait_for(state="visible", timeout=10000) @@ -146,8 +157,6 @@ class DiscreteMaterialPlanCleaner: match_result = int(match.group(1)) self._print(f"材料编码:{match_result}") - - input_box = inner_frame.locator("div").filter(has_text=re.compile(r"^材料名称$")).nth(2).locator("input[type='text']") self._print(f"材料名称:{input_box.input_value()}") @@ -157,19 +166,14 @@ class DiscreteMaterialPlanCleaner: inner_frame.get_by_role("button").filter(has_text=re.compile(r"^$")).nth(4).click() #page2.pause() - - - pass - - - - - - - else: + elif detail_count == 0: self._print(f"第 {order_index + 1} 个订单无数据需要清理,跳过...") page2.close() return + elif detail_status != "审批通过": + self._print(f"第 {order_index + 1} 个订单备料状态: {detail_status}") + page2.close() + return