优化原料管理界面功能
1. 类目选项标准化 - 新增和编辑界面的类目固定为"面料"、"辅料"、"其他"三个选项 - 新增原料时默认选中"面料" 2. 必填字段验证 - 新增必填验证:类目、类型、幅宽、克重 - 保存时验证所有必填字段,提供明确的错误提示 3. 已删除原料恢复功能 - 允许新增已被删除的型号,自动恢复并更新原料信息 - 无需用户确认,直接恢复已删除原料 4. 供应商字段优化 - 新增原料时供应商默认为空 - 用户可选择输入新供应商或从列表选择 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -111,11 +111,8 @@ class RawMaterialEditDialog(QDialog):
|
||||
"""加载类目和供应商列表"""
|
||||
try:
|
||||
with self.get_conn() as conn:
|
||||
# 加载类目
|
||||
cursor = conn.execute("SELECT DISTINCT category FROM fabrics WHERE category IS NOT NULL AND category != '' AND (is_deleted IS NULL OR is_deleted = 0)")
|
||||
majors = set(row[0] for row in cursor.fetchall() if row[0])
|
||||
majors.update({"布料", "辅料", "其他"})
|
||||
self.edit_major_category.addItems(sorted(majors))
|
||||
# 加载类目 - 设置默认选项为:面料、辅料、其他
|
||||
self.edit_major_category.addItems(["面料", "辅料", "其他"])
|
||||
|
||||
# 加载供应商
|
||||
cursor = conn.execute("SELECT DISTINCT supplier FROM fabrics WHERE supplier IS NOT NULL AND supplier != '' AND (is_deleted IS NULL OR is_deleted = 0) ORDER BY supplier")
|
||||
@@ -172,6 +169,26 @@ class RawMaterialEditDialog(QDialog):
|
||||
major = self.edit_major_category.currentText().strip()
|
||||
sub = self.edit_sub_category.text().strip()
|
||||
|
||||
# 验证必填字段:类目
|
||||
if not major:
|
||||
QMessageBox.warning(self, "错误", "请选择类目")
|
||||
return
|
||||
|
||||
# 验证必填字段:类型
|
||||
if not sub:
|
||||
QMessageBox.warning(self, "错误", "请输入类型")
|
||||
return
|
||||
|
||||
# 验证必填字段:幅宽
|
||||
if self.edit_width.value() <= 0:
|
||||
QMessageBox.warning(self, "错误", "请输入幅宽")
|
||||
return
|
||||
|
||||
# 验证必填字段:克重
|
||||
if self.edit_gsm.value() <= 0:
|
||||
QMessageBox.warning(self, "错误", "请输入克重")
|
||||
return
|
||||
|
||||
# 特殊处理胸杯类型
|
||||
if "胸杯" in sub:
|
||||
major = "辅料"
|
||||
@@ -471,26 +488,12 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
|
||||
def load_add_major_categories(self):
|
||||
"""加载添加界面的主类目"""
|
||||
try:
|
||||
with self.get_conn() as conn:
|
||||
cursor = conn.execute("SELECT DISTINCT category FROM fabrics WHERE category IS NOT NULL AND category != '' AND (is_deleted IS NULL OR is_deleted = 0)")
|
||||
majors = set(row[0] for row in cursor.fetchall() if row[0])
|
||||
majors.update({"布料", "辅料", "其他"})
|
||||
|
||||
# 设置默认类目选项为:面料、辅料、其他
|
||||
self.add_major_category.blockSignals(True)
|
||||
current_text = self.add_major_category.currentText()
|
||||
self.add_major_category.clear()
|
||||
self.add_major_category.addItems(sorted(majors))
|
||||
|
||||
if current_text in majors:
|
||||
self.add_major_category.setCurrentText(current_text)
|
||||
else:
|
||||
self.add_major_category.setCurrentText("布料")
|
||||
self.add_major_category.addItems(["面料", "辅料", "其他"])
|
||||
self.add_major_category.setCurrentText("面料")
|
||||
self.add_major_category.blockSignals(False)
|
||||
except:
|
||||
self.add_major_category.clear()
|
||||
self.add_major_category.addItems(["布料", "辅料", "其他"])
|
||||
self.add_major_category.setCurrentText("布料")
|
||||
|
||||
def load_sub_categories(self):
|
||||
"""加载子类型"""
|
||||
@@ -528,9 +531,12 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
self.supplier_combo.addItems(suppliers)
|
||||
self.supplier_combo.blockSignals(False)
|
||||
|
||||
# 新增原料界面的供应商下拉框,添加空选项作为默认值
|
||||
self.add_supplier.blockSignals(True)
|
||||
self.add_supplier.clear()
|
||||
self.add_supplier.addItem("") # 添加空选项
|
||||
self.add_supplier.addItems(suppliers)
|
||||
self.add_supplier.setCurrentIndex(0) # 默认选中空选项
|
||||
self.add_supplier.blockSignals(False)
|
||||
except:
|
||||
pass
|
||||
@@ -647,7 +653,7 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
|
||||
def delete_raw(self, model):
|
||||
"""逻辑删除原料"""
|
||||
reply = QMessageBox.question(self, "确认", f"确定要删除 '{model}' 吗?\n\n此操作将标记删除该原料,不会影响历史数据。")
|
||||
reply = QMessageBox.question(self, "确认", f"确定要删除 '{model}' 吗?")
|
||||
if reply == QMessageBox.Yes:
|
||||
try:
|
||||
with self.get_conn() as conn:
|
||||
@@ -668,6 +674,27 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
|
||||
major = self.add_major_category.currentText().strip()
|
||||
sub = self.add_sub_category.text().strip()
|
||||
|
||||
# 验证必填字段:类目
|
||||
if not major:
|
||||
QMessageBox.warning(self, "错误", "请选择类目")
|
||||
return
|
||||
|
||||
# 验证必填字段:类型
|
||||
if not sub:
|
||||
QMessageBox.warning(self, "错误", "请输入类型")
|
||||
return
|
||||
|
||||
# 验证必填字段:幅宽
|
||||
if self.add_width.value() <= 0:
|
||||
QMessageBox.warning(self, "错误", "请输入幅宽")
|
||||
return
|
||||
|
||||
# 验证必填字段:克重
|
||||
if self.add_gsm.value() <= 0:
|
||||
QMessageBox.warning(self, "错误", "请输入克重")
|
||||
return
|
||||
|
||||
if "胸杯" in sub:
|
||||
major = "辅料"
|
||||
|
||||
@@ -680,12 +707,32 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
|
||||
try:
|
||||
with self.get_conn() as conn:
|
||||
# 检查是否已存在
|
||||
cursor = conn.execute("SELECT model FROM fabrics WHERE model = ?", (model,))
|
||||
if cursor.fetchone():
|
||||
# 检查是否已存在该型号
|
||||
cursor = conn.execute("SELECT model, is_deleted FROM fabrics WHERE model = ?", (model,))
|
||||
existing = cursor.fetchone()
|
||||
|
||||
if existing:
|
||||
_, is_deleted = existing
|
||||
|
||||
# 如果型号存在且未被删除,提示使用编辑功能
|
||||
if not is_deleted or is_deleted == 0:
|
||||
QMessageBox.warning(self, "错误", f"型号 '{model}' 已存在,请使用编辑功能修改")
|
||||
return
|
||||
|
||||
# 如果型号已被删除,直接恢复并更新
|
||||
conn.execute('''
|
||||
UPDATE fabrics
|
||||
SET category=?, fabric_type=?, supplier=?, color=?, width=?, gsm=?,
|
||||
retail_price=?, bulk_price=?, unit=?, timestamp=?, is_deleted=0, updated_at=CURRENT_TIMESTAMP
|
||||
WHERE model=?
|
||||
''', (category, fabric_type, supplier, color,
|
||||
self.add_width.value() or None, self.add_gsm.value() or None,
|
||||
self.add_retail.value() or None, self.add_bulk.value() or None,
|
||||
unit, datetime.now().strftime('%Y-%m-%d %H:%M:%S'), model))
|
||||
conn.commit()
|
||||
QMessageBox.information(self, "成功", f"已保存 '{model}'")
|
||||
else:
|
||||
# 型号不存在,创建新记录
|
||||
conn.execute('''
|
||||
INSERT INTO fabrics
|
||||
(model, category, fabric_type, supplier, color, width, gsm, retail_price, bulk_price, unit, timestamp)
|
||||
@@ -695,7 +742,6 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
self.add_retail.value() or None, self.add_bulk.value() or None,
|
||||
unit, datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
|
||||
conn.commit()
|
||||
|
||||
QMessageBox.information(self, "成功", f"已保存 '{model}'")
|
||||
|
||||
# 清空表单
|
||||
|
||||
Reference in New Issue
Block a user