70 lines
3.1 KiB
Python
70 lines
3.1 KiB
Python
from datetime import date, timedelta
|
|
from odoo.tests.common import TransactionCase
|
|
from odoo.tests import tagged
|
|
from odoo.addons.fusion_accounting_followup.services.overdue_aging import (
|
|
compute_aging, BUCKETS,
|
|
)
|
|
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestOverdueAging(TransactionCase):
|
|
|
|
def test_empty_lines_returns_zero_buckets(self):
|
|
report = compute_aging(move_lines=[], as_of=date(2026, 4, 19))
|
|
self.assertEqual(report.total_amount, 0)
|
|
self.assertEqual(len(report.buckets), len(BUCKETS))
|
|
for b in report.buckets:
|
|
self.assertEqual(b.amount, 0)
|
|
|
|
def test_current_bucket_for_future_maturity(self):
|
|
as_of = date(2026, 4, 19)
|
|
lines = [{'date_maturity': date(2026, 5, 19), 'amount_residual': 100}]
|
|
report = compute_aging(move_lines=lines, as_of=as_of)
|
|
current = next(b for b in report.buckets if b.name == 'current')
|
|
self.assertEqual(current.amount, 100)
|
|
self.assertEqual(report.total_overdue_amount, 0)
|
|
|
|
def test_30_day_bucket(self):
|
|
as_of = date(2026, 4, 19)
|
|
lines = [{'date_maturity': as_of - timedelta(days=15), 'amount_residual': 200}]
|
|
report = compute_aging(move_lines=lines, as_of=as_of)
|
|
b = next(b for b in report.buckets if b.name == '1_30')
|
|
self.assertEqual(b.amount, 200)
|
|
|
|
def test_60_day_bucket(self):
|
|
as_of = date(2026, 4, 19)
|
|
lines = [{'date_maturity': as_of - timedelta(days=45), 'amount_residual': 300}]
|
|
report = compute_aging(move_lines=lines, as_of=as_of)
|
|
b = next(b for b in report.buckets if b.name == '31_60')
|
|
self.assertEqual(b.amount, 300)
|
|
|
|
def test_120_plus_bucket(self):
|
|
as_of = date(2026, 4, 19)
|
|
lines = [{'date_maturity': as_of - timedelta(days=200), 'amount_residual': 500}]
|
|
report = compute_aging(move_lines=lines, as_of=as_of)
|
|
b = next(b for b in report.buckets if b.name == '120_plus')
|
|
self.assertEqual(b.amount, 500)
|
|
|
|
def test_total_overdue_excludes_current(self):
|
|
as_of = date(2026, 4, 19)
|
|
lines = [
|
|
{'date_maturity': as_of + timedelta(days=10), 'amount_residual': 100},
|
|
{'date_maturity': as_of - timedelta(days=10), 'amount_residual': 200},
|
|
{'date_maturity': as_of - timedelta(days=50), 'amount_residual': 300},
|
|
]
|
|
report = compute_aging(move_lines=lines, as_of=as_of)
|
|
self.assertEqual(report.total_amount, 600)
|
|
self.assertEqual(report.total_overdue_amount, 500)
|
|
|
|
def test_buckets_sum_equals_total(self):
|
|
as_of = date(2026, 4, 19)
|
|
lines = [
|
|
{'date_maturity': as_of + timedelta(days=10), 'amount_residual': 100},
|
|
{'date_maturity': as_of - timedelta(days=15), 'amount_residual': 200},
|
|
{'date_maturity': as_of - timedelta(days=75), 'amount_residual': 300},
|
|
{'date_maturity': as_of - timedelta(days=200), 'amount_residual': 500},
|
|
]
|
|
report = compute_aging(move_lines=lines, as_of=as_of)
|
|
bucket_sum = sum(b.amount for b in report.buckets)
|
|
self.assertAlmostEqual(bucket_sum, report.total_amount, places=2)
|