Files
njts-accounting-core/check_opening_balances_data.py
2026-02-21 10:51:25 +09:00

40 lines
1.4 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
"""opening_balances テーブルのデータ確認"""
import psycopg
try:
conn = psycopg.connect('host=localhost user=postgres password=postgres dbname=accounting')
cur = conn.cursor()
# opening_balances テーブルの行数確認
cur.execute("SELECT COUNT(*) FROM opening_balances")
count = cur.fetchone()[0]
print(f"【opening_balances テーブル行数】: {count}")
if count == 0:
print("\n⚠️ opening_balances テーブルは空です")
print("→ 期首残高データが入力されていません")
else:
# 年度別データを確認
cur.execute("SELECT fiscal_year, COUNT(*) as cnt FROM opening_balances GROUP BY fiscal_year ORDER BY fiscal_year")
print("\n【年度別件数】")
for row in cur.fetchall():
print(f" {row[0]}年度: {row[1]}")
# 2025年度のサンプルデータ
print("\n【2025年度のサンプル最初の5件")
cur.execute("""
SELECT account_id, opening_debit, opening_credit
FROM opening_balances
WHERE fiscal_year = 2025
LIMIT 5
""")
for row in cur.fetchall():
print(f" account_id={row[0]}, debit={row[1]}, credit={row[2]}")
cur.close()
conn.close()
except Exception as e:
print(f"❌ エラー: {e}")