refactor: improve discrete material plan processing logic with better status handling

- Restructure conditional flow to check status before detail count
- Add handling for orders with no material plan data
- Add handling for completed orders (status=完成)
- Add warning for orders with unrecognized status
- Fix deletion condition to check for non-zero pending quantity

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-24 17:13:56 +08:00
parent e5f6f4ee0c
commit 7a8a38a3b6

View File

@@ -113,56 +113,62 @@ class DiscreteMaterialPlanCleaner:
detail_status = re.search(r"备料状态:(.+)$", status_text.replace("\n", "")).group(1) detail_status = re.search(r"备料状态:(.+)$", status_text.replace("\n", "")).group(1)
# 6. 执行清理逻辑 # 6. 执行清理逻辑
if detail_count > 0 and detail_status == "审批通过": if detail_status == "审批通过":
# --- 点击修改并等待状态切换 (保留原逻辑) --- if detail_count >0:
detail_inner_frame.get_by_role("button", name="修改").click() # --- 点击修改并等待状态切换 (保留原逻辑) ---
detail_inner_frame.get_by_role("button", name="修改").click()
# 关键判断:等待保存按钮出现,确认进入编辑模式 # 关键判断:等待保存按钮出现,确认进入编辑模式
save_button_locator = detail_inner_frame.get_by_role("button", name="保存") save_button_locator = detail_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)
self._log("已进入编辑模式(保存按钮已就绪)") self._log("已进入编辑模式(保存按钮已就绪)")
# --------------------------------------- # ---------------------------------------
detail_inner_frame.get_by_text("展开").first.click() detail_inner_frame.get_by_text("展开").first.click()
child_form = detail_inner_frame.locator(".card-table-side-box") child_form = detail_inner_frame.locator(".card-table-side-box")
button_wrapper = child_form.locator(".button-wrapper") button_wrapper = child_form.locator(".button-wrapper")
delete_row_btn = button_wrapper.get_by_role("button", name="删行") delete_row_btn = button_wrapper.get_by_role("button", name="删行")
next_btn = button_wrapper.locator(".icon-jiantouyou") next_btn = button_wrapper.locator(".icon-jiantouyou")
collapse_btn = button_wrapper.locator(".icon-celashouqi") collapse_btn = button_wrapper.locator(".icon-celashouqi")
last_row_number = None last_row_number = None
while True: while True:
# 稳定性检查:等待行号更新 # 稳定性检查:等待行号更新
current_row = self._get_input_value(child_form, r"^行号$") current_row = self._get_input_value(child_form, r"^行号$")
if current_row == last_row_number: if current_row == last_row_number:
time.sleep(0.5) time.sleep(0.5)
material_code = self._get_input_value(child_form, r"^材料编码") material_code = self._get_input_value(child_form, r"^材料编码")
material_name = self._get_input_value(child_form, r"^材料名称") material_name = self._get_input_value(child_form, r"^材料名称")
pending_qty = self._get_input_value(child_form, r"^累计待发数量$") pending_qty = self._get_input_value(child_form, r"^累计待发数量$")
if material_code in self.to_delete_set: if material_code in self.to_delete_set:
self._log(f"发现匹配物料: {material_name} ({material_code})") self._log(f"发现匹配物料: {material_name} ({material_code})")
if not pending_qty or float(pending_qty) == 0: if not pending_qty or float(pending_qty) != 0:
delete_row_btn.click() delete_row_btn.click()
self._log(f"✅ 已点击删行") self._log(f"✅ 已点击删行")
continue continue
else:
self._log(f"⚠️ 待发数量为 {pending_qty},跳过删除", "warn")
else: else:
self._log(f"⚠️ 待发数量为 {pending_qty},跳过删除", "warn") self._log(f"物料 {material_name} ({material_code}) 不在删除列表中,不做处理")
if self._is_button_enabled(next_btn):
if self._is_button_enabled(next_btn): last_row_number = current_row
last_row_number = current_row next_btn.click()
next_btn.click() else:
else: break
break collapse_btn.click()
collapse_btn.click()
# 执行最终保存逻辑(如业务需要)
# save_button_locator.click()
# 执行最终保存逻辑(如业务需要)
# save_button_locator.click()
else:
self._log("订单无备料计划数据,无需处理")
elif detail_status == "完成":
self._log("订单已完成,无需处理")
else:
self._log(f"订单状态为 [{detail_status}],不符合处理条件", "warn")
page2.close() page2.close()
def setup_query_interface(self, inner_frame): def setup_query_interface(self, inner_frame):