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

68 lines
2.2 KiB
Python
Raw Permalink 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
"""
所得税テーブルの詳細確認スクリプト
月収356,600円で対応する所得税を確認
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
from decimal import Decimal
from datetime import date
# テスト用の簡単なクエリシミュレーション
sample_rows_3 = [
# (From, To, 扶養3人の税額)
(350000, 355000, 5600),
(355000, 360000, 5840), # ← 356,600はここに該当するはず
(360000, 365000, 6080),
(365000, 370000, 6320),
]
monthly_income = 356600
dependents_count = 3
print("=== テスト: 月収 356,600円、扶養3人の所得税 ===\n")
# ケース1: monthly_income_to > monthly_income 条件
print("[ケース1] WHERE monthly_income_from <= %s AND monthly_income_to > %s")
print(f"条件: {monthly_income} >= From AND {monthly_income} < To\n")
found = False
for from_val, to_val, tax in sample_rows_3:
match = from_val <= monthly_income < to_val
status = "✓ MATCH" if match else "✗ NO"
print(f" {from_val:,} ~ {to_val:,}: {status} (tax={tax})")
if match:
found = True
result = tax
if found:
print(f"\n✓ 見つかりました: ¥{result}")
else:
print(f"\n✗ 見つかりませんでした")
# ケース2: monthly_income_to >= monthly_income 条件(元の間違ったロジック)
print("\n[ケース2元のバグ] WHERE monthly_income_from <= %s AND monthly_income_to >= %s")
print(f"条件: {monthly_income} >= From AND {monthly_income} <= To\n")
matches = []
for from_val, to_val, tax in sample_rows_3:
match = from_val <= monthly_income <= to_val
status = "✓ MATCH" if match else "✗ NO"
print(f" {from_val:,} ~ {to_val:,}: {status} (tax={tax})")
if match:
matches.append(tax)
if matches:
print(f"\n✓ 見つかりました: {len(matches)}")
for i, tax in enumerate(matches, 1):
print(f" {i}. ¥{tax}")
else:
print(f"\n✗ 見つかりませんでした")
print("\n=== 比較 ===")
print("正しいロジック (To > income): 5,840円")
print("バグロジック (To >= income): 複数マッチまたはマッチなし")
print(f"実際の計算結果: 7,450円 ← これはどこから来ているのか?")