This commit is contained in:
admin
2026-01-22 22:10:17 +09:00
parent 536266d70b
commit 50e534094d
9 changed files with 590 additions and 17 deletions

View File

@@ -12,7 +12,7 @@ class BonusCalculationService:
@staticmethod
def get_insurance_rate(rate_type: str, target_date: date, calculation_target: str = '賞与') -> Dict[str, Any]:
"""保険料率を取得(賞与用)"""
"""保険料率を取得(賞与用、年度がない場合は前年度を参照"""
with get_connection() as conn:
with conn.cursor() as cur:
# rate_yearで年度を判定
@@ -28,7 +28,28 @@ class BonusCalculationService:
""",
(rate_type, target_year, calculation_target)
)
return cur.fetchone()
result = cur.fetchone()
# 現在の年度でデータが見つからない場合は前年度を検索最大3年遡る
if not result:
for year_offset in range(1, 4):
previous_year = target_year - year_offset
cur.execute(
"""
SELECT * FROM insurance_rates
WHERE rate_type = %s
AND rate_year = %s
AND calculation_target = %s
ORDER BY rate_id DESC
LIMIT 1
""",
(rate_type, previous_year, calculation_target)
)
result = cur.fetchone()
if result:
break
return result
@staticmethod
def get_insurance_limit(setting_type: str, target_date: date) -> Decimal: