55 lines
2.2 KiB
Python
55 lines
2.2 KiB
Python
"""Tests for commentary_generator service."""
|
|
|
|
from odoo.tests.common import TransactionCase, tagged
|
|
from odoo.addons.fusion_accounting_reports.services.commentary_generator import (
|
|
generate_commentary, _templated_fallback,
|
|
)
|
|
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestCommentaryGenerator(TransactionCase):
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
# Ensure no provider is configured so we exercise the fallback path
|
|
self.env['ir.config_parameter'].sudo().search([
|
|
('key', 'in', ['fusion_accounting.provider.reports_commentary',
|
|
'fusion_accounting.provider.default'])
|
|
]).unlink()
|
|
|
|
def test_fallback_when_no_provider(self):
|
|
report = {
|
|
'report_name': 'P&L',
|
|
'period': {'label': 'Apr 2026'},
|
|
'rows': [
|
|
{'id': 'r1', 'label': 'Revenue', 'amount': 100000, 'is_subtotal': False},
|
|
{'id': 'r2', 'label': 'Net Income', 'amount': 25000, 'is_subtotal': True},
|
|
],
|
|
}
|
|
result = generate_commentary(self.env, report_result=report)
|
|
self.assertIn('summary', result)
|
|
self.assertIn('Net Income', result['summary'])
|
|
self.assertIn('25,000', result['summary'])
|
|
|
|
def test_fallback_includes_anomalies_in_concerns(self):
|
|
report = {
|
|
'report_name': 'P&L',
|
|
'period': {'label': 'Apr 2026'},
|
|
'rows': [],
|
|
}
|
|
anomalies = [
|
|
{'label': 'Revenue', 'direction': 'increase', 'variance_pct': 30.0,
|
|
'variance_amount': 5000, 'severity': 'medium'},
|
|
]
|
|
result = generate_commentary(self.env, report_result=report, anomalies=anomalies)
|
|
self.assertEqual(len(result['concerns']), 1)
|
|
self.assertIn('Revenue', result['concerns'][0])
|
|
self.assertIn('30.0%', result['concerns'][0])
|
|
self.assertGreater(len(result['next_actions']), 0)
|
|
|
|
def test_returns_dict_with_required_keys(self):
|
|
report = {'report_name': 'Test', 'period': {'label': 'X'}, 'rows': []}
|
|
result = generate_commentary(self.env, report_result=report)
|
|
for key in ('summary', 'highlights', 'concerns', 'next_actions'):
|
|
self.assertIn(key, result)
|