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): ...@@ -19,7 +19,8 @@ def print_trace(title: str, err):
for i in traceback.extract_tb(except_traceback): for i in traceback.extract_tb(except_traceback):
print("函数{},文件:{},行:{}".format(i.name, i.filename, i.lineno)) 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): ...@@ -29,8 +30,11 @@ def extract_numeric_value(value):
""" """
str_value = str(value).strip() 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) numeric_str = re.sub(r'[^\d.]', '', str_value)
......
...@@ -218,11 +218,14 @@ class Spa(AutoInterface): ...@@ -218,11 +218,14 @@ class Spa(AutoInterface):
for sheet_name, df in sheets.items(): for sheet_name, df in sheets.items():
# 找到第一个空行(NaN值)的索引 # 找到第一个空行(NaN值)的索引
first_empty = df[rebate_column].isna().idxmax() first_empty = df[rebate_column].isna().idxmax()
if pd.isna(first_empty) or first_empty == 0:
# 只计算第一个空行之前的数据 total = df[rebate_column].sum()
valid_data = df.loc[:first_empty - 1, rebate_column] total_amount = total_amount + total
# 计算总和,忽略NaN值 else:
total_amount = total_amount + valid_data.sum() # 只计算第一个空行之前的数据
valid_data = df.loc[:first_empty - 1, rebate_column]
# 计算总和,忽略NaN值
total_amount = total_amount + valid_data.sum()
return total_amount return total_amount
...@@ -307,7 +310,7 @@ class Spa(AutoInterface): ...@@ -307,7 +310,7 @@ class Spa(AutoInterface):
# 计算每个sheet总金额 # 计算每个sheet总金额
total_amount = self.__calculate_sheets_total_amount(item_dict) total_amount = self.__calculate_sheets_total_amount(item_dict)
original_balance = coop.get("Original balance", 0.0) 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 有税 # 0 没有税 1 有税
va_tax = int(total_amount != original_balance) 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