Commit 1a86bb2d authored by 邱阿朋's avatar 邱阿朋

fix(helper): 优化数字提取函数以支持不同国家的千分位分隔符

- 修改 extract_numeric_value 函数,增加 country 参数- 根据国家代码处理千分位分隔符:法国和德国使用逗号作为小数点,其他国家去掉逗号
- 在 spa.py 中调用更新后的 extract_numeric_value 函数,并传入国家代码
parent b52560cb
......@@ -19,7 +19,8 @@ def print_trace(title: str, err):
for i in traceback.extract_tb(except_traceback):
print("函数{},文件:{},行:{}".format(i.name, i.filename, i.lineno))
def extract_numeric_value(value):
def extract_numeric_value(value, country):
"""
从包含货币符号的字符串中提取纯数字
参数:
......@@ -29,8 +30,11 @@ def extract_numeric_value(value):
"""
str_value = str(value).strip()
# 处理千分位分隔符(如1,000.00)
str_value = str_value.replace(',', '')
# 法国和德国使用逗号作为小数点,其他语言去掉逗号
if country in ["FR", "DE"]:
str_value = str_value.replace(',', '.')
else:
str_value = str_value.replace(',', '')
# 移除非数字字符(保留数字和小数点)
numeric_str = re.sub(r'[^\d.]', '', str_value)
......
......@@ -218,11 +218,14 @@ class Spa(AutoInterface):
for sheet_name, df in sheets.items():
# 找到第一个空行(NaN值)的索引
first_empty = df[rebate_column].isna().idxmax()
# 只计算第一个空行之前的数据
valid_data = df.loc[:first_empty - 1, rebate_column]
# 计算总和,忽略NaN值
total_amount = total_amount + valid_data.sum()
if pd.isna(first_empty) or first_empty == 0:
total = df[rebate_column].sum()
total_amount = total_amount + total
else:
# 只计算第一个空行之前的数据
valid_data = df.loc[:first_empty - 1, rebate_column]
# 计算总和,忽略NaN值
total_amount = total_amount + valid_data.sum()
return total_amount
......@@ -307,7 +310,7 @@ class Spa(AutoInterface):
# 计算每个sheet总金额
total_amount = self.__calculate_sheets_total_amount(item_dict)
original_balance = coop.get("Original balance", 0.0)
original_balance = helper.extract_numeric_value(original_balance)
original_balance = helper.extract_numeric_value(original_balance, self.country)
# 0 没有税 1 有税
va_tax = int(total_amount != original_balance)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment