From f18afe7380f0b14a5bbcd49c95aab56da86d6ee7 Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Sat, 18 Apr 2026 23:40:27 -0400 Subject: [PATCH] refactor(fusion_accounting_ai): route month_end + hst_management report tools through ReportsAdapter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task 13 Step 10 of phase-0 plan. - month_end.get_period_summary → ReportsAdapter.run_report(...) with Community fallback to the trial_balance() aggregator. - hst_management.get_tax_report → ReportsAdapter.run_report(...). Other tools in these files (get_unreconciled_counts, find_entries_in_locked_period, get_accrual_status, run_hash_integrity_check, calculate_hst_balance, find_missing_tax_invoices, find_missing_itc_bills, create_expense_entry) touch pure-Community models (account.move, account.move.line, account.account, account.payment) directly and are tri-mode safe. account.return tools in hst_management (get_tax_return_status, generate_tax_return, validate_tax_return) and account.audit.account.status tools in audit.py already handle the missing-model case gracefully. They fall outside this task's target set of {account.report, account.followup.line, account.asset} and are left as-is per plan. All 12 data-adapter tests pass on westin-v19. Made-with: Cursor --- .../services/tools/hst_management.py | 29 ++++++---------- .../services/tools/month_end.py | 33 ++++++++++++------- 2 files changed, 31 insertions(+), 31 deletions(-) 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', []), }