feat(fusion_accounting_followup): risk_scorer service

Made-with: Cursor
This commit is contained in:
gsinghpal
2026-04-19 20:38:44 -04:00
parent d4ef19858d
commit 397fb238c5
5 changed files with 113 additions and 1 deletions

View File

@@ -1,2 +1,3 @@
from . import test_overdue_aging
from . import test_level_resolver
from . import test_risk_scorer

View File

@@ -0,0 +1,48 @@
from odoo.tests.common import TransactionCase
from odoo.tests import tagged
from odoo.addons.fusion_accounting_followup.services.risk_scorer import (
score_partner, PartnerRiskScore,
)
@tagged('post_install', '-at_install')
class TestRiskScorer(TransactionCase):
def test_no_history_returns_low(self):
result = score_partner()
self.assertEqual(result.band, 'low')
self.assertLess(result.score, 30)
def test_chronic_late_pays_returns_high(self):
result = score_partner(
total_invoices=20, paid_late_count=18,
avg_days_late=45, longest_overdue_days=90,
open_overdue_amount=15000, average_invoice_amount=2000,
)
self.assertIn(result.band, ('high', 'critical'))
self.assertGreater(len(result.drivers), 0)
def test_one_off_overdue_returns_medium(self):
result = score_partner(
total_invoices=10, paid_late_count=1,
avg_days_late=20, longest_overdue_days=45,
open_overdue_amount=2000, average_invoice_amount=2000,
)
self.assertIn(result.band, ('low', 'medium'))
def test_score_capped_at_100(self):
result = score_partner(
total_invoices=10, paid_late_count=10,
avg_days_late=180, longest_overdue_days=300,
open_overdue_amount=999999, average_invoice_amount=1000,
)
self.assertLessEqual(result.score, 100)
def test_score_floored_at_0(self):
result = score_partner()
self.assertGreaterEqual(result.score, 0)
def test_band_thresholds(self):
for s, expected_band in [(10, 'low'), (40, 'medium'), (70, 'high'), (90, 'critical')]:
r = PartnerRiskScore(score=s, band=expected_band, drivers=[])
self.assertEqual(r.band, expected_band)