Skip to content

Commit a214742

Browse files
committed
Order allocation, approval, finance and cost-recovery rows desc by date
1 parent 24eca3e commit a214742

File tree

1 file changed

+57
-40
lines changed

1 file changed

+57
-40
lines changed

rctab/routers/accounting/routes.py

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -391,60 +391,77 @@ def get_total_usage(
391391
@db_select
392392
def get_allocations(sub_id: UUID) -> Select:
393393
"""Get all allocations for a subscription."""
394-
return select(
395-
[
396-
allocations.c.ticket,
397-
allocations.c.amount,
398-
allocations.c.currency,
399-
allocations.c.time_created,
400-
]
401-
).where(allocations.c.subscription_id == sub_id)
394+
return (
395+
select(
396+
[
397+
allocations.c.ticket,
398+
allocations.c.amount,
399+
allocations.c.currency,
400+
allocations.c.time_created,
401+
]
402+
)
403+
.where(allocations.c.subscription_id == sub_id)
404+
.order_by(desc(allocations.c.time_created))
405+
)
402406

403407

404408
@db_select
405409
def get_approvals(sub_id: UUID) -> Select:
406410
"""Get all approvals for a subscription."""
407-
return select(
408-
[
409-
approvals.c.ticket,
410-
approvals.c.amount,
411-
approvals.c.currency,
412-
approvals.c.date_from,
413-
approvals.c.date_to,
414-
approvals.c.time_created,
415-
]
416-
).where(approvals.c.subscription_id == sub_id)
411+
return (
412+
select(
413+
[
414+
approvals.c.ticket,
415+
approvals.c.amount,
416+
approvals.c.currency,
417+
approvals.c.date_from,
418+
approvals.c.date_to,
419+
approvals.c.time_created,
420+
]
421+
)
422+
.where(approvals.c.subscription_id == sub_id)
423+
.order_by(desc(approvals.c.date_to))
424+
)
417425

418426

419427
@db_select
420428
def get_finance(sub_id: UUID) -> Select:
421429
"""Get all finance items."""
422-
return select(
423-
[
424-
finance.c.ticket,
425-
finance.c.amount,
426-
finance.c.priority,
427-
finance.c.finance_code,
428-
finance.c.date_from,
429-
finance.c.date_to,
430-
finance.c.time_created,
431-
]
432-
).where(finance.c.subscription_id == sub_id)
430+
return (
431+
select(
432+
[
433+
finance.c.ticket,
434+
finance.c.amount,
435+
finance.c.priority,
436+
finance.c.finance_code,
437+
finance.c.date_from,
438+
finance.c.date_to,
439+
finance.c.time_created,
440+
]
441+
)
442+
.where(finance.c.subscription_id == sub_id)
443+
.order_by(desc(finance.c.date_to))
444+
)
433445

434446

435447
@db_select
436448
def get_costrecovery(sub_id: UUID) -> Select:
437-
"""Get all cost recovery items for a subscription."""
438-
return select(
439-
[
440-
cost_recovery.c.subscription_id,
441-
cost_recovery.c.finance_id,
442-
cost_recovery.c.month,
443-
cost_recovery.c.finance_code,
444-
cost_recovery.c.amount,
445-
cost_recovery.c.date_recovered,
446-
]
447-
).where(cost_recovery.c.subscription_id == sub_id)
449+
"""Get all cost recovery items for a subscription in asc date order."""
450+
# order by month asc
451+
return (
452+
select(
453+
[
454+
cost_recovery.c.subscription_id,
455+
cost_recovery.c.finance_id,
456+
cost_recovery.c.month,
457+
cost_recovery.c.finance_code,
458+
cost_recovery.c.amount,
459+
cost_recovery.c.date_recovered,
460+
]
461+
)
462+
.where(cost_recovery.c.subscription_id == sub_id)
463+
.order_by(desc(cost_recovery.c.month))
464+
)
448465

449466

450467
@db_select

0 commit comments

Comments
 (0)