From 3f0f382d49e0d4d318c2d035482498c2c1a9dc89 Mon Sep 17 00:00:00 2001 From: mxr612 Date: Sat, 14 Jun 2025 06:32:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=8F=98=E5=8A=A8?= =?UTF-8?q?=E5=90=8E=E6=B4=A5=E8=B4=B4=E5=B7=A5=E8=B5=84=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=9A=84=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改allowance函数中的警告信息,明确指出津贴规则缺失 - 确保在津贴规则不存在时返回0,避免抛出异常 - 优化calc_history函数,新增变动后津贴工资字段的计算逻辑 --- main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 83acfb0..4a3846e 100644 --- a/main.py +++ b/main.py @@ -234,9 +234,10 @@ def allowance(role:str, level:int, time): tmp = rule["rule"][rule["rule"]["level"] == f"{role}-{level}"].iloc[0] return tmp["salary"] except: - logging.warning(f"组合[{role}-{level}]在[{time}]时不存在工资规则") + logging.warning(f"组合[{role}-{level}]在[{time}]时不存在津贴规则") + return 0 logging.warning(f"时间[{time}]时不存在津贴规则") - raise 0 + return 0 # 填充类辅助函数 @@ -367,9 +368,10 @@ def calc_history(History_pd, row): else: History_pd.at[index, "变动后级别档次"] = History_pd.at[index, "变动前级别档次"] # 计算工资 - History_pd.at[index, "变动后职务工资"] = role_salary(History_pd.iloc[index]["变动后职务"], hrow["变动后时间"]) - History_pd.at[index, "变动后级别工资"] = level_salary(History_pd.iloc[index]["变动后级别档次"], hrow["变动后时间"]) - History_pd.at[index, "变动后工资合计"] = to_int(History_pd.iloc[index]["变动后职务工资"]) + to_int(History_pd.iloc[index]["变动后级别工资"]) + History_pd.at[index, "变动后职务工资"] = role_salary(History_pd.at[index,"变动后职务"], hrow["变动后时间"]) + History_pd.at[index, "变动后级别工资"] = level_salary(History_pd.at[index,"变动后级别档次"], hrow["变动后时间"]) + History_pd.at[index, "变动后工资合计"] = to_int(History_pd.at[index,"变动后职务工资"]) + to_int(History_pd.at[index,"变动后级别工资"]) + History_pd.at[index, "变动后津贴工资"] = allowance(History_pd.at[index,"变动后职务"], History_pd.at[index,"工龄"], History_pd.at[index,"变动后时间"]) def fill_history_info(ws, History_pd):# 填充历史记录 for index, hrow in History_pd.iterrows(): # 打印