diff --git a/fusion_accounting_ai/services/tools/accounts_payable.py b/fusion_accounting_ai/services/tools/accounts_payable.py index ffc2d35d..57073c9c 100644 --- a/fusion_accounting_ai/services/tools/accounts_payable.py +++ b/fusion_accounting_ai/services/tools/accounts_payable.py @@ -6,32 +6,10 @@ _logger = logging.getLogger(__name__) def get_ap_aging(env, params): - today = fields.Date.today() - domain = [ - ('account_id.account_type', '=', 'liability_payable'), - ('parent_state', '=', 'posted'), - ('reconciled', '=', False), - ('company_id', '=', env.company.id), - ] - amls = env['account.move.line'].search(domain) - - buckets = {'current': 0, '1_30': 0, '31_60': 0, '61_90': 0, '90_plus': 0} - for aml in amls: - amt = abs(aml.amount_residual) - if not aml.date_maturity or aml.date_maturity >= today: - buckets['current'] += amt - else: - days = (today - aml.date_maturity).days - if days <= 30: - buckets['1_30'] += amt - elif days <= 60: - buckets['31_60'] += amt - elif days <= 90: - buckets['61_90'] += amt - else: - buckets['90_plus'] += amt - - return {'total': sum(buckets.values()), 'buckets': buckets, 'line_count': len(amls)} + """Return AP aging buckets. Routed through FollowupAdapter for tri-mode consistency.""" + from ..data_adapters import get_adapter + adapter = get_adapter(env, 'followup') + return adapter.aged_payables(company_id=env.company.id) def find_duplicate_bills(env, params):