refactor(fusion_accounting_ai): route month_end + hst_management report tools through ReportsAdapter

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
This commit is contained in:
gsinghpal
2026-04-18 23:40:27 -04:00
parent 484314625e
commit f18afe7380
2 changed files with 31 additions and 31 deletions

View File

@@ -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):

View File

@@ -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', []),
}