Files
njts-accounting-core/test_dependents_logic.py
2026-01-22 22:10:17 +09:00

53 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
扶養人数の検索ロジック検証
日本の所得税表では、扶養人数が多いほど税額が低くなります。
しかし、「3人」という記録が、実際には「3人以上」を意味しているかもしれません。
"""
# 仮想的な所得税テーブルの状態
sample_table = [
# (From, To, 扶養人数, 税額)
(355000, 360000, 0, 7450), # ← もしかしてこれが使われている?
(355000, 360000, 1, 6700),
(355000, 360000, 2, 6100),
(355000, 360000, 3, 5840), # ← これが正しい
(355000, 360000, 999, 3500), # または「3以上」という意味で大きい番号を使用
]
monthly_income = 356600
dependents_count = 3
print("=== 扶養人数の検索ロジック検証 ===\n")
print(f"検索条件: 月収 {monthly_income:,}, 扶養人数 {dependents_count}\n")
# シナリオ1: 完全一致検索
print("[シナリオ1] WHERE dependents_count = %s")
matches = [tax for from_v, to_v, dep, tax in sample_table
if from_v <= monthly_income < to_v and dep == dependents_count]
print(f"マッチ数: {len(matches)}")
for tax in matches:
print(f" → ¥{tax}")
# シナリオ2: >= 検索3人以上は3人の行を使う
print("\n[シナリオ2] WHERE dependents_count <= %s (DESC)")
matches = [tax for from_v, to_v, dep, tax in sample_table
if from_v <= monthly_income < to_v and dep <= dependents_count]
matches_sorted = sorted(matches, reverse=True)
print(f"マッチ数: {len(matches_sorted)}")
for tax in matches_sorted[:3]:
print(f" → ¥{tax}")
# シナリオ3: テーブルに0人の行が検索される場合
print("\n[シナリオ3] もし扶養人数3が見つからず、0が返される場合")
for from_v, to_v, dep, tax in sample_table:
if from_v <= monthly_income < to_v and dep == 0:
print(f" → ¥{tax} (0人扶養の税額が使用される)")
print("\n=== 推察 ===")
print("実際に 7,450円 が計算されているということは...")
print("1. 扶養人数が 0 人として計算されている可能性")
print("2. または、テーブルの月収範囲の定義が異なる可能性")
print("3. または、複数の条件で検索されて、意図しない行が使用されている可能性")