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,7 +113,8 @@ class DiscreteMaterialPlanCleaner:
detail_status = re.search(r"备料状态:(.+)$", status_text.replace("\n", "")).group(1)
# 6. 执行清理逻辑
if detail_count > 0 and detail_status == "审批通过":
if detail_status == "审批通过":
if detail_count >0:
# --- 点击修改并等待状态切换 (保留原逻辑) ---
detail_inner_frame.get_by_role("button", name="修改").click()
@@ -145,24 +146,29 @@ class DiscreteMaterialPlanCleaner:
if material_code in self.to_delete_set:
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()
self._log(f"✅ 已点击删行")
continue
else:
self._log(f"⚠️ 待发数量为 {pending_qty},跳过删除", "warn")
else:
self._log(f"物料 {material_name} ({material_code}) 不在删除列表中,不做处理")
if self._is_button_enabled(next_btn):
last_row_number = current_row
next_btn.click()
else:
break
collapse_btn.click()
# 执行最终保存逻辑(如业务需要)
# save_button_locator.click()
else:
self._log("订单无备料计划数据,无需处理")
elif detail_status == "完成":
self._log("订单已完成,无需处理")
else:
self._log(f"订单状态为 [{detail_status}],不符合处理条件", "warn")
page2.close()
def setup_query_interface(self, inner_frame):