refactor(fusion_accounting_ai): route accounts_payable aged balances through FollowupAdapter

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
This commit is contained in:
gsinghpal
2026-04-18 23:31:19 -04:00
parent 6791246def
commit 2ead351c30

View File

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