feat(fusion_accounting_ai): 5 new financial reports AI tools
Some checks failed
fusion_accounting CI / test (fusion_accounting_ai) (push) Has been cancelled
fusion_accounting CI / test (fusion_accounting_core) (push) Has been cancelled
fusion_accounting CI / test (fusion_accounting_migration) (push) Has been cancelled

Adds financial_reports.py tools module with 5 fusion-engine-routed
tools registered in TOOL_DISPATCH:

- fusion_run_report
- fusion_get_anomalies
- fusion_generate_commentary
- fusion_drill_down_report_line
- fusion_compare_periods

Each tool guards on 'fusion.report.engine' being in the registry and
otherwise returns a structured error so the chat agent can surface a
clear "module not installed" message.

6 new TransactionCase tests (including a TOOL_DISPATCH registration
sanity check).

Made-with: Cursor
This commit is contained in:
gsinghpal
2026-04-19 15:41:10 -04:00
parent 15cf4e129f
commit 118f0d9d16
5 changed files with 212 additions and 2 deletions

View File

@@ -12,3 +12,4 @@ from . import test_fusion_report_commentary
from . import test_fusion_report_anomaly
from . import test_reports_controller
from . import test_reports_adapter
from . import test_fusion_report_tools

View File

@@ -0,0 +1,81 @@
"""Tests for the 5 fusion AI tools registered in TOOL_DISPATCH."""
from odoo.tests.common import TransactionCase, tagged
from odoo.addons.fusion_accounting_ai.services.tools import financial_reports as tools
@tagged('post_install', '-at_install')
class TestFusionReportTools(TransactionCase):
def test_fusion_run_report_pnl(self):
result = tools.fusion_run_report(self.env, {
'report_type': 'pnl',
'date_from': '2026-01-01',
'date_to': '2026-12-31',
'company_id': self.env.company.id,
})
self.assertEqual(result['report_type'], 'pnl')
self.assertIn('rows', result)
self.assertIn('row_count', result)
def test_fusion_get_anomalies(self):
result = tools.fusion_get_anomalies(self.env, {
'report_type': 'pnl',
'date_from': '2026-01-01',
'date_to': '2026-12-31',
'comparison': 'previous_year',
'company_id': self.env.company.id,
})
self.assertIn('anomalies', result)
self.assertIn('count', result)
def test_fusion_generate_commentary(self):
result = tools.fusion_generate_commentary(self.env, {
'report_type': 'pnl',
'date_from': '2026-01-01',
'date_to': '2026-12-31',
'company_id': self.env.company.id,
})
self.assertIn('summary', result)
self.assertIn('highlights', result)
self.assertIn('concerns', result)
self.assertIn('next_actions', result)
def test_fusion_drill_down(self):
line = self.env['account.move.line'].search(
[('parent_state', '=', 'posted')], limit=1,
)
if not line:
self.skipTest("No posted move lines")
result = tools.fusion_drill_down_report_line(self.env, {
'account_id': line.account_id.id,
'date_from': str(line.date),
'date_to': str(line.date),
'company_id': line.company_id.id,
})
self.assertIn('rows', result)
self.assertIn('count', result)
def test_fusion_compare_periods(self):
result = tools.fusion_compare_periods(self.env, {
'report_type': 'pnl',
'date_from': '2026-01-01',
'date_to': '2026-12-31',
'company_id': self.env.company.id,
})
self.assertEqual(result['report_type'], 'pnl')
def test_tools_registered_in_dispatch(self):
from odoo.addons.fusion_accounting_ai.services.tools import TOOL_DISPATCH
for tool_name in [
'fusion_run_report',
'fusion_get_anomalies',
'fusion_generate_commentary',
'fusion_drill_down_report_line',
'fusion_compare_periods',
]:
self.assertIn(
tool_name, TOOL_DISPATCH,
f"{tool_name} not registered in TOOL_DISPATCH",
)