feat: Check preparation status before cleaning data

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.
This commit is contained in:
Misaka_Company
2026-01-23 11:11:22 +08:00
parent acd19025d4
commit cf88800444

View File

@@ -124,14 +124,25 @@ class DiscreteMaterialPlanCleaner:
detail_count = int(match.group(1)) detail_count = int(match.group(1))
self._print(f"详细信息数量: {detail_count}") 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() inner_frame.get_by_role("button", name="修改").click()
save_button_locator = inner_frame.get_by_role("button", name="保存") save_button_locator = inner_frame.get_by_role("button", name="保存")
save_button_locator.wait_for(state="visible", timeout=10000) save_button_locator.wait_for(state="visible", timeout=10000)
inner_frame.get_by_text("展开").first.click() inner_frame.get_by_text("展开").first.click()
page2.pause() #page2.pause()
for id in range(detail_count): for id in range(detail_count):
id_lable_locator= inner_frame.get_by_text("序号 " + str(id + 1)).wait_for(state="visible", timeout=10000) 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)) match_result = int(match.group(1))
self._print(f"材料编码:{match_result}") self._print(f"材料编码:{match_result}")
input_box = inner_frame.locator("div").filter(has_text=re.compile(r"^材料名称$")).nth(2).locator("input[type='text']") 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()}") 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() inner_frame.get_by_role("button").filter(has_text=re.compile(r"^$")).nth(4).click()
#page2.pause() #page2.pause()
elif detail_count == 0:
pass
else:
self._print(f"{order_index + 1} 个订单无数据需要清理,跳过...") self._print(f"{order_index + 1} 个订单无数据需要清理,跳过...")
page2.close() page2.close()
return return
elif detail_status != "审批通过":
self._print(f"{order_index + 1} 个订单备料状态: {detail_status}")
page2.close()
return