feat(excel): 过滤非采购行并改进单位处理

- 在ExcelProcessor中增加备注列检查,过滤包含"换货"、"退货"等关键字的非采购行
- 改进单位处理器的匹配逻辑,支持"件、"、"箱装"等变体格式
- 修复config.ini文件末尾缺少换行符的问题
This commit is contained in:
2026-03-30 10:24:18 +08:00
parent 3e2f46d26d
commit bfccdd3a37
9 changed files with 243 additions and 7 deletions
@@ -63,8 +63,9 @@ class JianUnitHandler(UnitHandler):
Returns:
是否可以处理
"""
unit = product.get('unit', '')
return unit == ''
unit = str(product.get('unit', '')).strip()
# 匹配"件"、"件、"、"件装"等
return unit == '' or unit.startswith('')
def handle(self, product: Dict[str, Any], level1: int, level2: int, level3: Optional[int]) -> Dict[str, Any]:
"""
@@ -117,8 +118,9 @@ class BoxUnitHandler(UnitHandler):
Returns:
是否可以处理
"""
unit = product.get('unit', '')
return unit == ''
unit = str(product.get('unit', '')).strip()
# 匹配"箱"、"箱、"、"箱装"等
return unit == '' or unit.startswith('')
def handle(self, product: Dict[str, Any], level1: int, level2: int, level3: Optional[int]) -> Dict[str, Any]:
"""
@@ -171,8 +173,8 @@ class TiHeUnitHandler(UnitHandler):
Returns:
是否可以处理
"""
unit = product.get('unit', '')
return unit in ['', '']
unit = str(product.get('unit', '')).strip()
return unit in ['', ''] or unit.startswith('') or unit.startswith('')
def handle(self, product: Dict[str, Any], level1: int, level2: int, level3: Optional[int]) -> Dict[str, Any]:
"""
+14
View File
@@ -253,6 +253,20 @@ class ExcelProcessor:
# 跳过空条码行
if not product['barcode']:
continue
# 检查备注列,过滤换货、退货、作废等非采购行
skip_row = False
for col in df.columns:
col_str = str(col)
if any(k in col_str for k in ['备注', '说明', '类型', '备注1']):
val = str(row[col]).strip()
# 过滤常见的非采购关键字
if any(k in val for k in ['换货', '退货', '作废', '减钱', '冲减', '赠品单', '补货']):
logger.info(f"过滤非采购行: {product['barcode']} - {product.get('name', '')}, 原因: {col_str}包含 '{val}'")
skip_row = True
break
if skip_row:
continue
# 提取商品名称
if '商品名称' in df.columns and not pd.isna(row['商品名称']):