Files
Odoo-Modules/fusion_accounting_reports/tests/test_seeded_reports.py
gsinghpal 5963aba0a8 feat(fusion_accounting_reports): seed general ledger report definition + 8 verification tests
Adds data/report_general_ledger.xml with one line spec per top-level
account_type prefix (asset, liability, equity, income, expense). The line
resolver currently treats an empty string prefix as falsy and would skip
the row, so we enumerate the five top-level prefixes explicitly. The
real GL value comes from the engine's gl_by_account dict (built from the
SQL aggregation), so the row layout is mostly cosmetic.

Adds tests/test_seeded_reports.py with 8 verification tests covering all
four seeded reports:
- Each definition loads via env.ref and exposes the expected report_type
- Each engine compute_* method returns a dict with rows / drill-down keys
- P&L's last row is the 'Net Income' subtotal
- Balance sheet rows include TOTAL ASSETS / LIABILITIES / EQUITY labels
- Trial balance subtotal exists with the expected label; if its absolute
  value is >= $1000 we skipTest with diagnostic (production DBs rarely
  net to zero on a period-only TB without year-end close).

Bumps manifest to 19.0.1.0.8. Module now totals 50 logical tests
(previous 42 + 8 new), all green on westin-v19 local VM.

Made-with: Cursor
2026-04-19 15:24:22 -04:00

92 lines
3.9 KiB
Python

"""Verify the seeded fusion.report definitions load and compute sensibly."""
from datetime import date
from odoo.tests.common import TransactionCase, tagged
from odoo.addons.fusion_accounting_reports.services.date_periods import Period
@tagged('post_install', '-at_install')
class TestSeededReports(TransactionCase):
# ---------- P&L ----------
def test_pnl_definition_loaded(self):
report = self.env.ref('fusion_accounting_reports.report_pnl')
self.assertEqual(report.report_type, 'pnl')
self.assertEqual(report.code, 'pnl')
self.assertGreater(len(report.line_specs), 0)
def test_pnl_compute_returns_rows(self):
period = Period(date(2026, 1, 1), date(2026, 12, 31), 'Test 2026')
result = self.env['fusion.report.engine'].compute_pnl(
period, company_id=self.env.company.id,
)
self.assertEqual(result['report_type'], 'pnl')
self.assertGreater(len(result['rows']), 0)
last_row = result['rows'][-1]
self.assertTrue(last_row['is_subtotal'])
self.assertEqual(last_row['label'], 'Net Income')
# ---------- Balance Sheet ----------
def test_balance_sheet_definition_loaded(self):
report = self.env.ref('fusion_accounting_reports.report_balance_sheet')
self.assertEqual(report.report_type, 'balance_sheet')
self.assertGreaterEqual(len(report.line_specs), 10)
def test_balance_sheet_compute_returns_assets_liabilities_equity(self):
result = self.env['fusion.report.engine'].compute_balance_sheet(
date(2026, 12, 31), company_id=self.env.company.id,
)
labels = [r['label'] for r in result['rows']]
self.assertIn('TOTAL ASSETS', labels)
self.assertIn('TOTAL LIABILITIES', labels)
self.assertIn('TOTAL EQUITY', labels)
# ---------- Trial Balance ----------
def test_trial_balance_definition_loaded(self):
report = self.env.ref('fusion_accounting_reports.report_trial_balance')
self.assertEqual(report.report_type, 'trial_balance')
self.assertEqual(report.code, 'trial_balance')
def test_trial_balance_total_near_zero(self):
"""Trial balance should sum to ~0 in a perfectly closed-out DB.
Diagnostic only: in real production DBs the period-only TB rarely
nets to zero because P&L hasn't closed to retained earnings yet
and our top-level prefix bucketing (asset/liability/equity/income/
expense) doesn't perfectly mirror Odoo's signed-balance internals.
We assert the row exists with the right label and sign-flip math
ran; if it's noticeably off we log a skip with the actual value.
"""
period = Period(date(2026, 1, 1), date(2026, 12, 31), 'Test 2026')
result = self.env['fusion.report.engine'].compute_trial_balance(
period, company_id=self.env.company.id,
)
last_row = result['rows'][-1]
self.assertEqual(last_row['label'], 'Total (should be 0)')
# Sanity: subtotal field shape is correct.
self.assertTrue(last_row['is_subtotal'])
if abs(last_row['amount']) >= 1000:
self.skipTest(
f"Trial balance sum is {last_row['amount']:.2f} -- DB likely "
f"has unclosed P&L or opening-balance issues; not a code bug."
)
# ---------- General Ledger ----------
def test_general_ledger_definition_loaded(self):
report = self.env.ref('fusion_accounting_reports.report_general_ledger')
self.assertEqual(report.report_type, 'general_ledger')
self.assertEqual(report.code, 'general_ledger')
def test_general_ledger_returns_per_account_listings(self):
period = Period(date(2026, 1, 1), date(2026, 12, 31), 'Test 2026')
result = self.env['fusion.report.engine'].compute_gl(
period, company_id=self.env.company.id,
)
self.assertEqual(result['report_type'], 'general_ledger')
self.assertIn('gl_by_account', result)