From 2ead351c30176a8afb4956f569ac5eeb71bf361c Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Sat, 18 Apr 2026 23:31:19 -0400 Subject: [PATCH] refactor(fusion_accounting_ai): route accounts_payable aged balances through FollowupAdapter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task 13 Step 8 of phase-0 plan. get_ap_aging → FollowupAdapter.aged_payables(). The adapter method was added alongside aged_receivables() in the previous commit, so this is a pure tool-wrapper change. Other AP tools (find_duplicate_bills, get_unpaid_bills, get_payment_schedule, etc.) touch account.move / account.move.line with pure-Community filters (move_type in (in_invoice, in_refund)) which are tri-mode safe and do not need adapter routing. All 9 data-adapter tests pass on westin-v19. Made-with: Cursor --- .../services/tools/accounts_payable.py | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) 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):