refactor(fusion_accounting_ai): route reporting tools through ReportsAdapter

Task 13 Step 9 of phase-0 plan.

All Enterprise account.report entry points now go through ReportsAdapter:

  - get_profit_loss → ReportsAdapter.run_report(account_reports.profit_and_loss)
  - get_balance_sheet → ReportsAdapter.run_report(account_reports.balance_sheet)
  - get_trial_balance → ReportsAdapter.run_report(...) with Community fallback
    to the existing trial_balance() account.move.line aggregation
  - get_cash_flow → ReportsAdapter.run_report(account_reports.cash_flow_statement)
  - compare_periods → two run_report() calls
  - export_report → ReportsAdapter.export_report() (PDF/XLSX via Enterprise)

ReportsAdapter extended with:

  - run_report(ref_id, date_from, date_to, limit) — generic Enterprise
    account.report wrapper. Enterprise mode returns {report_name, lines};
    Community mode returns a graceful error dict pointing users at the
    raw trial_balance() aggregation tool.
  - export_report(ref_id, fmt, date_from, date_to) — Enterprise-only PDF/XLSX
    export; Community mode returns an error dict.

Pure-Community tools in reporting.py (get_invoicing_summary, get_billing_summary,
get_collections_summary) unchanged — they aggregate account.move /
account.payment directly which is tri-mode safe.

3 new data-adapter tests added for run_report happy/error paths and
export_report shape. Total: 12 tests, all passing on westin-v19.

Made-with: Cursor
This commit is contained in:
gsinghpal
2026-04-18 23:33:54 -04:00
parent 2ead351c30
commit e983a370aa
3 changed files with 222 additions and 79 deletions

View File

@@ -66,15 +66,37 @@ class TestReportsAdapter(TransactionCase):
def test_trial_balance_returns_rows_in_pure_community(self):
adapter = get_adapter(self.env, 'reports')
# Compute an empty-filter trial balance for the current company. Should
# return a list (possibly empty in a fresh test DB) without errors.
result = adapter.trial_balance()
self.assertIsInstance(result, list)
# Each row should have account_id and balance keys
for row in result:
self.assertIn('account_id', row)
self.assertIn('balance', row)
def test_run_report_returns_lines_or_error_dict(self):
"""run_report() must always return either an Enterprise-shaped
{'report_name', 'lines'} dict or an {'error': ...} dict — never raise."""
adapter = get_adapter(self.env, 'reports')
result = adapter.run_report(ref_id='account_reports.profit_and_loss')
self.assertIsInstance(result, dict)
# Either a report_name+lines response or an error — both valid
self.assertTrue(
('lines' in result and 'report_name' in result) or 'error' in result,
f"Unexpected result shape: {result!r}",
)
def test_run_report_with_unknown_ref_returns_error(self):
adapter = get_adapter(self.env, 'reports')
result = adapter.run_report(ref_id='nonexistent.report.xml_id')
self.assertIsInstance(result, dict)
self.assertIn('error', result)
def test_export_report_returns_dict(self):
adapter = get_adapter(self.env, 'reports')
result = adapter.export_report(
ref_id='account_reports.profit_and_loss', fmt='pdf',
)
self.assertIsInstance(result, dict)
@tagged('post_install', '-at_install')
class TestFollowupAdapter(TransactionCase):