style: normalize code formatting across the codebase
- Standardize quote style (single to double quotes) - Improve code formatting consistency - Apply formatting to utilities, GUI components, and tools - Update imports and docstrings for consistency Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,14 @@
|
||||
离散备料计划维护数据清理工具
|
||||
负责登录、逐个清理订单数据
|
||||
"""
|
||||
|
||||
import os
|
||||
from playwright.sync_api import sync_playwright
|
||||
from utils.auth import login, logout
|
||||
from db.production_order_query import read_production_ids, query_production_order_numbers
|
||||
from db.production_order_query import (
|
||||
read_production_ids,
|
||||
query_production_order_numbers,
|
||||
)
|
||||
from db.materials_to_delete import get_materials_to_delete
|
||||
|
||||
|
||||
@@ -54,7 +58,16 @@ class DiscreteMaterialPlanCleaner:
|
||||
|
||||
return order_ids
|
||||
|
||||
def process_order(self, inner_frame, order_id, order_index, page1, materials_to_delete=None, debug_mode=False, debug_order=None):
|
||||
def process_order(
|
||||
self,
|
||||
inner_frame,
|
||||
order_id,
|
||||
order_index,
|
||||
page1,
|
||||
materials_to_delete=None,
|
||||
debug_mode=False,
|
||||
debug_order=None,
|
||||
):
|
||||
"""清理单个订单的数据
|
||||
|
||||
Args:
|
||||
@@ -97,9 +110,8 @@ class DiscreteMaterialPlanCleaner:
|
||||
if debug_mode and (debug_order is None or order_index == debug_order):
|
||||
self._print(f"=== 调试暂停:第 {order_index + 1} 个订单 ===")
|
||||
page1.pause()
|
||||
|
||||
|
||||
inner_frame.locator("#hot-key-head_list").get_by_text("更多").click()
|
||||
|
||||
|
||||
with page1.expect_popup() as page2_info:
|
||||
inner_frame.get_by_text("备料计划").click()
|
||||
@@ -153,9 +165,7 @@ class DiscreteMaterialPlanCleaner:
|
||||
detail_status = match.group(1)
|
||||
self._print(f"备料状态: {detail_status}")
|
||||
|
||||
|
||||
|
||||
#page2.pause()
|
||||
# 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="保存")
|
||||
@@ -163,7 +173,6 @@ class DiscreteMaterialPlanCleaner:
|
||||
|
||||
inner_frame.get_by_text("展开").first.click()
|
||||
|
||||
|
||||
# 获取展开后的父容器,基于它定位子元素更加精确
|
||||
# 父元素 class="card-table-side-box undefined"
|
||||
child_form = inner_frame.locator(".card-table-side-box")
|
||||
@@ -171,7 +180,6 @@ class DiscreteMaterialPlanCleaner:
|
||||
child_form.wait_for(state="visible", timeout=5000)
|
||||
self._print(f"父容器 .card-table-side-box 已找到")
|
||||
|
||||
|
||||
page2.pause()
|
||||
for id in range(detail_count):
|
||||
id_lable_locator = child_form.get_by_text("序号 " + str(id + 1))
|
||||
@@ -179,20 +187,37 @@ class DiscreteMaterialPlanCleaner:
|
||||
self._print(f"处理 {id_lable_locator.inner_text()} ")
|
||||
|
||||
# 获取材料编码(通过文本定位,取第一个input)
|
||||
input_box = child_form.locator("div").filter(has_text=re.compile(r"^材料编码\d{11}$", re.MULTILINE)).locator("input").first
|
||||
input_box = (
|
||||
child_form.locator("div")
|
||||
.filter(has_text=re.compile(r"^材料编码\d{11}$", re.MULTILINE))
|
||||
.locator("input")
|
||||
.first
|
||||
)
|
||||
self._print(f"材料编码:{input_box.input_value()}")
|
||||
|
||||
# 获取材料名称
|
||||
input_box = child_form.locator("div").filter(has_text=re.compile(r"^材料名称$")).locator("input[type='text']")
|
||||
input_box = (
|
||||
child_form.locator("div")
|
||||
.filter(has_text=re.compile(r"^材料名称$"))
|
||||
.locator("input[type='text']")
|
||||
)
|
||||
material_name = input_box.input_value()
|
||||
self._print(f"材料名称:{material_name}")
|
||||
|
||||
# 获取累计待发数量
|
||||
input_box = child_form.locator("div").filter(has_text=re.compile(r"^累计待发数量$")).locator("input[type='text']")
|
||||
input_box = (
|
||||
child_form.locator("div")
|
||||
.filter(has_text=re.compile(r"^累计待发数量$"))
|
||||
.locator("input[type='text']")
|
||||
)
|
||||
self._print(f"累计待发数量:{input_box.input_value()}")
|
||||
|
||||
# 获取累计出库数量
|
||||
input_box = child_form.locator("div").filter(has_text=re.compile(r"^累计出库数量$")).locator("input[type='text']")
|
||||
input_box = (
|
||||
child_form.locator("div")
|
||||
.filter(has_text=re.compile(r"^累计出库数量$"))
|
||||
.locator("input[type='text']")
|
||||
)
|
||||
self._print(f"累计出库数量:{input_box.input_value()}")
|
||||
|
||||
# 检查是否需要清理该物料
|
||||
@@ -205,16 +230,22 @@ class DiscreteMaterialPlanCleaner:
|
||||
break
|
||||
|
||||
if should_delete:
|
||||
self._print(f">>> 需要清理:材料名称【{material_name}】匹配关键字【{matched_keyword}】")
|
||||
self._print(
|
||||
f">>> 需要清理:材料名称【{material_name}】匹配关键字【{matched_keyword}】"
|
||||
)
|
||||
# TODO: 执行删除操作
|
||||
else:
|
||||
self._print(f"保留:材料名称【{material_name}】无需清理")
|
||||
|
||||
if id != detail_count - 1:
|
||||
child_form.get_by_role("button").filter(has_text=re.compile(r"^$")).nth(2).click()
|
||||
child_form.get_by_role("button").filter(
|
||||
has_text=re.compile(r"^$")
|
||||
).nth(2).click()
|
||||
else:
|
||||
child_form.get_by_role("button").filter(has_text=re.compile(r"^$")).nth(4).click()
|
||||
#page2.pause()
|
||||
child_form.get_by_role("button").filter(
|
||||
has_text=re.compile(r"^$")
|
||||
).nth(4).click()
|
||||
# page2.pause()
|
||||
|
||||
elif detail_count == 0:
|
||||
self._print(f"第 {order_index + 1} 个订单无数据需要清理,跳过...")
|
||||
@@ -225,11 +256,6 @@ class DiscreteMaterialPlanCleaner:
|
||||
page2.close()
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
page2.close()
|
||||
time.sleep(1)
|
||||
pass
|
||||
@@ -255,9 +281,13 @@ class DiscreteMaterialPlanCleaner:
|
||||
self._print(f"文本框填充成功: {expected_value}")
|
||||
break
|
||||
else:
|
||||
self._print(f"第 {attempt + 1} 次填充失败,实际值: {actual_value},重试...")
|
||||
self._print(
|
||||
f"第 {attempt + 1} 次填充失败,实际值: {actual_value},重试..."
|
||||
)
|
||||
if attempt == max_retries - 1:
|
||||
self._print(f"警告: {max_retries} 次尝试后仍未成功填充,继续执行...")
|
||||
self._print(
|
||||
f"警告: {max_retries} 次尝试后仍未成功填充,继续执行..."
|
||||
)
|
||||
|
||||
def clean(self, production_id_file, debug_mode=False, debug_order=None):
|
||||
"""
|
||||
@@ -280,7 +310,7 @@ class DiscreteMaterialPlanCleaner:
|
||||
username=self.username,
|
||||
password=self.password,
|
||||
headless=self.headless,
|
||||
ignore_https_errors=True
|
||||
ignore_https_errors=True,
|
||||
)
|
||||
|
||||
self._print("=" * 80)
|
||||
@@ -310,10 +340,17 @@ class DiscreteMaterialPlanCleaner:
|
||||
|
||||
# 按订单清理
|
||||
for order_index, order_id in enumerate(order_ids):
|
||||
self._print(f"\n=== 开始处理第 {order_index + 1} 个订单,订单号: {order_id} ===")
|
||||
self._print(
|
||||
f"\n=== 开始处理第 {order_index + 1} 个订单,订单号: {order_id} ==="
|
||||
)
|
||||
self.process_order(
|
||||
inner_frame, order_id, order_index, page1, materials_to_delete,
|
||||
debug_mode=debug_mode, debug_order=debug_order
|
||||
inner_frame,
|
||||
order_id,
|
||||
order_index,
|
||||
page1,
|
||||
materials_to_delete,
|
||||
debug_mode=debug_mode,
|
||||
debug_order=debug_order,
|
||||
)
|
||||
|
||||
# 执行账号注销
|
||||
@@ -334,7 +371,7 @@ def main():
|
||||
password="Cqbld123456.",
|
||||
manager_name="彭羽",
|
||||
headless=False,
|
||||
verbose=True
|
||||
verbose=True,
|
||||
)
|
||||
|
||||
production_id_file = os.path.join(os.path.dirname(__file__), "productionID.txt")
|
||||
|
||||
Reference in New Issue
Block a user