diff --git a/fusion_accounting_ai/services/tools/hst_management.py b/fusion_accounting_ai/services/tools/hst_management.py index 63f4e71c..6caf3287 100644 --- a/fusion_accounting_ai/services/tools/hst_management.py +++ b/fusion_accounting_ai/services/tools/hst_management.py @@ -52,25 +52,16 @@ def calculate_hst_balance(env, params): def get_tax_report(env, params): - report_ref = params.get('report_ref', 'account.generic_tax_report') - try: - report = env.ref(report_ref) - except Exception: - return {'error': f'Report not found: {report_ref}'} - options = report.get_options({ - 'date': { - 'date_from': params.get('date_from', ''), - 'date_to': params.get('date_to', ''), - } - }) - lines = report._get_lines(options) - return { - 'report_name': report.name, - 'lines': [{ - 'name': l.get('name', ''), - 'columns': [c.get('no_format', c.get('name', '')) for c in l.get('columns', [])], - } for l in lines[:50]], - } + """Route through ReportsAdapter for tri-mode consistency. The Community + fallback returns an error dict explaining the report is Enterprise-only.""" + from ..data_adapters import get_adapter + adapter = get_adapter(env, 'reports') + return adapter.run_report( + ref_id=params.get('report_ref', 'account.generic_tax_report'), + date_from=params.get('date_from'), + date_to=params.get('date_to'), + limit=50, + ) def find_missing_tax_invoices(env, params): diff --git a/fusion_accounting_ai/services/tools/month_end.py b/fusion_accounting_ai/services/tools/month_end.py index e35fc7cc..4a941b0b 100644 --- a/fusion_accounting_ai/services/tools/month_end.py +++ b/fusion_accounting_ai/services/tools/month_end.py @@ -101,22 +101,31 @@ def run_hash_integrity_check(env, params): def get_period_summary(env, params): + """Period summary via trial-balance. Routed through ReportsAdapter so the + Enterprise-only account_reports.trial_balance_report path is isolated; + Community installs fall back to the adapter's trial_balance() aggregation.""" + from ..data_adapters import get_adapter + adapter = get_adapter(env, 'reports') date_from = params.get('date_from') date_to = params.get('date_to') - try: - report = env.ref('account_reports.trial_balance_report') - except Exception: - report = env.ref('account.trial_balance_report', raise_if_not_found=False) - if not report: - return {'error': 'Trial balance report not found'} - options = report.get_options({'date': {'date_from': date_from, 'date_to': date_to}}) - lines = report._get_lines(options) + result = adapter.run_report( + ref_id='account_reports.trial_balance_report', + date_from=date_from, date_to=date_to, + ) + if isinstance(result, dict) and result.get('error'): + rows = adapter.trial_balance( + date_to=date_to, company_ids=[env.company.id], + ) + return { + 'period': f'{date_from} to {date_to}', + 'lines': [{ + 'name': f"{r['account_code']} {r['account_name']}", + 'columns': [r['debit'], r['credit'], r['balance']], + } for r in rows[:100]], + } return { 'period': f'{date_from} to {date_to}', - 'lines': [{ - 'name': l.get('name', ''), - 'columns': [c.get('no_format', c.get('name', '')) for c in l.get('columns', [])], - } for l in lines[:100]], + 'lines': result.get('lines', []), }