v1.1.0: 版本更新 - 增强规格解析能力、修复条码映射功能、改进特殊条码处理
This commit is contained in:
@@ -297,6 +297,17 @@ class UnitConverter:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 处理带重量单位的规格,如5kg*6、500g*12等
|
||||
weight_match = re.match(r'([\d\.]+)(?:kg|g|克|千克|公斤)[*](\d+)', spec, re.IGNORECASE)
|
||||
if weight_match:
|
||||
try:
|
||||
# 对于重量单位,使用1作为一级包装,后面的数字作为二级包装
|
||||
level2 = int(weight_match.group(2))
|
||||
logger.info(f"解析重量规格: {spec} -> 1*{level2}")
|
||||
return 1, level2, None
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 处理带容量单位的规格,如500ml*15, 1L*12等
|
||||
ml_match = re.match(r'(\d+)(?:ml|毫升)[*](\d+)', spec, re.IGNORECASE)
|
||||
if ml_match:
|
||||
@@ -340,6 +351,17 @@ class UnitConverter:
|
||||
return 1, quantity, None
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 处理不规范格式,如IL*12, 6oo*12等,从中提取数字部分作为包装数量
|
||||
# 只要规格中包含*和数字,就尝试提取*后面的数字作为件数
|
||||
irregular_match = re.search(r'[^0-9]*\*(\d+)', spec)
|
||||
if irregular_match:
|
||||
try:
|
||||
level2 = int(irregular_match.group(1))
|
||||
logger.info(f"解析不规范规格: {spec} -> 1*{level2}")
|
||||
return 1, level2, None
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 默认值
|
||||
logger.warning(f"无法解析规格: {spec},使用默认值1*1")
|
||||
@@ -440,6 +462,12 @@ class UnitConverter:
|
||||
'6923644268923': {
|
||||
'map_to': '6923644268480',
|
||||
'description': '条码映射:6923644268923 -> 6923644268480'
|
||||
},
|
||||
# 添加特殊条码6958620703716,既需要特殊处理又需要映射
|
||||
'6958620703716': {
|
||||
'specification': '1*14',
|
||||
'map_to': '6958620703907',
|
||||
'description': '特殊处理: 规格1*14,同时映射到6958620703907'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,6 @@ class BarcodeMapper:
|
||||
|
||||
special_config = self.special_barcodes[barcode]
|
||||
|
||||
# 处理条码映射
|
||||
if 'map_to' in special_config:
|
||||
new_barcode = special_config['map_to']
|
||||
logger.info(f"条码映射: {barcode} -> {new_barcode}")
|
||||
result['barcode'] = new_barcode
|
||||
|
||||
# 处理特殊倍数
|
||||
if 'multiplier' in special_config:
|
||||
multiplier = special_config.get('multiplier', 1)
|
||||
@@ -79,5 +73,11 @@ class BarcodeMapper:
|
||||
result['quantity'] = new_quantity
|
||||
result['price'] = new_price
|
||||
result['unit'] = target_unit
|
||||
|
||||
# 处理条码映射 - 放在后面以便可以同时进行特殊处理和条码映射
|
||||
if 'map_to' in special_config:
|
||||
new_barcode = special_config['map_to']
|
||||
logger.info(f"条码映射: {barcode} -> {new_barcode}")
|
||||
result['barcode'] = new_barcode
|
||||
|
||||
return result
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox, ttk
|
||||
from tkinter import messagebox, ttk, simpledialog
|
||||
from datetime import datetime
|
||||
|
||||
def create_custom_dialog(title="提示", message="", result_file=None, time_info=None,
|
||||
@@ -363,6 +363,45 @@ def create_barcode_mapping_dialog(parent=None, on_save=None, current_mappings=No
|
||||
remove_special_btn = tk.Button(special_btn_frame, text="删除特殊处理", command=remove_special)
|
||||
remove_special_btn.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
# 添加映射到特殊处理的功能
|
||||
def add_mapping_to_special():
|
||||
selected = special_tree.selection()
|
||||
if not selected:
|
||||
messagebox.showwarning("未选择", "请先选择要添加映射的特殊处理条目")
|
||||
return
|
||||
|
||||
# 获取选中项
|
||||
item = special_tree.item(selected[0])
|
||||
barcode = item['values'][0]
|
||||
|
||||
# 弹出对话框输入映射目标
|
||||
target_barcode = tk.simpledialog.askstring("添加映射", f"为条码 {barcode} 添加映射目标条码:")
|
||||
if not target_barcode:
|
||||
return
|
||||
|
||||
# 更新特殊处理列表中的项
|
||||
for i, (b, mult, unit, price, spec, desc) in enumerate(special_list):
|
||||
if b == barcode:
|
||||
# 如果描述中已有映射信息,更新它
|
||||
if "映射到:" in desc:
|
||||
desc = desc.split("映射到:")[0].strip()
|
||||
|
||||
# 添加映射信息到描述
|
||||
new_desc = f"{desc} 映射到: {target_barcode}"
|
||||
special_list[i] = (b, mult, unit, price, spec, new_desc)
|
||||
|
||||
# 更新显示
|
||||
special_tree.item(selected[0], values=(b, mult, unit, price, spec, new_desc))
|
||||
|
||||
# 标记该条码有映射
|
||||
special_tree.item(selected[0], tags=("mapped",))
|
||||
special_tree.tag_configure("mapped", foreground="blue")
|
||||
|
||||
break
|
||||
|
||||
map_special_btn = tk.Button(special_btn_frame, text="添加条码映射", command=add_mapping_to_special)
|
||||
map_special_btn.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
# 底部按钮区域
|
||||
bottom_frame = tk.Frame(dialog)
|
||||
bottom_frame.pack(fill=tk.X, padx=10, pady=10)
|
||||
@@ -380,7 +419,9 @@ def create_barcode_mapping_dialog(parent=None, on_save=None, current_mappings=No
|
||||
|
||||
# 添加特殊处理
|
||||
for barcode, multiplier, unit, price, spec, desc in special_list:
|
||||
mappings[barcode] = {}
|
||||
# 检查该条码是否已存在
|
||||
if barcode not in mappings:
|
||||
mappings[barcode] = {}
|
||||
|
||||
if multiplier:
|
||||
try:
|
||||
@@ -411,7 +452,19 @@ def create_barcode_mapping_dialog(parent=None, on_save=None, current_mappings=No
|
||||
if spec:
|
||||
mappings[barcode]['specification'] = spec
|
||||
|
||||
if desc:
|
||||
# 检查描述中是否包含映射信息
|
||||
if desc and "映射到:" in desc:
|
||||
parts = desc.split("映射到:")
|
||||
base_desc = parts[0].strip()
|
||||
target_barcode = parts[1].strip()
|
||||
|
||||
# 设置基本描述
|
||||
if base_desc:
|
||||
mappings[barcode]['description'] = base_desc
|
||||
|
||||
# 设置映射目标
|
||||
mappings[barcode]['map_to'] = target_barcode
|
||||
elif desc:
|
||||
mappings[barcode]['description'] = desc
|
||||
|
||||
# 调用保存回调
|
||||
|
||||
@@ -69,6 +69,29 @@ class OrderService:
|
||||
"""
|
||||
return self.order_merger.get_purchase_orders()
|
||||
|
||||
def merge_purchase_orders(self, file_paths: List[str]) -> Optional[str]:
|
||||
"""
|
||||
合并指定的采购单文件
|
||||
|
||||
Args:
|
||||
file_paths: 采购单文件路径列表
|
||||
|
||||
Returns:
|
||||
合并后的采购单文件路径,如果合并失败则返回None
|
||||
"""
|
||||
logger.info(f"OrderService开始合并指定采购单: {file_paths}")
|
||||
return self.merge_orders(file_paths)
|
||||
|
||||
def merge_all_purchase_orders(self) -> Optional[str]:
|
||||
"""
|
||||
合并所有可用的采购单文件
|
||||
|
||||
Returns:
|
||||
合并后的采购单文件路径,如果合并失败则返回None
|
||||
"""
|
||||
logger.info("OrderService开始合并所有采购单")
|
||||
return self.merge_orders(None)
|
||||
|
||||
def merge_orders(self, file_paths: Optional[List[str]] = None) -> Optional[str]:
|
||||
"""
|
||||
合并采购单
|
||||
|
||||
Reference in New Issue
Block a user