Fix _current_outstanding_in_scope sort + tighten team-filter test
Two tweaks from code review on 82594fa: 1. The sort `key=lambda r: -r['amount']` placed NEGATIVE amounts (rare but possible: a project with only a deductive adjustment) AHEAD of larger positive exposures. Swapped to `key=lambda r: r['amount'], reverse=True` — same runtime, clearer intent, correct for negatives. 2. test_team_filter_scopes_total only asserted the net total. A partial scoping regression where the adjustment leaked but netted to zero would have silently passed. Added two assertions that by_project has exactly the expected 2 entries and R 500 never appears in the amount list. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
82594faad7
commit
ccc44a8d51
@ -589,3 +589,8 @@ class CurrentOutstandingInScopeTests(TestCase):
|
||||
# With team filter, only self.w's logs appear — R 400 total
|
||||
result = _current_outstanding_in_scope(team_ids=[self.t1.id])
|
||||
self.assertEqual(result['total'], Decimal('400.00'))
|
||||
# The R500 bonus on other_worker must NOT appear in by_project because
|
||||
# that worker isn't in t1 — the team scope excludes them entirely.
|
||||
self.assertEqual(len(result['by_project']), 2)
|
||||
amounts = [row['amount'] for row in result['by_project']]
|
||||
self.assertNotIn(Decimal('500.00'), amounts)
|
||||
|
||||
@ -270,7 +270,8 @@ def _current_outstanding_in_scope(project_ids=None, team_ids=None):
|
||||
raw = _compute_outstanding(project_ids=project_ids, team_ids=team_ids)
|
||||
by_project_list = sorted(
|
||||
[{'name': name, 'amount': amt} for name, amt in raw['outstanding_by_project'].items()],
|
||||
key=lambda r: -r['amount'],
|
||||
key=lambda r: r['amount'],
|
||||
reverse=True,
|
||||
)
|
||||
return {
|
||||
'total': raw['outstanding_payments'],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user